LCOV - code coverage report
Current view: top level - alma/ASDMBinaries - SDMDataObject.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 6 955 0.6 %
Date: 2024-10-04 16:51:10 Functions: 3 176 1.7 %

          Line data    Source code
       1             : #include <alma/ASDMBinaries/SDMDataObject.h>
       2             : #include <alma/ASDMBinaries/SDMDataObjectParser.h>
       3             : #include <algorithm>
       4             : #include <iostream>
       5             : #include <iterator>
       6             : #include <iostream>
       7             : #include <sstream>
       8             : 
       9             : #ifndef WITHOUT_BOOST
      10             : #include <boost/range/iterator_range.hpp>
      11             : #include <boost/algorithm/string/find.hpp>
      12             : #endif
      13             : 
      14             : using namespace AtmPhaseCorrectionMod;
      15             : using namespace AxisNameMod;
      16             : using namespace BasebandNameMod;
      17             : using namespace CorrelationModeMod;
      18             : using namespace CorrelatorTypeMod;
      19             : using namespace NetSidebandMod;
      20             : using namespace PrimitiveDataTypeMod;
      21             : using namespace ProcessorTypeMod;
      22             : using namespace SpectralResolutionTypeMod;
      23             : using namespace StokesParameterMod;
      24             : 
      25             : using namespace std;
      26             : 
      27             : namespace asdmbinaries {
      28             : 
      29             :   // Initialization section.
      30             :   //
      31             :   vector<string> SDMDataObject::axes;
      32             :   vector<string> SDMDataObject::correlationModeRefs;
      33             :   vector<string> SDMDataObject::types;
      34             :   vector<string> SDMDataObject::apcs;
      35             : 
      36             :   const bool SDMDataObject::_init = SDMDataObject::init();
      37           3 :   bool SDMDataObject::init() {
      38           3 :     return true;
      39             :   }
      40             : 
      41             :   // A regular expression to define the syntax of a spectral window identifier.
      42             : #ifndef WITHOUT_BOOST
      43             :   const boost::regex SDMDataObject::SPWID("[0-9]+");
      44             : #else
      45             :   const std::regex SDMDataObject::SPWID("[0-9]+");
      46             : #endif
      47             :   
      48             :   // SDMDataObject::SpectralWindow:: methods
      49             :   //
      50           0 :   SDMDataObject::SpectralWindow::SpectralWindow():
      51           0 :     scaleFactor_(0.0),
      52           0 :     numSpectralPoint_(0),
      53           0 :     numBin_(0)
      54           0 :   {owner_ = 0; strSw_ = ""; strImage_ = "";}
      55             :   
      56           0 :   SDMDataObject::SpectralWindow::~SpectralWindow() {;}
      57             :   
      58           0 :   SDMDataObject::SpectralWindow::SpectralWindow(const vector<StokesParameter>& crossPolProducts,
      59             :                                                 float scaleFactor, unsigned int numSpectralPoint,
      60             :                                                 unsigned int numBin,
      61           0 :                                                 NetSidebandMod::NetSideband sideband):
      62           0 :     crossPolProducts_(crossPolProducts),
      63           0 :     scaleFactor_(scaleFactor),
      64           0 :     numSpectralPoint_(numSpectralPoint),
      65           0 :     numBin_(numBin),
      66           0 :     sideband_(sideband)
      67           0 :   {owner_ = 0;  strSw_ = ""; strImage_ = "";}
      68             :   
      69           0 :   SDMDataObject::SpectralWindow::SpectralWindow::SpectralWindow(const vector<StokesParameter>& sdPolProducts,
      70             :                                                                 unsigned int numSpectralPoint,
      71             :                                                                 unsigned numBin,
      72           0 :                                                                 NetSidebandMod::NetSideband sideband):
      73           0 :     sdPolProducts_(sdPolProducts),
      74           0 :     numSpectralPoint_(numSpectralPoint),
      75           0 :     numBin_(numBin),
      76           0 :     sideband_(sideband)
      77           0 :   {owner_ = 0; strSw_ = ""; strImage_ = "";}
      78             :   
      79           0 :   SDMDataObject::SpectralWindow::SpectralWindow(const vector<StokesParameter>& crossPolProducts,
      80             :                                                 const vector<StokesParameter>& sdPolProducts,
      81             :                                                 float scaleFactor,
      82             :                                                 unsigned int numSpectralPoint,
      83             :                                                 unsigned int numBin,
      84           0 :                                                 NetSidebandMod::NetSideband sideband):
      85           0 :     crossPolProducts_(crossPolProducts),
      86           0 :     sdPolProducts_(sdPolProducts),
      87           0 :     scaleFactor_(scaleFactor),
      88           0 :     numSpectralPoint_(numSpectralPoint),
      89           0 :     numBin_(numBin),
      90           0 :     sideband_(sideband)
      91           0 :   {owner_ = 0; strSw_ = ""; strImage_ = "";}
      92             :   
      93           0 :   const vector<StokesParameter>& SDMDataObject::SpectralWindow::crossPolProducts() const { 
      94           0 :     if (owner_ && (owner_->isTP() || owner_->correlationMode() == AUTO_ONLY)) Utils::invalidCall("SDMDataObject::SpectralWindow::crossPolProducts", owner_);
      95           0 :     return crossPolProducts_; 
      96             :   }
      97             : 
      98             :   //  void SDMDataObject::SpectralWindow::crossPolProducts(const vector<StokesParameter>& value) { crossPolProducts_ = value; }
      99             : 
     100           0 :   const vector<StokesParameter>& SDMDataObject::SpectralWindow::sdPolProducts() const { 
     101           0 :     if (owner_ && (owner_->correlationMode() == CROSS_ONLY)) Utils::invalidCall("SDMDataObject::SpectralWindow::sdPolProducts", owner_);
     102           0 :     return sdPolProducts_; 
     103             :   }
     104             : 
     105             :   //  void SDMDataObject::SpectralWindow::sdPolProducts(const vector<StokesParameter>& value) { sdPolProducts_ = value; }
     106             : 
     107           0 :   float SDMDataObject::SpectralWindow::scaleFactor() const { 
     108           0 :     if (owner_ && owner_->correlationMode() == AUTO_ONLY) Utils::invalidCall("SDMDataObject::SpectralWindow::scaleFactor", owner_);    
     109           0 :     return scaleFactor_; 
     110             :   }
     111             :   //  void SDMDataObject::SpectralWindow::scaleFactor(float value )  { scaleFactor_ = value; }
     112             :   
     113           0 :   unsigned int SDMDataObject::SpectralWindow::numSpectralPoint() const { return numSpectralPoint_; }
     114             :   //  void SDMDataObject::SpectralWindow::numSpectralPoint(unsigned int value)  { numSpectralPoint_ = value; }
     115             : 
     116           0 :   unsigned int SDMDataObject::SpectralWindow::numBin() const { return numBin_; }
     117             :   //  void SDMDataObject::SpectralWindow::numBin(unsigned int value) { numBin_ = value; }
     118             : 
     119           0 :   void SDMDataObject::SpectralWindow::owner(const SDMDataObject* o) { owner_ = o; }
     120             : 
     121           0 :   NetSidebandMod::NetSideband SDMDataObject::SpectralWindow::sideband() const { return sideband_; }
     122             : 
     123           0 :   void SDMDataObject::SpectralWindow::strImage(const string& s) {
     124             : #ifndef WITHOUT_BOOST
     125             :     boost::cmatch what;
     126             : #else
     127           0 :     std::cmatch what;
     128             : #endif
     129           0 :     if ((s.size() == 0) || regex_match(s.c_str(), what, SDMDataObject::SPWID)) {
     130           0 :       strImage_ = s;
     131             :     }
     132             :     else
     133           0 :       throw SDMDataObjectException("SpectralWindow::strImage : '" + s + "' is an invalid string to identify a spectral window.");
     134           0 :   }
     135             : 
     136           0 :   const string& SDMDataObject::SpectralWindow::strImage() const { return strImage_; }
     137             : 
     138           0 :   void SDMDataObject::SpectralWindow::strSw(const string& s) {
     139             : #ifndef WITHOUT_BOOST
     140             :     boost::cmatch what;
     141             : #else
     142           0 :     std::cmatch what;
     143             : #endif
     144           0 :     if ((s.size() == 0) || regex_match(s.c_str(), what, SDMDataObject::SPWID)) {
     145           0 :       strSw_ = s;
     146             :     }
     147             :     else
     148           0 :       throw SDMDataObjectException("SpectralWindow::strSw :  '" + s + "' is an invalid string to identify a spectral window.");
     149           0 :   }
     150             : 
     151           0 :   const string& SDMDataObject::SpectralWindow::strSw() const { return strSw_; }
     152             : 
     153             :   // SDMDataObject::SpectralWindow::
     154             : 
     155             : 
     156             :   // SDMDataObject::Baseband methods
     157             :   //
     158           0 :   SDMDataObject::Baseband::Baseband() {owner_ = 0;}
     159             :   
     160           0 :   SDMDataObject::Baseband::Baseband(BasebandName name,
     161           0 :                                     const vector<SpectralWindow>& spectralWindows):
     162           0 :     name_(name),
     163           0 :     spectralWindows_(spectralWindows) {owner_ = 0;}
     164             : 
     165             : 
     166           0 :   SDMDataObject::Baseband::~Baseband() {;}
     167             :   
     168           0 :   BasebandName SDMDataObject::Baseband::name() const { 
     169           0 :     return name_; 
     170             :   }
     171             : 
     172             :   //  void SDMDataObject::Baseband::ref(BasebandName value) { ref_ = value; }
     173             :   
     174           0 :   const vector<SDMDataObject::SpectralWindow>& SDMDataObject::Baseband::spectralWindows() const { return spectralWindows_; }
     175           0 :   void SDMDataObject::Baseband::spectralWindows(const vector<SDMDataObject::SpectralWindow>& value) { spectralWindows_ = value; }
     176           0 :   void SDMDataObject::Baseband::owner(const SDMDataObject* o) {owner_ = o; }
     177             :   // SDMDataObject::Baseband::
     178             : 
     179             :   // SDMDataObject::BinaryPart:: methods
     180             :   //
     181           0 :   SDMDataObject::BinaryPart::BinaryPart() {owner_ = 0; size_ = 0;}
     182           0 :   SDMDataObject::BinaryPart::~BinaryPart() {;}
     183             :   
     184             :   
     185           0 :   SDMDataObject::BinaryPart::BinaryPart( unsigned int size,
     186           0 :                                          const vector<AxisName>& axes):
     187           0 :     size_(size),
     188           0 :     axes_(axes){owner_ = 0;}
     189             :   
     190             :   
     191           0 :   unsigned int SDMDataObject::BinaryPart::size() const { return size_; }
     192             :   //  void SDMDataObject::BinaryPart::size (unsigned int value) { size_ = value; }
     193             :   
     194           0 :   const vector<AxisName>& SDMDataObject::BinaryPart::axes() const { return axes_; }
     195             :   //  void SDMDataObject::BinaryPart::axes (const vector<AxisName>& axes) { axes_ = axes; }
     196             : 
     197           0 :   void SDMDataObject::BinaryPart::owner(const SDMDataObject* o) { owner_ = o; }
     198             :   // SDMDataObject::BinaryPart
     199             :   
     200             :   // SDMDataObject::AutoDataBinaryPart:: methods
     201           0 :   SDMDataObject::AutoDataBinaryPart::AutoDataBinaryPart(): BinaryPart() { normalized_ = false; }
     202           0 :   SDMDataObject::AutoDataBinaryPart::~AutoDataBinaryPart() {;}
     203             : 
     204           0 :   SDMDataObject::AutoDataBinaryPart::AutoDataBinaryPart(unsigned int size,
     205             :                                                         const vector<AxisName>& axes,
     206           0 :                                                         bool normalized) : BinaryPart(size, axes) {
     207           0 :     normalized_ = normalized;
     208           0 :   }
     209             : 
     210           0 :   bool SDMDataObject::AutoDataBinaryPart::normalized() const { return normalized_; }
     211             : 
     212             :   // SDMDataObject::AutoDataBinaryPart::
     213             : 
     214             :   // SDMDataObject::ZeroLagsBinaryPart:: methods
     215           0 :   SDMDataObject::ZeroLagsBinaryPart::ZeroLagsBinaryPart(): BinaryPart() { correlatorType_ = XF; }
     216           0 :   SDMDataObject::ZeroLagsBinaryPart::~ZeroLagsBinaryPart() {;}
     217             : 
     218           0 :   SDMDataObject::ZeroLagsBinaryPart::ZeroLagsBinaryPart(unsigned int size,
     219             :                                                         const vector<AxisName>& axes,
     220           0 :                                                         CorrelatorType correlatorType) : BinaryPart(size, axes) {
     221           0 :     correlatorType_ = correlatorType;
     222           0 :   }
     223             : 
     224           0 :   CorrelatorType SDMDataObject::ZeroLagsBinaryPart::correlatorType() const { return correlatorType_; }
     225             : 
     226             :   // SDMDataObject::ZeroLagsBinaryPart::
     227             : 
     228             :   // SDMDataObject::DataStruct:: methods
     229             :   //
     230             : 
     231             :   /**
     232             :    * The empty constructor.
     233             :    *
     234             :    * @note This constructor should never be used.
     235             :    */
     236           0 :   SDMDataObject::DataStruct::DataStruct() {owner_ = 0;}
     237             : 
     238             :   /**
     239             :    * The destructor.
     240             :    */
     241           0 :   SDMDataObject::DataStruct::~DataStruct() {;}
     242             : 
     243             : 
     244             :   /** 
     245             :    * The full constructor.
     246             :    */
     247           0 :   SDMDataObject::DataStruct::DataStruct(const vector<AtmPhaseCorrection>& apc,
     248             :                                         const vector<Baseband>& basebands,
     249             :                                         const BinaryPart& flags,
     250             :                                         const BinaryPart& actualTimes,
     251             :                                         const BinaryPart& actualDurations,
     252             :                                         const ZeroLagsBinaryPart& zeroLags,
     253             :                                         const BinaryPart& crossData,
     254             :                                         const AutoDataBinaryPart& autoData
     255           0 :                                         ):apc_(apc),
     256           0 :                                           basebands_(basebands),
     257           0 :                                           flags_(flags),
     258           0 :                                           actualTimes_(actualTimes),
     259           0 :                                           actualDurations_(actualDurations),
     260           0 :                                           zeroLags_(zeroLags),
     261           0 :                                           crossData_(crossData),
     262           0 :                                           autoData_(autoData)
     263             :   {
     264           0 :     owner_ = 0;
     265           0 :   }      
     266           0 :   const vector<AtmPhaseCorrection>& SDMDataObject::DataStruct::apc() const { return apc_; }
     267             :   //  void SDMDataObject::DataStruct::apc(const vector<AtmPhaseCorrection>& value) { apc_ = value; }
     268             :   
     269           0 :   const vector<SDMDataObject::Baseband>& SDMDataObject::DataStruct::basebands() const { return basebands_; }
     270             :   //  void SDMDataObject::DataStruct::basebands(const vector<SDMDataObject::Baseband>& value) { basebands_ = value; }
     271             :   
     272           0 :   const SDMDataObject::BinaryPart& SDMDataObject::DataStruct::flags() const { return flags_;}
     273             :   //  void SDMDataObject::DataStruct::flags(const SDMDataObject::BinaryPart& value) { flags_ = value; }
     274             :   
     275           0 :   const SDMDataObject::BinaryPart& SDMDataObject::DataStruct::actualTimes() const { return actualTimes_;}
     276             :   //  void SDMDataObject::DataStruct::actualTimes(const SDMDataObject::BinaryPart& value) { actualTimes_ = value; }
     277             :  
     278           0 :   const SDMDataObject::BinaryPart& SDMDataObject::DataStruct::actualDurations() const { return actualDurations_;}
     279             :   //  void SDMDataObject::DataStruct::actualDurations(const SDMDataObject::BinaryPart& value) { actualDurations_ = value; }
     280             :   
     281           0 :   const SDMDataObject::ZeroLagsBinaryPart& SDMDataObject::DataStruct::zeroLags() const { 
     282           0 :     if (owner_ && owner_->isTP()) Utils::invalidCall("SDMDataObject::DataStruct::zeroLags", owner_);
     283           0 :     return zeroLags_;
     284             :   } 
     285             : 
     286             :   //  void SDMDataObject::DataStruct::zeroLags(const SDMDataObject::BinaryPart& value) { 
     287             :   //    if (owner_ && owner_->isTP()) Utils::invalidCall("SDMDataObject::DataStruct::zeroLags", owner_);
     288             :   //    zeroLags_ = value;
     289             :   //  }
     290             : 
     291           0 :   const SDMDataObject::BinaryPart& SDMDataObject::DataStruct::crossData() const { return crossData_;}
     292             :   //  void SDMDataObject::DataStruct::crossData(const SDMDataObject::BinaryPart& value) { crossData_ = value; }
     293             :   
     294           0 :   const SDMDataObject::AutoDataBinaryPart& SDMDataObject::DataStruct::autoData() const { return autoData_;} 
     295             :   //  void SDMDataObject::DataStruct::autoData(const SDMDataObject::BinaryPart& value) { autoData_ = value; }
     296           0 :   void SDMDataObject::DataStruct::owner(const SDMDataObject* o) { owner_ = o; }
     297             : 
     298           0 :   void SDMDataObject::DataStruct::checkCoordinate(unsigned int ibb, unsigned int ispw) const {
     299           0 :     ostringstream oss;
     300             : 
     301           0 :     if (ibb >= basebands_.size()) {
     302           0 :       oss << "In '("<< ibb << "," << ispw <<")' '" << ibb << "' is invalid as a baseband index, it should not exceed '" << basebands_.size()-1 << "'";
     303           0 :       throw SDMDataObjectException(oss.str());
     304             :     }
     305             :      
     306           0 :     if (ispw >= basebands_.at(ibb).spectralWindows().size()) {
     307           0 :       oss << "In '("<< ibb << "," << ispw <<")' '" << ispw << "' is invalid as a spectral window index, it should not exceed '" << basebands_.at(ibb).spectralWindows().size()-1 << "'";
     308             :     }    
     309           0 :   }
     310             : 
     311           0 :   bool SDMDataObject::DataStruct::associatedSPW(unsigned int ibb,
     312             :                                                 unsigned int ispw1,
     313             :                                                 unsigned int ispw2) {
     314           0 :     checkCoordinate(ibb, ispw1);
     315           0 :     checkCoordinate(ibb, ispw2);
     316             : 
     317           0 :     ostringstream oss;
     318           0 :     oss << ibb << " " << ispw1;
     319           0 :     string key = oss.str();
     320             : 
     321           0 :     oss.str("");
     322             :     
     323           0 :     oss << ibb << " " << ispw2;
     324           0 :     string value = oss.str();
     325             :     
     326           0 :     map<string, string>::iterator iter1 = imageSPW_.find(key);
     327           0 :     map<string, string>::iterator iter2 = imageOfSPW_.find(key);
     328             : 
     329           0 :     return ( ((iter1 != imageSPW_.end()) && ((iter1->second).compare(value) == 0))
     330           0 :              ||
     331           0 :              ((iter2 != imageOfSPW_.end()) && ((iter2->second).compare(value) == 0))
     332           0 :              );
     333           0 :   }
     334             : 
     335           0 :   void SDMDataObject::DataStruct::divorceSPW(unsigned int ibb, unsigned int ispw) {
     336           0 :     checkCoordinate(ibb, ispw);
     337             : 
     338           0 :     ostringstream oss;
     339           0 :     oss << ibb << " " << ispw; 
     340           0 :     string key = oss.str();
     341           0 :     map<string, string>::iterator iter0, iter1;
     342           0 :     if ((iter0 = imageSPW_.find(key)) != imageSPW_.end()) {
     343           0 :       if ((iter1 = imageOfSPW_.find(iter0->second)) != imageOfSPW_.end()) {
     344           0 :         imageOfSPW_.erase(iter1);
     345             :       }
     346           0 :       imageSPW_.erase(iter0);
     347             :     }
     348           0 :   }
     349             : 
     350           0 :   void SDMDataObject::DataStruct::imageSPW(unsigned int ibb,
     351             :                                            unsigned int ispw1,
     352             :                                            unsigned int ispw2) {
     353           0 :     checkCoordinate(ibb, ispw1);
     354           0 :     checkCoordinate(ibb, ispw2);
     355             :     
     356           0 :     if (!associatedSPW(ibb, ispw1, ispw2)) {
     357           0 :       divorceSPW(ibb, ispw1);
     358           0 :       divorceSPW(ibb, ispw2);
     359             :     }
     360             : 
     361           0 :     ostringstream oss;
     362             : 
     363           0 :     oss << ibb << " " << ispw1;
     364           0 :     string key = oss.str();
     365             : 
     366           0 :     oss.str("");
     367           0 :     oss << ibb << " " << ispw2;
     368           0 :     string value = oss.str();
     369           0 :     imageSPW_[key] = value;
     370           0 :     imageOfSPW_[value] = key;
     371           0 :   }
     372             : 
     373           0 :   void SDMDataObject::DataStruct::imageOfSPW(unsigned int ibb,
     374             :                                              unsigned int ispw1,
     375             :                                              unsigned int ispw2) {
     376           0 :     imageSPW(ibb,ispw2,ispw1);
     377           0 :   }
     378             : 
     379           0 :   const SDMDataObject::SpectralWindow* SDMDataObject::DataStruct::imageSPW(unsigned int ibb,
     380             :                                                                            unsigned int ispw) const {
     381           0 :     checkCoordinate(ibb, ispw);
     382             : 
     383           0 :     ostringstream oss;
     384             : 
     385           0 :     oss << ibb << " " << ispw;
     386           0 :     string key = oss.str();
     387             : 
     388           0 :     map<string, string>::const_iterator iter;
     389           0 :     if ((iter = imageSPW_.find(key)) == imageSPW_.end())
     390           0 :       return 0;
     391             : 
     392             :     unsigned int ibbImage;
     393             :     unsigned int ispwImage;
     394             : 
     395           0 :     istringstream iss(iter->second);
     396           0 :     iss >> ibbImage;
     397           0 :     iss >> ispwImage;
     398           0 :     checkCoordinate (ibbImage, ispwImage);
     399             : 
     400           0 :     return &(basebands_.at(ibbImage).spectralWindows().at(ispwImage));
     401           0 :   }
     402             : 
     403             : 
     404           0 :   const SDMDataObject::SpectralWindow* SDMDataObject::DataStruct::imageOfSPW(unsigned int ibb,
     405             :                                                                              unsigned int ispw) const {
     406           0 :     checkCoordinate(ibb, ispw);
     407             : 
     408           0 :     ostringstream oss;
     409             : 
     410           0 :     oss << ibb << " " << ispw;
     411           0 :     string key = oss.str();
     412             : 
     413           0 :     map<string, string>::const_iterator iter;
     414           0 :     if ((iter = imageOfSPW_.find(key)) == imageOfSPW_.end())
     415           0 :       return 0;
     416             : 
     417             :     unsigned int ibbOf;
     418             :     unsigned int ispwOf;
     419             : 
     420           0 :     istringstream iss(iter->second);
     421           0 :     iss >> ibbOf;
     422           0 :     iss >> ispwOf;
     423           0 :     checkCoordinate (ibbOf, ispwOf);
     424             :     
     425           0 :     return &(basebands_.at(ibbOf).spectralWindows().at(ispwOf));
     426           0 :   }
     427             :   
     428             : 
     429             :   // SDMDataObject::DataStruct
     430             : 
     431             :   // SDMDataObject:: methods
     432             :   //
     433             : 
     434             : #define TSTVALID() if (valid_ == false) throw SDMDataObjectException("no valid binary data in this SDMDataObject.");
     435             : 
     436             : 
     437           0 :   SDMDataObject::SDMDataObject() {numTime_ = 0; valid_  = false; aborted_ = false; }
     438           0 :   SDMDataObject::SDMDataObject(unsigned long long startTime,
     439             :                                const string& dataOID,
     440             :                                unsigned int dimensionality,
     441             :                                const string& execBlockUID, 
     442             :                                unsigned int execBlockNum,
     443             :                                unsigned int scanNum,
     444             :                                unsigned int subscanNum,
     445             :                                unsigned int numAntenna,
     446             :                                CorrelationMode correlationMode,
     447           0 :                                const SDMDataObject::DataStruct& dataStruct):
     448           0 :     startTime_(startTime),
     449           0 :     dataOID_(dataOID),
     450           0 :     dimensionality_(dimensionality),
     451           0 :     numTime_(0),
     452           0 :     execBlockUID_(execBlockUID),
     453           0 :     execBlockNum_(execBlockNum),
     454           0 :     scanNum_(scanNum),
     455           0 :     subscanNum_(subscanNum),
     456           0 :     numAntenna_(numAntenna),
     457           0 :     correlationMode_(correlationMode),
     458           0 :     dataStruct_(dataStruct){
     459           0 :     valid_ = true;
     460           0 :     aborted_ = false;
     461           0 :   }
     462             :   
     463             :   
     464           0 :   SDMDataObject::SDMDataObject(unsigned long long startTime,
     465             :                                const string& dataOID,
     466             :                                unsigned int dimensionality,
     467             :                                unsigned int numTime,
     468             :                                const string& execBlockUID,
     469             :                                unsigned int execBlockNum,
     470             :                                unsigned int scanNum,
     471             :                                unsigned int subscanNum,
     472             :                                unsigned int numAntenna,
     473           0 :                                const SDMDataObject::DataStruct& dataStruct):
     474           0 :     startTime_(startTime),
     475           0 :     dataOID_(dataOID),
     476           0 :     dimensionality_(dimensionality),
     477           0 :     numTime_(numTime),
     478           0 :     execBlockUID_(execBlockUID),
     479           0 :     execBlockNum_(execBlockNum),
     480           0 :     scanNum_(scanNum),
     481           0 :     subscanNum_(subscanNum),
     482           0 :     numAntenna_(numAntenna),
     483           0 :     dataStruct_(dataStruct)
     484           0 :   { valid_ = true; aborted_ = false;}
     485             :   
     486           0 :   string SDMDataObject::title() const { TSTVALID(); return title_; }
     487           0 :   void SDMDataObject::title(const string& value) { title_ = value; }
     488             : 
     489           0 :   const ByteOrder* SDMDataObject::byteOrder() const { TSTVALID(); return byteOrder_; }
     490             : 
     491           0 :   unsigned long long SDMDataObject::startTime() const {TSTVALID(); return startTime_; }
     492           0 :   void SDMDataObject::startTime(unsigned long long value) { startTime_ = value; }
     493             :   
     494           0 :   unsigned int SDMDataObject::numTime() const  {TSTVALID(); return numTime_; }
     495           0 :   void SDMDataObject::numTime(unsigned int value) { numTime_ = value; }
     496             :   
     497           0 :   string SDMDataObject::dataOID() const {TSTVALID(); return dataOID_; }
     498           0 :   void SDMDataObject::dataOID(const string& value) { dataOID_ = value; }
     499             :   
     500           0 :   unsigned int SDMDataObject::dimensionality() const  {TSTVALID(); return dimensionality_; }
     501           0 :   void SDMDataObject::dimensionality( unsigned int value ) { dimensionality_ = value; }
     502             : 
     503           0 :   string SDMDataObject::execBlockUID() const {TSTVALID(); return execBlockUID_; }
     504           0 :   void SDMDataObject::execBlockUID (const string& value) { execBlockUID_ = value; }
     505             :   
     506           0 :   unsigned int SDMDataObject::execBlockNum() const  {TSTVALID(); return execBlockNum_; }
     507           0 :   void SDMDataObject::execBlockNum (unsigned int value ) { execBlockNum_ = value; }
     508             :   
     509           0 :   unsigned int SDMDataObject::scanNum() const  {TSTVALID(); return scanNum_ ; }
     510           0 :   void SDMDataObject::scanNum( unsigned int value) { scanNum_ = value; }
     511             :   
     512           0 :   unsigned int SDMDataObject::subscanNum() const {TSTVALID(); return subscanNum_; }
     513           0 :   void SDMDataObject::subscanNum(int value) { subscanNum_ = value; }
     514             :   
     515           0 :   string SDMDataObject::projectPath() const {
     516           0 :     TSTVALID();
     517           0 :     ostringstream oss;
     518           0 :     oss << execBlockNum_ << "/" << scanNum_ << "/" << subscanNum_ << "/";
     519           0 :     return oss.str();
     520           0 :   }
     521             : 
     522           0 :   unsigned int SDMDataObject::numAntenna() const  {TSTVALID();  return numAntenna_; }
     523           0 :   void SDMDataObject::numAntenna (unsigned int value) { numAntenna_ = value; }
     524             :   
     525           0 :   const SDMDataObject::DataStruct& SDMDataObject::dataStruct() const {TSTVALID(); return dataStruct_; }
     526           0 :   void SDMDataObject::dataStruct(const SDMDataObject::DataStruct& value) {dataStruct_ = value; }
     527             : 
     528           0 :   CorrelationMode SDMDataObject::correlationMode() const  {TSTVALID(); return correlationMode_; }
     529             : 
     530           0 :   OptionalSpectralResolutionType SDMDataObject::spectralResolutionType() const {TSTVALID(); return spectralResolutionType_; }
     531           0 :   ProcessorType SDMDataObject::processorType() const {TSTVALID(); return processorType_; }
     532           0 :   CorrelatorType SDMDataObject::correlatorType() const {
     533           0 :     TSTVALID(); 
     534           0 :     if (processorType_ == CORRELATOR) 
     535           0 :       return dataStruct_.zeroLags_.correlatorType_ ;
     536             :     else
     537           0 :       throw SDMDataObjectException("no correlator type defined in the current context (processor type = '" +
     538           0 :                                    CProcessorType::name(processorType_));
     539             :   }
     540             : 
     541             : 
     542           0 :   bool SDMDataObject::inTitle(const std::string&  what) const {TSTVALID();
     543             :     // string s(title_);
     544             :     // boost::iterator_range<std::string::iterator> range = boost::algorithm::ifind_first(s, what);
     545             :     // return !range.empty();
     546           0 :     return title_.find(what) != std::string::npos;
     547             :   }
     548             : 
     549             :   /*
     550             :    * Due to the fact that the value of processor type in the global header does not allow to really determine which processor has produced the data
     551             :    * (this is particularly true for ALMA_RADIOMETER and SQUARE_LAW_DETECTOR which fall under the same type PROCESSOR, I decided to use
     552             :    * the content of the title to make a clear distinction. Of course this is based on a non said conventions used to form the title...
     553             :    */ 
     554           0 :   bool SDMDataObject::isTP() const {TSTVALID(); return inTitle("Total Power");}
     555           0 :   bool SDMDataObject::isWVR() const {TSTVALID(); return inTitle("WVR");}
     556           0 :   bool SDMDataObject::isCorrelation() const {TSTVALID(); return processorType() == CORRELATOR;}
     557             : 
     558             : 
     559             :   /*
     560             :    * hasPackedData returns true if all the integrations are grouped in one subset for all the timestamps and conversely false if 
     561             :    * there is one subset per integration (i.e. per timestamp).
     562             :    */
     563           0 :   bool SDMDataObject::hasPackedData() const {TSTVALID(); return dimensionality() == 0;}
     564             :   
     565           0 :   const vector<SDMDataSubset>& SDMDataObject::sdmDataSubsets() const {
     566           0 :     TSTVALID();
     567           0 :     return dataSubsets_;
     568             :   }
     569             : 
     570           0 :   const vector<SDMDataSubset>& SDMDataObject::corrDataSubsets() const {
     571           0 :     TSTVALID();
     572           0 :     if (isTP()) Utils::invalidCall("corrDataSubsets", this);
     573           0 :     return dataSubsets_;
     574             :   }
     575             : 
     576           0 :   const SDMDataSubset& SDMDataObject::sdmDataSubset(const string& projectPath) const {
     577           0 :     TSTVALID();
     578             : 
     579           0 :     map<string, unsigned int>::const_iterator iter;
     580           0 :     iter = str2index_.find(projectPath);
     581           0 :     if (iter == str2index_.end())
     582           0 :       throw SDMDataObjectException("dataSubset with project path '" + projectPath + "' not found.");
     583           0 :     return dataSubsets_.at(iter->second);
     584             :   }
     585             : 
     586             : 
     587             : 
     588           0 :   bool SDMDataObject::aborted() const {
     589           0 :     if (isTP()) Utils::invalidCall("SDMDataObject::aborted", this);
     590             :     
     591           0 :     return aborted_;
     592             :   }
     593             : 
     594           0 :   unsigned long long SDMDataObject::abortTime() const {
     595           0 :     if (isTP()) Utils::invalidCall("SDMDataObject::abortTime", this);
     596             : 
     597           0 :     return abortTime_;
     598             : 
     599             :   }
     600             : 
     601           0 :   string SDMDataObject::abortReason() const {
     602           0 :     if (isTP()) Utils::invalidCall("SDMDataObject::abortReason", this);
     603             : 
     604           0 :     return abortReason_;
     605             : 
     606             :   }
     607             : 
     608           0 :   const SDMDataSubset& SDMDataObject::tpDataSubset() const {
     609           0 :     TSTVALID();
     610           0 :     if (isCorrelation()) Utils::invalidCall("tpDataSubset", this);
     611           0 :     return dataSubsets_.at(0);
     612             :     //return str2index_.begin()->second;
     613             :   }
     614             : 
     615           0 :   void SDMDataObject::tpDataSubset(const SDMDataSubset& value) {
     616           0 :     if (isCorrelation()) Utils::invalidCall("tpDataSubset", this);
     617           0 :     dataSubsets_.push_back(value);
     618             : 
     619           0 :     string projectPath = value.projectPath();
     620           0 :     if (SDMDataObjectParser::trim(projectPath).size() == 0)
     621           0 :       throw (SDMDataObjectException("can't accept a data subset without a project path"));
     622             : 
     623           0 :     str2index_[projectPath] = dataSubsets_.size() - 1;
     624           0 :   }
     625             :   
     626           0 :   vector<string> SDMDataObject::projectPaths() const {
     627           0 :     vector<string> result(str2index_.size());
     628             : 
     629           0 :     map<string, unsigned int>::const_iterator iter = str2index_.begin();
     630             :  
     631           0 :     for ( ; iter != str2index_.end(); iter++)
     632           0 :       result[iter->second] = iter->first;
     633             :     
     634           0 :     return result;
     635           0 :   }
     636             :  
     637           0 :   void SDMDataObject::done() {
     638           0 :     valid_ = false;
     639             :     
     640           0 :     str2index_.clear();
     641           0 :     dataSubsets_.clear();
     642           0 :   }
     643             : 
     644           0 :   void SDMDataObject::append(const SDMDataSubset& value) {
     645           0 :     TSTVALID();
     646           0 :     dataSubsets_.push_back(value);
     647           0 :     str2index_[value.projectPath()] = dataSubsets_.size()-1;
     648           0 :     numTime_ = dataSubsets_.size();
     649           0 :   }
     650             :   
     651           0 :   void SDMDataObject::owns() {
     652             :     // I own my correlationMode
     653           0 :     dataStruct_.owner_ = this;
     654             : 
     655             :     // I own my basebands and their spectral windows
     656           0 :     for (unsigned int i = 0; i < dataStruct_.basebands_.size(); i++) {
     657           0 :       Baseband& bb = dataStruct_.basebands_.at(i);
     658           0 :       bb.owner_ = this;
     659             :       
     660           0 :       for (unsigned int j = 0 ; j < bb.spectralWindows_.size(); j++) {
     661           0 :         bb.spectralWindows_.at(j).owner_ = this;
     662             :       }
     663             :     }
     664             : 
     665             :     // I own my binary part descriptions
     666             :     // (let's all of them, even those which are not relevant)
     667           0 :     dataStruct_.flags_.owner_   = this;
     668           0 :     dataStruct_.actualTimes_.owner_     = this;
     669           0 :     dataStruct_.actualDurations_.owner_ = this;
     670           0 :     dataStruct_.zeroLags_.owner_        = this;
     671           0 :     dataStruct_.crossData_.owner_       = this;
     672           0 :     dataStruct_.autoData_.owner_        = this;
     673             : 
     674             :     // I own my dataSubsets
     675           0 :     for (unsigned int i = 0; i < dataSubsets_.size(); i++)
     676           0 :       dataSubsets_.at(i).owner_ = this;
     677           0 :   }
     678             : 
     679             : 
     680             : #define FIRST_JAN_2007 4674326400000000000LL
     681             :   
     682           0 :   string SDMDataObject::toString() const {
     683           0 :     TSTVALID();
     684           0 :     ostringstream result;
     685             :     //ptime t1(date(2007, Jan, 1), time_duration(0, 0, 0,(startTime_ - FIRST_JAN_2007)/1000 ));
     686           0 :     result << "SDMDataObject at address '" << this << "' :" << endl; 
     687           0 :     result << "XML Schema version = " << schemaVersion_ << endl;
     688           0 :     result << "Byte order = " << byteOrder_->toString() << endl;
     689             :     //result << "startTime = " << startTime_ << " (" << to_simple_string(t1) << ")" << endl;
     690           0 :     result << "startTime = " << startTime_ << endl;
     691           0 :     result << "dataOID = " << dataOID_ << endl;
     692           0 :     result << "title = " << title_ << endl;
     693           0 :     if (dimensionality_==0) 
     694           0 :       result << "numTime = " << numTime_ << endl;
     695             :     else
     696           0 :       result << "dimensionality = " << dimensionality_ << endl;
     697           0 :     result << "execBlockUID = " << execBlockUID_ << endl;
     698           0 :     result << "execBlockNum = " << execBlockNum_ << endl;
     699           0 :     result << "scanNum = " << scanNum_ << endl;
     700           0 :     result << "subscanNum = " << subscanNum_ << endl;
     701           0 :     result << "numAntenna = " << numAntenna_ << endl;
     702           0 :     result << "correlationMode = " << CCorrelationMode::name(correlationMode_) << endl;
     703           0 :     if (spectralResolutionType_.present()) 
     704           0 :       result << "spectralResolutionType = " << CSpectralResolutionType::name(spectralResolutionType_.literal()) << endl;
     705           0 :     result << "processorType = " << CProcessorType::name(processorType_) << endl;
     706           0 :     if ( correlationMode_ != AUTO_ONLY ) {
     707           0 :       result << "atmospheric phase correction = " << TOSTRING<AtmPhaseCorrection, CAtmPhaseCorrection>(dataStruct_.apc_) << endl;
     708             :     } 
     709           0 :     const vector<Baseband>& bbs = dataStruct_.basebands();
     710           0 :     for (unsigned int i = 0; i < bbs.size(); i++) {
     711           0 :       result << "baseband #" << i << ":" << endl;
     712           0 :       result << "\tname = " << CBasebandName::name(bbs.at(i).name()) << endl;
     713           0 :       const vector<SpectralWindow>& spWs = bbs.at(i).spectralWindows();
     714           0 :       for (unsigned int j = 0; j < spWs.size(); j++) {
     715           0 :         result << "\tspectralWindow #" << j << ":" << endl;
     716             :         
     717           0 :         SpectralWindow spW = spWs.at(j);
     718           0 :         result << "\t\t" << "sw = " << spW.strSw() << endl;
     719           0 :         switch (correlationMode_) {
     720           0 :         case CROSS_ONLY :
     721           0 :           result << "\t\t" << "crossPolProducts = " << TOSTRING<StokesParameter, CStokesParameter>(spW.crossPolProducts()) << endl;
     722           0 :           result << "\t\t" << "scaleFactor = " << spW.scaleFactor() << endl;
     723           0 :           result << "\t\t" << "numSpectralPoint = " << spW.numSpectralPoint() << endl;
     724           0 :           result << "\t\t" << "numBin = " << spW.numBin() << endl;
     725           0 :           break;
     726             :           
     727           0 :         case AUTO_ONLY :
     728           0 :           result << "\t\t" << "sPolProducts = " << TOSTRING<StokesParameter, CStokesParameter>(spW.sdPolProducts()) << endl;
     729           0 :           result << "\t\t" << "numSpectralPoint = " << spW.numSpectralPoint() << endl;
     730           0 :           result << "\t\t" << "numBin = " << spW.numBin() << endl;
     731           0 :           break;
     732             : 
     733           0 :         case CROSS_AND_AUTO :
     734           0 :           result << "\t\t" << "crossPolProducts = " << TOSTRING<StokesParameter, CStokesParameter>(spW.crossPolProducts()) << endl;
     735           0 :           result << "\t\t" << "sdPolProducts = " << TOSTRING<StokesParameter, CStokesParameter>(spW.sdPolProducts()) << endl;
     736           0 :           result << "\t\t" << "scaleFactor = " << spW.scaleFactor() << endl;
     737           0 :           result << "\t\t" << "numSpectralPoint = " << spW.numSpectralPoint() << endl;
     738           0 :           result << "\t\t" << "numBin = " << spW.numBin() << endl;
     739             :           
     740           0 :           break;
     741             :           
     742           0 :         default:
     743           0 :           break;
     744             :         }
     745           0 :         result << "\t\t" << "sideband = " << TOSTRING<NetSideband, CNetSideband>(spW.sideband()) << endl;
     746           0 :         if (spW.strSw().size() > 0)    
     747           0 :         if (spW.strImage().size() > 0) result << "\t\t" << "image = " << spW.strImage() << endl;
     748           0 :       }
     749             :     }
     750             :         
     751           0 :     result << "flags:" << endl;
     752           0 :     result << "\tsize = " << dataStruct_.flags().size() << endl;
     753           0 :     result << "\taxes = " << TOSTRING<AxisName, CAxisName>(dataStruct_.flags().axes()) << endl; 
     754             :     
     755           0 :     result << "actualTimes:" << endl;
     756           0 :     result << "\tsize = " << dataStruct_.actualTimes().size() << endl;
     757           0 :     result << "\taxes = " << TOSTRING<AxisName, CAxisName>(dataStruct_.actualTimes().axes()) << endl; 
     758             :     
     759           0 :     result << "actualDurations:" << endl;
     760           0 :     result << "\tsize = " << dataStruct_.actualDurations().size() << endl;
     761           0 :     result << "\taxes = " << TOSTRING<AxisName, CAxisName>(dataStruct_.actualDurations().axes()) << endl;
     762             :     
     763           0 :     if ((processorType_ == CORRELATOR)
     764           0 :         && (dataStruct_.zeroLags_.correlatorType_ != FX)
     765           0 :         && (dataStruct_.zeroLags_.size_ != 0)) {
     766           0 :       result << "zeroLags:" << endl;
     767           0 :       result << "\tsize = " << dataStruct_.zeroLags().size() << endl;
     768           0 :       result << "\taxes = " << TOSTRING<AxisName, CAxisName>(dataStruct_.zeroLags().axes()) << endl;
     769           0 :       result << "\tcorrelatorType = " << TOSTRING<CorrelatorType, CCorrelatorType>(dataStruct_.zeroLags_.correlatorType_) << endl;
     770             :     }
     771             : 
     772           0 :     switch (correlationMode_) {
     773           0 :     case CROSS_ONLY :
     774           0 :       result << "crossData:" << endl;
     775           0 :       result << "\tsize = " << dataStruct_.crossData().size() << endl;
     776           0 :       result << "\taxes = " << TOSTRING<AxisName, CAxisName> (dataStruct_.crossData().axes()) << endl;
     777           0 :       break;
     778             :       
     779           0 :     case AUTO_ONLY :
     780           0 :       result << "autoData:" << endl;
     781           0 :       result << "\tsize = " << dataStruct_.autoData().size() << endl;
     782           0 :       result << "\taxes = " << TOSTRING<AxisName, CAxisName>(dataStruct_.autoData().axes()) << endl;
     783           0 :       result << "\tnormalized = " << (dataStruct_.autoData_.normalized_ ? "true" : "false") << endl;
     784           0 :       break;
     785             :       
     786           0 :     case CROSS_AND_AUTO :
     787           0 :       result << "crossData:" << endl;
     788           0 :       result << "\tsize = " << dataStruct_.crossData().size() << endl;
     789           0 :       result << "\taxes = " << TOSTRING<AxisName, CAxisName>(dataStruct_.crossData().axes()) << endl;
     790             :       
     791           0 :       result << "autoData:" << endl;
     792           0 :       result << "\tsize = " << dataStruct_.autoData().size() << endl;
     793           0 :       result << "\taxes = " << TOSTRING<AxisName, CAxisName>(dataStruct_.autoData().axes()) << endl;
     794           0 :       result << "\tnormalized = " << (dataStruct_.autoData_.normalized_ ? "true" : "false") << endl;
     795           0 :       break;
     796             :         
     797           0 :     default:
     798           0 :       break;
     799             :     }
     800           0 :     return result.str();
     801           0 :   }
     802             : 
     803             : 
     804           0 :   void SDMDataObject::toXML(const BinaryPart& binaryPart, const string& elementName, ostringstream& oss) const {
     805           0 :     oss << "<" << elementName ;
     806           0 :     oss << " " << HeaderParser::SIZE << "=" << QUOTE(binaryPart.size())
     807           0 :         << " " << HeaderParser::AXES << "=" << QUOTE<AxisName, CAxisName>(binaryPart.axes())
     808           0 :         << "/>"
     809           0 :         << endl;
     810           0 :   }
     811             : 
     812           0 :   void SDMDataObject::toXML(const AutoDataBinaryPart& autoDataBinaryPart, const string& elementName, ostringstream& oss) const {
     813           0 :     oss << "<" << elementName ;
     814           0 :     oss << " " << HeaderParser::SIZE << "=" << QUOTE(autoDataBinaryPart.size())
     815           0 :         << " " << HeaderParser::AXES << "=" << QUOTE<AxisName, CAxisName>(autoDataBinaryPart.axes())
     816           0 :         << " " << HeaderParser::NORMALIZED << "=" << QUOTE(autoDataBinaryPart.normalized())
     817           0 :         << "/>"
     818           0 :         << endl;
     819           0 :   }
     820             : 
     821           0 :   void SDMDataObject::toXML(const ZeroLagsBinaryPart& zeroLagsBinaryPart, const string& elementName, ostringstream& oss) const {
     822           0 :     oss << "<" << elementName ;
     823           0 :     oss << " " << HeaderParser::SIZE << "=" << QUOTE(zeroLagsBinaryPart.size())
     824           0 :         << " " << HeaderParser::AXES << "=" << QUOTE<AxisName, CAxisName>(zeroLagsBinaryPart.axes())
     825           0 :         << " " << HeaderParser::CORRELATORTYPE << "=" << QUOTE<CorrelatorType, CCorrelatorType>(zeroLagsBinaryPart.correlatorType())
     826           0 :         << "/>"
     827           0 :         << endl;
     828           0 :   }
     829             : 
     830           0 :   void SDMDataObject::spectralWindowsToXML(const vector<Baseband>& basebands,unsigned int ibb,  ostringstream& oss) const {
     831           0 :     const vector<SDMDataObject::SpectralWindow>& spectralWindows = basebands.at(ibb).spectralWindows();
     832           0 :     for (unsigned int i = 0; i < spectralWindows.size(); i++) {
     833           0 :       const SpectralWindow& spectralWindow = spectralWindows.at(i);
     834           0 :       oss << "<" << HeaderParser::SPECTRALWINDOW;
     835           0 :       oss << " " << HeaderParser::SW << "=" << QUOTE(i+1);
     836           0 :       oss << " " << HeaderParser::SWBB << "=" << QUOTE(CBasebandName::name(basebands.at(ibb).name()));
     837             :       
     838           0 :       switch (correlationMode_) {
     839           0 :       case CROSS_ONLY:
     840           0 :         oss << " " << HeaderParser::CROSSPOLPRODUCTS << "=" << QUOTE<StokesParameter, CStokesParameter>(spectralWindow.crossPolProducts()) ;
     841           0 :         oss << " " << HeaderParser::SCALEFACTOR << "=" << QUOTE(spectralWindow.scaleFactor()) ;
     842           0 :         oss << " " << HeaderParser::NUMSPECTRALPOINT << "=" << QUOTE(spectralWindow.numSpectralPoint()) ;
     843           0 :         oss << " " << HeaderParser::NUMBIN << "=" << QUOTE(spectralWindow.numBin()) ;
     844           0 :         break;
     845             :         
     846           0 :       case AUTO_ONLY:
     847           0 :         oss << " " << HeaderParser::SDPOLPRODUCTS << "=" << QUOTE<StokesParameter, CStokesParameter>(spectralWindow.sdPolProducts()) ;
     848           0 :         oss << " " << HeaderParser::NUMSPECTRALPOINT << "=" << QUOTE(spectralWindow.numSpectralPoint()) ;
     849           0 :         oss << " " << HeaderParser::NUMBIN << "=" << QUOTE(spectralWindow.numBin()) ;
     850           0 :         break;
     851             :         
     852           0 :       case CROSS_AND_AUTO:
     853           0 :         oss << " " << HeaderParser::CROSSPOLPRODUCTS << "=" << QUOTE<StokesParameter, CStokesParameter>(spectralWindow.crossPolProducts()) ;
     854           0 :         oss << " " << HeaderParser::SDPOLPRODUCTS << "=" << QUOTE<StokesParameter, CStokesParameter>(spectralWindow.sdPolProducts()) ;
     855           0 :         oss << " " << HeaderParser::SCALEFACTOR << "=" << QUOTE(spectralWindow.scaleFactor()) ;
     856           0 :         oss << " " << HeaderParser::NUMSPECTRALPOINT << "=" << QUOTE(spectralWindow.numSpectralPoint()) ;
     857           0 :         oss << " " << HeaderParser::NUMBIN << "=" << QUOTE(spectralWindow.numBin()) ;
     858           0 :         break;
     859             :       }
     860             : 
     861           0 :       oss << " " << HeaderParser::SIDEBAND << "=" << QUOTE<NetSideband, CNetSideband>(spectralWindow.sideband());
     862             : 
     863           0 :       if (spectralWindow.strImage().size() > 0) oss << " " << HeaderParser::IMAGE << "=" << QUOTE(::atoi(spectralWindow.strImage().c_str()));
     864             :       
     865           0 :       oss << "/>" << endl;
     866             :     }
     867           0 :   }
     868             : 
     869           0 :   void SDMDataObject::basebandsToXML(ostringstream& oss) const {
     870           0 :     for (unsigned int ibb = 0; ibb < dataStruct_.basebands_.size(); ibb++) {
     871           0 :       oss << "<" << HeaderParser::BASEBAND << " " << HeaderParser::NAME << "=" << QUOTE(CBasebandName::name(dataStruct_.basebands_.at(ibb).name())) << ">" << endl;
     872           0 :       spectralWindowsToXML(dataStruct_.basebands_, ibb, oss);
     873           0 :       oss << "</" << HeaderParser::BASEBAND << ">" << endl;
     874             :     }
     875           0 :   }
     876             : 
     877           0 :   void SDMDataObject::dataStructToXML(ostringstream& oss) {
     878           0 :     oss << "<" << HeaderParser::DATASTRUCT ;
     879             : 
     880             :     // The xsi:type attribute.
     881           0 :     oss << " xsi:type=" ;
     882           0 :     switch (correlationMode_) {
     883           0 :     case CROSS_ONLY:
     884           0 :       oss << QUOTE("CrossDataFullResolution");
     885           0 :       break;
     886           0 :     case AUTO_ONLY:
     887           0 :       oss << QUOTE("AutoDataFullResolution");
     888           0 :       break;
     889           0 :     case CROSS_AND_AUTO:
     890           0 :       oss << QUOTE("CrossAndAutoDataFullResolution");
     891           0 :       break;
     892             :     }
     893             :     
     894             :     // the apc attribute
     895           0 :     switch (correlationMode_) {
     896           0 :     case CROSS_ONLY:
     897             :     case CROSS_AND_AUTO:
     898           0 :       oss << " apc=" ;
     899           0 :       oss << QUOTE<AtmPhaseCorrection, CAtmPhaseCorrection>(dataStruct_.apc_);
     900           0 :       break;
     901           0 :     case AUTO_ONLY: 
     902           0 :       break;
     903             :     }
     904             :     
     905           0 :     oss << ">" << endl;
     906             :     
     907             :     // Before unrolling the basebands let's prepare the id_ and image_ private fields of the spectral windows.
     908           0 :     updateIdImageSPW();
     909             :     
     910             :     // Now unroll the basebands.    
     911           0 :     basebandsToXML(oss);
     912             :     
     913           0 :     if ( dataStruct_.flags_.size() )          toXML(dataStruct_.flags_, HeaderParser::FLAGS, oss);
     914           0 :     if ( dataStruct_.actualTimes_.size() )    toXML(dataStruct_.actualTimes_, HeaderParser::ACTUALTIMES, oss);
     915           0 :     if ( dataStruct_.actualDurations_.size() )toXML(dataStruct_.actualDurations_, HeaderParser::ACTUALDURATIONS, oss);
     916             :     
     917           0 :     switch (correlationMode_) {
     918           0 :     case CROSS_ONLY:
     919           0 :       toXML(dataStruct_.crossData_, HeaderParser::CROSSDATA, oss);
     920           0 :       break;
     921           0 :     case AUTO_ONLY:
     922           0 :       toXML(dataStruct_.autoData_, HeaderParser::AUTODATA, oss);
     923           0 :       break;
     924           0 :     case CROSS_AND_AUTO:
     925           0 :       toXML(dataStruct_.crossData_, HeaderParser::CROSSDATA, oss);
     926           0 :       toXML(dataStruct_.autoData_, HeaderParser::AUTODATA, oss);
     927           0 :       break;
     928           0 :     default:
     929           0 :       break;
     930             :     }
     931             :     
     932             :     /*
     933             :       if (spectralResolutionType_ == FULL_RESOLUTION ) {
     934             :       toXML(dataStruct_.zeroLags_, HeaderParser::ZEROLAGS, oss);
     935             :       }
     936             :     */
     937             :     // zeroLags are optional in any case - Michel Caillat - 24 Jul 2008
     938           0 :     if (dataStruct_.zeroLags().size() != 0) {
     939           0 :       toXML(dataStruct_.zeroLags_, HeaderParser::ZEROLAGS, oss);
     940             :     }
     941             :     
     942           0 :     oss << "</" << HeaderParser::DATASTRUCT << ">" << endl;
     943           0 :   }
     944             : 
     945           0 :   string SDMDataObject::toXML()  {
     946           0 :     TSTVALID();
     947           0 :     ostringstream result;
     948             :   
     949           0 :     result << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
     950             :   
     951             :     result << "<" << HeaderParser::SDMDATAHEADER 
     952           0 :            << " " << HeaderParser::BYTEORDER << "=\"" << byteOrder_->toString() << "\""
     953           0 :            << " " << HeaderParser::SCHEMAVERSION << "=\"" << schemaVersion_ << "\""
     954             :            << " xsi:noNamespaceSchemaLocation=\"binDataHeader9.xsd\"" 
     955             :            << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
     956             :            << " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"" 
     957             :            << " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
     958             :            << " xmlns:xhtml=\"http://www.w3.org/1999/xhtml\""
     959             :            << " xmlns:xvers=\"http://aramis.obspm.fr/~alma/xvers\""
     960           0 :            << " " << HeaderParser::PROJECTPATH << "=" << QUOTE(projectPath())
     961             :            << " " << "xvers:schemaVersion=\"0\""
     962             :            << " " << "xvers:revision=\"0.0.96\""
     963           0 :            << ">" << endl;
     964             :   
     965             :     // startTime...
     966           0 :     TOXML(HeaderParser::STARTTIME, startTime_, result);   
     967             :   
     968             :     // dataOID...
     969             :     result << "<" << HeaderParser::DATAOID
     970             :            << " xlink:type=\"locator\""
     971           0 :            << " xlink:" << HeaderParser::XLINKHREF  << "=" << QUOTE(dataOID_)
     972           0 :            << " xlink:" << HeaderParser::XLINKTITLE << "=" << QUOTE(title_)
     973           0 :            << "/>" << endl;
     974             :   
     975             :     // dimensionality or numTime ...
     976           0 :     if (dimensionality_ == 0) {
     977             :       result << "<" << HeaderParser::NUMTIME
     978           0 :              << ">"
     979           0 :              << numTime_
     980           0 :              << "</" << HeaderParser::NUMTIME << ">"
     981           0 :              << endl;
     982             :     }
     983             :     else { 
     984             :       result << "<" << HeaderParser::DIMENSIONALITY
     985             :              << " axes=\"TIM\""
     986           0 :              << ">"
     987           0 :              << dimensionality_
     988           0 :              << "</" << HeaderParser::DIMENSIONALITY << ">"
     989           0 :              << endl;
     990             :     }
     991             :   
     992             :     // execBlock...
     993           0 :     result << "<" << HeaderParser::EXECBLOCK << " " << HeaderParser::XLINKHREF << "=" << QUOTE(execBlockUID_) << "/>" << endl;
     994             :   
     995             :     // numAntenna
     996           0 :     TOXML(HeaderParser::NUMANTENNA, numAntenna_, result);
     997             :   
     998             :     //correlationMode
     999           0 :     TOXML<CorrelationMode, CCorrelationMode>(HeaderParser::CORRELATIONMODE,
    1000             :                                              correlationMode_,
    1001             :                                              result);
    1002             : 
    1003             :     // spectralResolutionType ... if present.
    1004           0 :     if (spectralResolutionType_.present())
    1005           0 :       TOXML<SpectralResolutionType, CSpectralResolutionType>(HeaderParser::SPECTRALRESOLUTION,
    1006             :                                                              spectralResolutionType_.literal(),
    1007             :                                                              result);
    1008             :   
    1009             :     // processorType
    1010           0 :     TOXML<ProcessorType, CProcessorType>(HeaderParser::PROCESSORTYPE,
    1011             :                                          processorType_,
    1012             :                                          result);
    1013             :   
    1014             :     // dataStruct
    1015           0 :     dataStructToXML(result);
    1016             :   
    1017           0 :     result << "</" << HeaderParser::SDMDATAHEADER << ">";
    1018             :   
    1019             :   
    1020           0 :     return result.str();
    1021           0 :   }
    1022             : 
    1023           0 :   void SDMDataObject::updateIdImageSPW() {
    1024           0 :     ostringstream oss;
    1025           0 :     for (unsigned int ibb = 0; ibb < dataStruct_.basebands_.size(); ibb++) {
    1026           0 :       vector<SDMDataObject::SpectralWindow>& spws = dataStruct_.basebands_.at(ibb).spectralWindows_;
    1027           0 :       for (unsigned int ispw = 0; ispw < spws.size(); ispw++) {
    1028           0 :         oss.str("");
    1029           0 :         oss << ispw+1;
    1030           0 :         spws.at(ispw).strSw(oss.str());
    1031           0 :         spws.at(ispw).strImage("");
    1032             :       }
    1033             :     }
    1034             :     
    1035             :     unsigned int ibbKey;
    1036             :     unsigned int ispwKey;
    1037             :     unsigned int ibbValue;
    1038             :     unsigned int ispwValue;
    1039             :     
    1040           0 :     string key, value;
    1041           0 :     map<string, string>::const_iterator iter;
    1042           0 :     istringstream iss;
    1043             : 
    1044             :     
    1045           0 :     for (iter = dataStruct_.imageSPW_.begin(); iter != dataStruct_.imageSPW_.end(); iter++) {
    1046           0 :       key   = iter->first;
    1047           0 :       iss.clear();
    1048           0 :       iss.str(key);
    1049           0 :       iss >> ibbKey;
    1050           0 :       iss >> ispwKey;
    1051             : 
    1052           0 :       value = iter->second;
    1053           0 :       iss.clear();
    1054           0 :       iss.str(value);
    1055           0 :       iss >> ibbValue;
    1056           0 :       iss >> ispwValue;      
    1057             : 
    1058           0 :       oss.str("");
    1059           0 :       oss << ispwKey;
    1060           0 :       dataStruct_.basebands_.at(ibbKey).spectralWindows_.at(ispwKey).strImage_  = dataStruct_.basebands_.at(ibbKey).spectralWindows_.at(ispwValue).strSw_;
    1061             :     }
    1062           0 :   }
    1063             : 
    1064             :   const ByteOrder* ByteOrder::Little_Endian = new ByteOrder("Little_Endian");
    1065             :   const ByteOrder* ByteOrder::Big_Endian = new ByteOrder("Big_Endian");
    1066             :   const ByteOrder* ByteOrder::Machine_Endianity = ByteOrder::machineEndianity();
    1067             : 
    1068           6 :   ByteOrder::ByteOrder(const string& name):
    1069           6 :     name_(name) {;}
    1070             : 
    1071           0 :   ByteOrder::~ByteOrder() {;}
    1072             : 
    1073           3 :   const ByteOrder* ByteOrder::machineEndianity() {
    1074             : #if defined(__APPLE__)
    1075             :     if (__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN)
    1076             : #else 
    1077             :     if (__BYTE_ORDER == __LITTLE_ENDIAN)
    1078             : #endif
    1079           3 :       return Little_Endian;
    1080             :     else
    1081             :       return Big_Endian;
    1082             :   }
    1083             :   
    1084           0 :   string ByteOrder::toString() const {
    1085           0 :     return name_;
    1086             :   }
    1087             : 
    1088             :   // SDMDataObject::
    1089             : 
    1090             :   // SDMDataSubset:: methods
    1091             :   //
    1092           0 :   SDMDataSubset::SDMDataSubset(SDMDataObject* owner) {
    1093           0 :     owner_             = owner ;
    1094           0 :     integrationNum_    = 0;
    1095           0 :     subintegrationNum_ = 0;
    1096           0 :     time_              = 0;
    1097           0 :     interval_          = 0;
    1098           0 :     actualTimes_       = 0;
    1099           0 :     nActualTimes_      = 0;
    1100           0 :     actualDurations_   = 0;
    1101           0 :     nActualDurations_  = 0;
    1102           0 :     zeroLags_          = 0;
    1103           0 :     nZeroLags_         = 0;
    1104           0 :     flags_             = 0;
    1105           0 :     nFlags_            = 0;
    1106           0 :     longCrossData_     = 0;
    1107           0 :     shortCrossData_    = 0;
    1108           0 :     floatCrossData_    = 0;
    1109           0 :     nCrossData_        = 0;
    1110           0 :     autoData_          = 0;
    1111           0 :     nAutoData_         = 0;
    1112           0 :     aborted_           = false;
    1113           0 :   }
    1114             : 
    1115             : 
    1116           0 :   SDMDataSubset::SDMDataSubset(SDMDataObject* owner,
    1117             :                                unsigned long long time,
    1118             :                                unsigned long long interval,
    1119           0 :                                const vector<float>& autoData):
    1120           0 :     owner_(owner),
    1121           0 :     time_(time),
    1122           0 :     interval_(interval) {
    1123           0 :     integrationNum_    = 0;
    1124           0 :     subintegrationNum_ = 0;
    1125           0 :     actualTimes_       = 0;
    1126           0 :     nActualTimes_      = 0;
    1127           0 :     actualDurations_   = 0;
    1128           0 :     nActualDurations_  = 0;
    1129           0 :     zeroLags_          = 0;
    1130           0 :     nZeroLags_         = 0;
    1131           0 :     flags_             = 0;
    1132           0 :     nFlags_            = 0;
    1133           0 :     longCrossData_     = 0;
    1134           0 :     shortCrossData_    = 0;
    1135           0 :     floatCrossData_    = 0;
    1136           0 :     nCrossData_        = 0;
    1137           0 :     if (autoData.size() != 0) {
    1138           0 :       autoData_ = &autoData.at(0);
    1139           0 :       nAutoData_ = autoData.size();
    1140             :     }
    1141             :     else {
    1142           0 :       autoData_ = 0;
    1143           0 :       nAutoData_ = 0;
    1144             :     }
    1145           0 :     aborted_ = false;
    1146           0 :   }
    1147             :   
    1148           0 :   SDMDataSubset::SDMDataSubset(const SDMDataSubset& sdmDataSubset) {
    1149           0 :     owner_             = sdmDataSubset.owner_ ;
    1150           0 :     integrationNum_    = sdmDataSubset.integrationNum_;
    1151           0 :     subintegrationNum_ = sdmDataSubset.subintegrationNum_;
    1152           0 :     ref_               = sdmDataSubset.ref_;
    1153           0 :     time_              = sdmDataSubset.time_;
    1154           0 :     interval_          = sdmDataSubset.interval_;
    1155           0 :     dataStruct_        = sdmDataSubset.dataStruct_;
    1156           0 :     flagsREF_          = sdmDataSubset.flagsREF_;
    1157           0 :     actualTimesREF_    = sdmDataSubset.actualTimesREF_;
    1158           0 :     actualDurationsREF_= sdmDataSubset.actualDurationsREF_;
    1159           0 :     zeroLagsREF_       = sdmDataSubset.zeroLagsREF_;
    1160           0 :     crossDataREF_      = sdmDataSubset.crossDataREF_;
    1161           0 :     crossDataType_     = sdmDataSubset.crossDataType_;
    1162           0 :     autoDataREF_       = sdmDataSubset.autoDataREF_;
    1163           0 :     actualTimes_       = sdmDataSubset.actualTimes_;
    1164           0 :     nActualTimes_      = sdmDataSubset.nActualTimes_;
    1165           0 :     actualDurations_   = sdmDataSubset.actualDurations_;
    1166           0 :     nActualDurations_  = sdmDataSubset.nActualDurations_;
    1167           0 :     zeroLags_          = sdmDataSubset.zeroLags_;
    1168           0 :     nZeroLags_         = sdmDataSubset.nZeroLags_;
    1169           0 :     flags_             = sdmDataSubset.flags_;
    1170           0 :     nFlags_            = sdmDataSubset.nFlags_;
    1171           0 :     longCrossData_     = sdmDataSubset.longCrossData_;
    1172           0 :     shortCrossData_    = sdmDataSubset.shortCrossData_;
    1173           0 :     floatCrossData_    = sdmDataSubset.floatCrossData_;
    1174           0 :     nCrossData_        = sdmDataSubset.nCrossData_;
    1175           0 :     autoData_          = sdmDataSubset.autoData_;
    1176           0 :     nAutoData_         = sdmDataSubset.nAutoData_;
    1177           0 :     aborted_           = sdmDataSubset.aborted_;
    1178           0 :     abortTime_         = sdmDataSubset.abortTime_;
    1179           0 :     abortReason_       = sdmDataSubset.abortReason_;
    1180           0 :   }
    1181             : 
    1182           0 :   SDMDataSubset& SDMDataSubset::operator=(const SDMDataSubset& sdmDataSubset) {
    1183           0 :     owner_             = sdmDataSubset.owner_ ;
    1184           0 :     integrationNum_    = sdmDataSubset.integrationNum_;
    1185           0 :     subintegrationNum_ = sdmDataSubset.subintegrationNum_;
    1186           0 :     ref_               = sdmDataSubset.ref_;
    1187           0 :     time_              = sdmDataSubset.time_;
    1188           0 :     interval_          = sdmDataSubset.interval_;
    1189           0 :     dataStruct_        = sdmDataSubset.dataStruct_;
    1190           0 :     flagsREF_          = sdmDataSubset.flagsREF_;
    1191           0 :     actualTimesREF_    = sdmDataSubset.actualTimesREF_;
    1192           0 :     actualDurationsREF_= sdmDataSubset.actualDurationsREF_;
    1193           0 :     zeroLagsREF_       = sdmDataSubset.zeroLagsREF_;
    1194           0 :     crossDataREF_      = sdmDataSubset.crossDataREF_;
    1195           0 :     crossDataType_     = sdmDataSubset.crossDataType_;
    1196           0 :     autoDataREF_       = sdmDataSubset.autoDataREF_;
    1197           0 :     actualTimes_       = sdmDataSubset.actualTimes_;
    1198           0 :     nActualTimes_      = sdmDataSubset.nActualTimes_;
    1199           0 :     actualDurations_   = sdmDataSubset.actualDurations_;
    1200           0 :     nActualDurations_  = sdmDataSubset.nActualDurations_;
    1201           0 :     zeroLags_          = sdmDataSubset.zeroLags_;
    1202           0 :     nZeroLags_         = sdmDataSubset.nZeroLags_;
    1203           0 :     flags_             = sdmDataSubset.flags_;
    1204           0 :     nFlags_            = sdmDataSubset.nFlags_;
    1205           0 :     longCrossData_     = sdmDataSubset.longCrossData_;
    1206           0 :     shortCrossData_    = sdmDataSubset.shortCrossData_;
    1207           0 :     floatCrossData_    = sdmDataSubset.floatCrossData_;
    1208           0 :     nCrossData_        = sdmDataSubset.nCrossData_;
    1209           0 :     autoData_          = sdmDataSubset.autoData_;
    1210           0 :     nAutoData_         = sdmDataSubset.nAutoData_;
    1211           0 :     aborted_           = sdmDataSubset.aborted_;
    1212           0 :     abortTime_         = sdmDataSubset.abortTime_;
    1213           0 :     abortReason_       = sdmDataSubset.abortReason_;
    1214           0 :     return *this;
    1215             :   }
    1216             : 
    1217           0 :   SDMDataSubset::~SDMDataSubset() {;}
    1218             : 
    1219           0 :   string SDMDataSubset::projectPath() const {
    1220           0 :     if (owner_ == 0) return "";
    1221             : 
    1222           0 :     ostringstream oss;
    1223           0 :     oss << owner_->execBlockNum_ << "/" << owner_->scanNum_ << "/" << owner_->subscanNum_ << "/"; 
    1224             : 
    1225           0 :     if (integrationNum_ > 0) oss << integrationNum_ << "/";
    1226           0 :     if (subintegrationNum_ > 0) oss << subintegrationNum_ << "/";
    1227             : 
    1228           0 :     return oss.str();
    1229           0 :   }
    1230             :   
    1231             : 
    1232           0 :   unsigned int SDMDataSubset::integrationNum() const { return integrationNum_; }
    1233             : 
    1234           0 :   unsigned int SDMDataSubset::subintegrationNum() const { return subintegrationNum_; }
    1235             : 
    1236           0 :   unsigned long long SDMDataSubset::time() const { return time_; }
    1237             :   
    1238           0 :   unsigned long long SDMDataSubset::interval() const { 
    1239             :     // if (owner_ && !owner_->isTP()) Utils::invalidCall("SDMDataSubset::interval", owner_);
    1240           0 :     return interval_; 
    1241             :   }
    1242             : 
    1243             :    
    1244           0 :   unsigned long int SDMDataSubset::actualDurations(const ACTUALDURATIONSTYPE* & ptr) const {ptr = actualDurations_; return nActualDurations_;}
    1245           0 :   uint64_t SDMDataSubset::actualDurationsPosition() const { return actualDurationsPosition_; }
    1246           0 :   unsigned long int SDMDataSubset::actualTimes(const ACTUALTIMESTYPE* & ptr) const { ptr = actualTimes_; return nActualTimes_;}
    1247           0 :   uint64_t SDMDataSubset::actualTimesPosition() const { return actualTimesPosition_; }
    1248           0 :   unsigned long int SDMDataSubset::autoData(const AUTODATATYPE* & ptr)const  { ptr = autoData_; return nAutoData_; }
    1249           0 :   uint64_t SDMDataSubset::autoDataPosition() const { return autoDataPosition_; }
    1250           0 :   unsigned long int SDMDataSubset::crossData(const SHORTCROSSDATATYPE* & ptr) const { 
    1251           0 :     if (owner_ && (owner_->isTP() || owner_->correlationMode() == AUTO_ONLY)) Utils::invalidCall("SDMDataSubset::crossData", owner_);
    1252           0 :     ptr = shortCrossData_; return nCrossData_; 
    1253             :   }
    1254           0 :   PrimitiveDataType SDMDataSubset::crossDataType() const { return crossDataType_; }
    1255           0 :   void SDMDataSubset::crossDataType(PrimitiveDataType value) { crossDataType_ = value;}
    1256             : 
    1257           0 :   unsigned long int SDMDataSubset::crossData(const INTCROSSDATATYPE* & ptr) const { 
    1258           0 :     if (owner_ && (owner_->isTP() || owner_->correlationMode() == AUTO_ONLY)) Utils::invalidCall("SDMDataSubset::crossData", owner_);
    1259           0 :     ptr = longCrossData_; return nCrossData_; 
    1260             :   }
    1261             : 
    1262             : 
    1263           0 :   unsigned long int SDMDataSubset::crossData(const FLOATCROSSDATATYPE* & ptr) const { 
    1264           0 :     if (owner_ && (owner_->isTP() || owner_->correlationMode() == AUTO_ONLY)) Utils::invalidCall("SDMDataSubset::crossData", owner_);
    1265           0 :     ptr = floatCrossData_; return nCrossData_; 
    1266             :   }
    1267             : 
    1268           0 :   uint64_t SDMDataSubset::crossDataPosition() const { return crossDataPosition_; }
    1269           0 :   unsigned long int SDMDataSubset::flags(const FLAGSTYPE* & ptr) const { ptr = flags_; return nFlags_; }
    1270           0 :   uint64_t SDMDataSubset::flagsPosition() const { return flagsPosition_; }
    1271             : 
    1272           0 :   unsigned long int SDMDataSubset::zeroLags(const ZEROLAGSTYPE* & ptr) const { 
    1273           0 :     if (owner_ && owner_->isTP()) Utils::invalidCall("SDMDataSubset::zeroLags", owner_);
    1274           0 :     ptr = zeroLags_; return nZeroLags_;
    1275             :   }
    1276           0 :   uint64_t SDMDataSubset::zeroLagsPosition() const { return zeroLagsPosition_; }
    1277             :   
    1278           0 :   bool SDMDataSubset::aborted() const {return aborted_; }
    1279           0 :   unsigned long long SDMDataSubset::abortTime() const {return abortTime_; }  
    1280           0 :   string SDMDataSubset::abortReason() const {return abortReason_;}
    1281             : 
    1282             : #define MIN_(a,b) ((a<b)?a:b)
    1283             : #define PRINT(_v_, _n_, _nmax_, _out_ ) for (unsigned int i = 0; i < MIN_(_n_, _nmax_); i++) _out_ << " " << _v_[i]; if (_n_ > _nmax_) _out_ << "...";
    1284             :  
    1285           0 :   string SDMDataSubset::toString(unsigned int N ) const {
    1286           0 :     ostringstream result;
    1287             :     //boost::gregorian::date d(2007, Jan, 1);
    1288             :     //ptime t1(date(2007, Jan, 1), time_duration(0, 0, 0,(time_ - FIRST_JAN_2007)/1000 ));
    1289             :     //result << "(owned by '" << owner_ << "')" << endl; 
    1290             :   
    1291           0 :     result << "projectPath = " << projectPath() << endl;
    1292             :     //result << "time = " << time_ << " (" << to_simple_string(t1)  << ")" << endl;
    1293           0 :     result << "time = " << time_ << endl;
    1294             :     //result << "dataStructureDesc = " << dataStructureDesc_ << endl;
    1295           0 :     result << "interval = " << interval_ <<endl;
    1296             :   
    1297             : 
    1298           0 :     if ( aborted_ ) {
    1299             :       // It"s an aborted [sub]integration.
    1300           0 :       result << "Aborted at = " << abortTime_ << endl;
    1301           0 :       result << "Reason = " << abortReason_ << endl;
    1302           0 :       return result.str();
    1303             :     }
    1304             : 
    1305             : 
    1306             :     // It's not an aborted [sub]integration.
    1307           0 :     switch (owner_->dimensionality_) {
    1308           0 :     case 0:
    1309           0 :       break;
    1310             :       
    1311           0 :     case 1:
    1312           0 :       switch (owner_->correlationMode_) {
    1313           0 :       case CROSS_ONLY:
    1314           0 :         result << "crossDataType = " << CPrimitiveDataType::name(crossDataType_) << endl;
    1315           0 :         break;
    1316           0 :       case AUTO_ONLY:
    1317           0 :         break;
    1318           0 :       case CROSS_AND_AUTO:
    1319           0 :         result << "crossDataType = " << CPrimitiveDataType::name(crossDataType_) << endl;
    1320           0 :         break;
    1321             :       }
    1322           0 :       break;
    1323           0 :     default:
    1324           0 :       break;
    1325             :     }
    1326             : 
    1327           0 :     result << "Binary attachments :" << endl;
    1328             :     
    1329           0 :     if (nActualTimes_) {
    1330           0 :       result << "ActualTimes (" << nActualTimes_ << " values ) = "; PRINT(actualTimes_, nActualTimes_, N, result); result << endl;
    1331             :     }
    1332             : 
    1333           0 :     if (nActualDurations_) {
    1334           0 :       result << "ActualDurations (" << nActualDurations_ << " values ) = "; PRINT(actualDurations_, nActualDurations_, N, result); result << endl;
    1335             :     }
    1336             : 
    1337           0 :     if (nFlags_) { 
    1338           0 :       result << "Flags (" << nFlags_ << " values ) = "; PRINT(flags_, nFlags_, N, result); result << endl;
    1339             :     }
    1340             :     
    1341           0 :     if (nCrossData_) { 
    1342           0 :       result << "CrossData (" << nCrossData_ << " values ) = "; 
    1343           0 :       switch (crossDataType_) {
    1344           0 :       case INT32_TYPE :
    1345           0 :         PRINT(longCrossData_, nCrossData_, N, result); result << endl;
    1346           0 :         break;
    1347           0 :       case INT16_TYPE :
    1348           0 :         PRINT(shortCrossData_, nCrossData_, N, result); result << endl;
    1349           0 :         break;
    1350           0 :       case FLOAT32_TYPE:
    1351           0 :         PRINT(floatCrossData_, nCrossData_, N, result); result << endl;
    1352           0 :         break;
    1353             : 
    1354           0 :       default: 
    1355           0 :         throw SDMDataObjectException("'" + CPrimitiveDataType::name(crossDataType_)+"' data are not processed here."); 
    1356             :   
    1357             :       }
    1358             :     }
    1359             : 
    1360           0 :     if (nAutoData_) {
    1361           0 :       result << "AutoData (" << nAutoData_ << " values ) = "; PRINT(autoData_, nAutoData_, N, result); result << endl;
    1362             :     }
    1363             :     
    1364           0 :     if (nZeroLags_) { 
    1365           0 :       result << "ZeroLags (" << nZeroLags_ << " values ) = = "; PRINT(zeroLags_, nZeroLags_, N, result); result << endl;
    1366             :     }
    1367             : 
    1368           0 :     return result.str();
    1369           0 :   }
    1370             : 
    1371             : 
    1372           0 :   void SDMDataSubset::binAttachToXML(const string& name, ostringstream& oss) {
    1373           0 :     oss << "<" << name << " xlink:href= \"" << projectPath() << "/" << name << ".bin\"";
    1374           0 :     if (name == "crossData") 
    1375           0 :       oss << " type=\"" <<  CPrimitiveDataType::name(crossDataType_) << "\"";
    1376           0 :     oss << "/>" << endl;
    1377           0 :   }
    1378             : 
    1379           0 :   void SDMDataSubset::tpBinAttachToXML(ostringstream& oss) {
    1380           0 :     if (nFlags_)
    1381           0 :       binAttachToXML(TPSubsetHeaderParser::FLAGSREF, oss);
    1382           0 :     if (nActualTimes_)
    1383           0 :       binAttachToXML(TPSubsetHeaderParser::ACTUALTIMESREF, oss);
    1384           0 :     if (nActualDurations_)
    1385           0 :       binAttachToXML(TPSubsetHeaderParser::ACTUALDURATIONSREF, oss);
    1386           0 :     binAttachToXML(TPSubsetHeaderParser::AUTODATAREF, oss);
    1387           0 :   }
    1388             : 
    1389           0 :   void SDMDataSubset::corrBinAttachToXML(ostringstream& oss) {    
    1390             :     // The binaryAttachments elements
    1391             : 
    1392           0 :     if (nFlags_)
    1393           0 :       binAttachToXML(CorrSubsetHeaderParser::FLAGSREF, oss);
    1394           0 :     if (nActualTimes_)
    1395           0 :       binAttachToXML(CorrSubsetHeaderParser::ACTUALTIMESREF, oss);
    1396           0 :     if (nActualDurations_)
    1397           0 :       binAttachToXML(CorrSubsetHeaderParser::ACTUALDURATIONSREF, oss);
    1398             : 
    1399           0 :     switch (owner_->correlationMode_) {
    1400           0 :     case CROSS_ONLY:
    1401             :       
    1402           0 :       binAttachToXML(CorrSubsetHeaderParser::CROSSDATAREF, oss);
    1403           0 :       break;
    1404             :       
    1405           0 :     case AUTO_ONLY:
    1406           0 :       binAttachToXML(CorrSubsetHeaderParser::AUTODATAREF, oss);          
    1407           0 :       break;
    1408             : 
    1409           0 :     case CROSS_AND_AUTO:
    1410           0 :       binAttachToXML(CorrSubsetHeaderParser::CROSSDATAREF, oss);            
    1411           0 :       binAttachToXML(CorrSubsetHeaderParser::AUTODATAREF, oss);          
    1412           0 :       break;
    1413             :     }
    1414             : 
    1415           0 :     if ((owner_->processorType_ == CORRELATOR) && (owner_->correlatorType() != FX))
    1416           0 :         binAttachToXML(CorrSubsetHeaderParser::ZEROLAGSREF, oss);            
    1417           0 :   }
    1418             :  
    1419             : 
    1420           0 :   string SDMDataSubset::xsiType() const {
    1421           0 :     string result;
    1422             :     
    1423           0 :     switch (owner_->correlationMode_) {
    1424           0 :     case CROSS_ONLY:     result = "BinaryCrossData" ; break;
    1425           0 :     case AUTO_ONLY:      result = "BinaryAutoData" ; break;
    1426           0 :     case CROSS_AND_AUTO: result = "BinaryCrossAndAutoData" ; break;
    1427             :     }
    1428             :         
    1429           0 :     return result;
    1430           0 :   }
    1431             : 
    1432             : 
    1433           0 :   string SDMDataSubset::toXML() {
    1434           0 :     ostringstream oss;
    1435             :     
    1436             :     //oss << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
    1437           0 :     if (owner_->processorType_ == CORRELATOR) {
    1438             :       oss << "<" << CorrSubsetHeaderParser::SDMDATASUBSETHEADER
    1439             :           << " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
    1440             :           << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
    1441           0 :           << " xsi:type=\"" << xsiType() << "\""
    1442           0 :           << " projectPath="<< QUOTE(projectPath())
    1443           0 :           << ">" << endl;
    1444             :       
    1445           0 :       OXML(CorrSubsetHeaderParser::SCHEDULEPERIODTIME, oss);
    1446           0 :       TOXML(CorrSubsetHeaderParser::TIME, time_, oss);
    1447           0 :       TOXML(CorrSubsetHeaderParser::INTERVAL, interval_, oss);
    1448           0 :       CXML(CorrSubsetHeaderParser::SCHEDULEPERIODTIME, oss);
    1449             :       
    1450           0 :       oss << "<" << CorrSubsetHeaderParser::DATASTRUCT << " ref =" << QUOTE("sdmDataHeader") << "/>" << endl;
    1451           0 :       corrBinAttachToXML(oss);
    1452           0 :       oss << "</" << CorrSubsetHeaderParser::SDMDATASUBSETHEADER << ">";
    1453           0 :       return oss.str();
    1454             :     }
    1455           0 :     else if (owner_->processorType_ == RADIOMETER) {
    1456             :       oss << "<" << TPSubsetHeaderParser::SDMDATASUBSETHEADER
    1457             :           << " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
    1458             :           << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
    1459           0 :           << " xsi:type=\"" << xsiType() << "\""
    1460           0 :           << " projectPath="<< QUOTE(projectPath())
    1461           0 :           << ">" << endl;
    1462             :     
    1463           0 :       OXML(TPSubsetHeaderParser::SCHEDULEPERIODTIME, oss);
    1464           0 :       TOXML(TPSubsetHeaderParser::TIME, time_, oss);
    1465           0 :       TOXML(TPSubsetHeaderParser::INTERVAL, interval_, oss);
    1466           0 :       CXML(TPSubsetHeaderParser::SCHEDULEPERIODTIME, oss);
    1467             :       
    1468           0 :       oss << "<" << TPSubsetHeaderParser::DATASTRUCT << " ref =" << QUOTE("sdmDataHeader") << "/>" << endl;
    1469           0 :       tpBinAttachToXML(oss);
    1470           0 :       oss << "</" << TPSubsetHeaderParser::SDMDATASUBSETHEADER << ">";
    1471           0 :       return oss.str();
    1472             :     }
    1473             :     else
    1474           0 :       throw SDMDataObjectException("no XML representation defined for an SDMDataSubset with a processor type defined as '"
    1475           0 :                                    + CProcessorType::name(owner_->processorType_));
    1476           0 :   }
    1477             :   
    1478             : 
    1479           0 :   const SDMDataObject* SDMDataSubset::owner() const { return owner_; }
    1480             :   // SDMDataSubset::
    1481             : 
    1482             : 
    1483             :   // Utils:: methods
    1484             :   //
    1485             : #define COUTCONTAINER(result, v) (copy(v.begin(), v.end(), ostream_iterator<string>(result, " ")))  
    1486           0 :   string Utils::quote(const string& s) {
    1487           0 :     return "\""+s+"\"";
    1488             :   }
    1489             : 
    1490             : 
    1491           0 :   void Utils::invalidCall(const string & methodName, const SDMDataObject* sdmDataObject) {
    1492           0 :     ostringstream oss;
    1493           0 :     oss << "Invalid call of method '" << methodName << "' in this context :";
    1494             :     
    1495           0 :     if (sdmDataObject->isTP()) 
    1496           0 :       oss << "total power data ('" << CCorrelationMode::name(sdmDataObject->correlationMode()) << "')" << endl;
    1497           0 :     else if (sdmDataObject->isCorrelation()) {
    1498           0 :       oss << "correlator data ('" << CCorrelationMode::name(sdmDataObject->correlationMode()) << "')" << endl; 
    1499             :     }
    1500           0 :     throw SDMDataObjectException(oss.str());
    1501           0 :   }
    1502             : 
    1503           0 :   string Utils::quote(bool b) {
    1504           0 :     ostringstream oss;
    1505           0 :     oss << "\"" << (b?"true":"false") << "\"";
    1506           0 :     return oss.str();
    1507           0 :   }
    1508             : 
    1509           0 :   string Utils::quote(int i) {
    1510           0 :     ostringstream oss;
    1511           0 :     oss << "\"" << i << "\"";
    1512           0 :     return oss.str();
    1513           0 :   }
    1514             : 
    1515           0 :   string Utils::quote(unsigned int ui) {
    1516           0 :     ostringstream oss;
    1517           0 :     oss << "\"" << ui << "\"";
    1518           0 :     return oss.str();
    1519           0 :   }
    1520             : 
    1521             : 
    1522           0 :   string Utils::quote(long long l) {
    1523           0 :     ostringstream oss;
    1524           0 :     oss << "\"" << l << "\"";
    1525           0 :     return oss.str();
    1526           0 :   }
    1527             : 
    1528           0 :   string Utils::quote(float f) {
    1529           0 :     ostringstream oss;
    1530           0 :     oss << "\"" << f << "\"";
    1531           0 :     return oss.str();
    1532           0 :   }
    1533             : 
    1534           0 :   string Utils::quote(const set<string>& s) {
    1535           0 :     ostringstream oss;
    1536           0 :     oss << "\"";
    1537           0 :     COUTCONTAINER(oss, s);
    1538           0 :     oss << "\"";
    1539           0 :     return oss.str();
    1540           0 :   }
    1541             : 
    1542             : 
    1543           0 :   string Utils::quote(const vector<string>& s) {
    1544           0 :     ostringstream oss;
    1545           0 :     oss << "\"";
    1546           0 :     COUTCONTAINER(oss, s);
    1547           0 :     oss << "\"";
    1548           0 :     return oss.str();
    1549           0 :   }
    1550             : 
    1551             : 
    1552           0 :   void  Utils::toXML(const string& elementName, int value, ostringstream& oss){
    1553           0 :     oss << "<" << elementName << ">" << value << "</" << elementName << ">" << endl;
    1554           0 :   }
    1555             : 
    1556           0 :   void  Utils::toXML(const string& elementName, unsigned int value, ostringstream& oss){
    1557           0 :     oss << "<" << elementName << ">" << value << "</" << elementName << ">" << endl;
    1558           0 :   }
    1559             : 
    1560           0 :   void  Utils::toXML(const string& elementName, long long value, ostringstream& oss){
    1561           0 :     oss << "<" << elementName << ">" << value << "</" << elementName << ">" << endl;
    1562           0 :   }
    1563             : 
    1564           0 :   void  Utils::toXML(const string& elementName, unsigned long long value, ostringstream& oss){
    1565           0 :     oss << "<" << elementName << ">" << value << "</" << elementName << ">" << endl;
    1566           0 :   }
    1567             : 
    1568           0 :   void Utils::oXML(const string& elementName, ostringstream& oss) {
    1569           0 :     oss << "<" << elementName << ">" << endl;
    1570           0 :   }
    1571             : 
    1572           0 :   void Utils::cXML(const string& elementName, ostringstream& oss) {
    1573           0 :     oss << "</" << elementName << ">" << endl;
    1574           0 :   }
    1575             : 
    1576             :   // Utils::
    1577             : 
    1578             : 
    1579             : } // asdmbinaries

Generated by: LCOV version 1.16