LCOV - code coverage report
Current view: top level - alma/ASDMBinaries - SDMDataObject.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 467 891 52.4 %
Date: 2023-10-25 08:47:59 Functions: 117 176 66.5 %

          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           1 :   bool SDMDataObject::init() {
      38           1 :     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        8724 :   SDMDataObject::SpectralWindow::SpectralWindow():
      51             :     scaleFactor_(0.0),
      52             :     numSpectralPoint_(0),
      53        8724 :     numBin_(0)
      54        8724 :   {owner_ = 0; strSw_ = ""; strImage_ = "";}
      55             :   
      56     4558715 :   SDMDataObject::SpectralWindow::~SpectralWindow() {;}
      57             :   
      58          74 :   SDMDataObject::SpectralWindow::SpectralWindow(const vector<StokesParameter>& crossPolProducts,
      59             :                                                 float scaleFactor, unsigned int numSpectralPoint,
      60             :                                                 unsigned int numBin,
      61          74 :                                                 NetSidebandMod::NetSideband sideband):
      62             :     crossPolProducts_(crossPolProducts),
      63             :     scaleFactor_(scaleFactor),
      64             :     numSpectralPoint_(numSpectralPoint),
      65             :     numBin_(numBin),
      66          74 :     sideband_(sideband)
      67          74 :   {owner_ = 0;  strSw_ = ""; strImage_ = "";}
      68             :   
      69        5917 :   SDMDataObject::SpectralWindow::SpectralWindow::SpectralWindow(const vector<StokesParameter>& sdPolProducts,
      70             :                                                                 unsigned int numSpectralPoint,
      71             :                                                                 unsigned numBin,
      72        5917 :                                                                 NetSidebandMod::NetSideband sideband):
      73             :     sdPolProducts_(sdPolProducts),
      74             :     numSpectralPoint_(numSpectralPoint),
      75             :     numBin_(numBin),
      76        5917 :     sideband_(sideband)
      77        5917 :   {owner_ = 0; strSw_ = ""; strImage_ = "";}
      78             :   
      79        3269 :   SDMDataObject::SpectralWindow::SpectralWindow(const vector<StokesParameter>& crossPolProducts,
      80             :                                                 const vector<StokesParameter>& sdPolProducts,
      81             :                                                 float scaleFactor,
      82             :                                                 unsigned int numSpectralPoint,
      83             :                                                 unsigned int numBin,
      84        3269 :                                                 NetSidebandMod::NetSideband sideband):
      85             :     crossPolProducts_(crossPolProducts),
      86             :     sdPolProducts_(sdPolProducts),
      87             :     scaleFactor_(scaleFactor),
      88             :     numSpectralPoint_(numSpectralPoint),
      89             :     numBin_(numBin),
      90        3269 :     sideband_(sideband)
      91        3269 :   {owner_ = 0; strSw_ = ""; strImage_ = "";}
      92             :   
      93     3946502 :   const vector<StokesParameter>& SDMDataObject::SpectralWindow::crossPolProducts() const { 
      94     3946502 :     if (owner_ && (owner_->isTP() || owner_->correlationMode() == AUTO_ONLY)) Utils::invalidCall("SDMDataObject::SpectralWindow::crossPolProducts", owner_);
      95     3946502 :     return crossPolProducts_; 
      96             :   }
      97             : 
      98             :   //  void SDMDataObject::SpectralWindow::crossPolProducts(const vector<StokesParameter>& value) { crossPolProducts_ = value; }
      99             : 
     100      550595 :   const vector<StokesParameter>& SDMDataObject::SpectralWindow::sdPolProducts() const { 
     101      550595 :     if (owner_ && (owner_->correlationMode() == CROSS_ONLY)) Utils::invalidCall("SDMDataObject::SpectralWindow::sdPolProducts", owner_);
     102      550595 :     return sdPolProducts_; 
     103             :   }
     104             : 
     105             :   //  void SDMDataObject::SpectralWindow::sdPolProducts(const vector<StokesParameter>& value) { sdPolProducts_ = value; }
     106             : 
     107        2990 :   float SDMDataObject::SpectralWindow::scaleFactor() const { 
     108        2990 :     if (owner_ && owner_->correlationMode() == AUTO_ONLY) Utils::invalidCall("SDMDataObject::SpectralWindow::scaleFactor", owner_);    
     109        2990 :     return scaleFactor_; 
     110             :   }
     111             :   //  void SDMDataObject::SpectralWindow::scaleFactor(float value )  { scaleFactor_ = value; }
     112             :   
     113   127387849 :   unsigned int SDMDataObject::SpectralWindow::numSpectralPoint() const { return numSpectralPoint_; }
     114             :   //  void SDMDataObject::SpectralWindow::numSpectralPoint(unsigned int value)  { numSpectralPoint_ = value; }
     115             : 
     116        2732 :   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        2732 :   NetSidebandMod::NetSideband SDMDataObject::SpectralWindow::sideband() const { return sideband_; }
     122             : 
     123         536 :   void SDMDataObject::SpectralWindow::strImage(const string& s) {
     124             : #ifndef WITHOUT_BOOST
     125             :     boost::cmatch what;
     126             : #else
     127        1072 :     std::cmatch what;
     128             : #endif
     129         536 :     if ((s.size() == 0) || regex_match(s.c_str(), what, SDMDataObject::SPWID)) {
     130         536 :       strImage_ = s;
     131             :     }
     132             :     else
     133           0 :       throw SDMDataObjectException("SpectralWindow::strImage : '" + s + "' is an invalid string to identify a spectral window.");
     134         536 :   }
     135             : 
     136        9260 :   const string& SDMDataObject::SpectralWindow::strImage() const { return strImage_; }
     137             : 
     138        9260 :   void SDMDataObject::SpectralWindow::strSw(const string& s) {
     139             : #ifndef WITHOUT_BOOST
     140             :     boost::cmatch what;
     141             : #else
     142       18520 :     std::cmatch what;
     143             : #endif
     144        9260 :     if ((s.size() == 0) || regex_match(s.c_str(), what, SDMDataObject::SPWID)) {
     145        9260 :       strSw_ = s;
     146             :     }
     147             :     else
     148           0 :       throw SDMDataObjectException("SpectralWindow::strSw :  '" + s + "' is an invalid string to identify a spectral window.");
     149        9260 :   }
     150             : 
     151        8724 :   const string& SDMDataObject::SpectralWindow::strSw() const { return strSw_; }
     152             : 
     153             :   // SDMDataObject::SpectralWindow::
     154             : 
     155             : 
     156             :   // SDMDataObject::Baseband methods
     157             :   //
     158        8455 :   SDMDataObject::Baseband::Baseband() {owner_ = 0;}
     159             :   
     160         536 :   SDMDataObject::Baseband::Baseband(BasebandName name,
     161         536 :                                     const vector<SpectralWindow>& spectralWindows):
     162             :     name_(name),
     163         536 :     spectralWindows_(spectralWindows) {owner_ = 0;}
     164             : 
     165             : 
     166     2283881 :   SDMDataObject::Baseband::~Baseband() {;}
     167             :   
     168        1072 :   BasebandName SDMDataObject::Baseband::name() const { 
     169        1072 :     return name_; 
     170             :   }
     171             : 
     172             :   //  void SDMDataObject::Baseband::ref(BasebandName value) { ref_ = value; }
     173             :   
     174     2253707 :   const vector<SDMDataObject::SpectralWindow>& SDMDataObject::Baseband::spectralWindows() const { return spectralWindows_; }
     175        8455 :   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       33788 :   SDMDataObject::BinaryPart::BinaryPart() {owner_ = 0; size_ = 0;}
     182       51031 :   SDMDataObject::BinaryPart::~BinaryPart() {;}
     183             :   
     184             :   
     185       14027 :   SDMDataObject::BinaryPart::BinaryPart( unsigned int size,
     186       14027 :                                          const vector<AxisName>& axes):
     187             :     size_(size),
     188       14027 :     axes_(axes){owner_ = 0;}
     189             :   
     190             :   
     191       40332 :   unsigned int SDMDataObject::BinaryPart::size() const { return size_; }
     192             :   //  void SDMDataObject::BinaryPart::size (unsigned int value) { size_ = value; }
     193             :   
     194        6032 :   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        5399 :   SDMDataObject::AutoDataBinaryPart::AutoDataBinaryPart(): BinaryPart() { normalized_ = false; }
     202        9278 :   SDMDataObject::AutoDataBinaryPart::~AutoDataBinaryPart() {;}
     203             : 
     204        3343 :   SDMDataObject::AutoDataBinaryPart::AutoDataBinaryPart(unsigned int size,
     205             :                                                         const vector<AxisName>& axes,
     206        3343 :                                                         bool normalized) : BinaryPart(size, axes) {
     207        3343 :     normalized_ = normalized;
     208        3343 :   }
     209             : 
     210          24 :   bool SDMDataObject::AutoDataBinaryPart::normalized() const { return normalized_; }
     211             : 
     212             :   // SDMDataObject::AutoDataBinaryPart::
     213             : 
     214             :   // SDMDataObject::ZeroLagsBinaryPart:: methods
     215        6096 :   SDMDataObject::ZeroLagsBinaryPart::ZeroLagsBinaryPart(): BinaryPart() { correlatorType_ = XF; }
     216        7794 :   SDMDataObject::ZeroLagsBinaryPart::~ZeroLagsBinaryPart() {;}
     217             : 
     218        1162 :   SDMDataObject::ZeroLagsBinaryPart::ZeroLagsBinaryPart(unsigned int size,
     219             :                                                         const vector<AxisName>& axes,
     220        1162 :                                                         CorrelatorType correlatorType) : BinaryPart(size, axes) {
     221        1162 :     correlatorType_ = correlatorType;
     222        1162 :   }
     223             : 
     224         160 :   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        5399 :   SDMDataObject::DataStruct::DataStruct() {owner_ = 0;}
     237             : 
     238             :   /**
     239             :    * The destructor.
     240             :    */
     241        5935 :   SDMDataObject::DataStruct::~DataStruct() {;}
     242             : 
     243             : 
     244             :   /** 
     245             :    * The full constructor.
     246             :    */
     247         536 :   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         536 :                                         ):apc_(apc),
     256             :                                           basebands_(basebands),
     257             :                                           flags_(flags),
     258             :                                           actualTimes_(actualTimes),
     259             :                                           actualDurations_(actualDurations),
     260             :                                           zeroLags_(zeroLags),
     261             :                                           crossData_(crossData),
     262         536 :                                           autoData_(autoData)
     263             :   {
     264         536 :     owner_ = 0;
     265         536 :   }      
     266         697 :   const vector<AtmPhaseCorrection>& SDMDataObject::DataStruct::apc() const { return apc_; }
     267             :   //  void SDMDataObject::DataStruct::apc(const vector<AtmPhaseCorrection>& value) { apc_ = value; }
     268             :   
     269       12474 :   const vector<SDMDataObject::Baseband>& SDMDataObject::DataStruct::basebands() const { return basebands_; }
     270             :   //  void SDMDataObject::DataStruct::basebands(const vector<SDMDataObject::Baseband>& value) { basebands_ = value; }
     271             :   
     272        4639 :   const SDMDataObject::BinaryPart& SDMDataObject::DataStruct::flags() const { return flags_;}
     273             :   //  void SDMDataObject::DataStruct::flags(const SDMDataObject::BinaryPart& value) { flags_ = value; }
     274             :   
     275        3212 :   const SDMDataObject::BinaryPart& SDMDataObject::DataStruct::actualTimes() const { return actualTimes_;}
     276             :   //  void SDMDataObject::DataStruct::actualTimes(const SDMDataObject::BinaryPart& value) { actualTimes_ = value; }
     277             :  
     278        3212 :   const SDMDataObject::BinaryPart& SDMDataObject::DataStruct::actualDurations() const { return actualDurations_;}
     279             :   //  void SDMDataObject::DataStruct::actualDurations(const SDMDataObject::BinaryPart& value) { actualDurations_ = value; }
     280             :   
     281        4109 :   const SDMDataObject::ZeroLagsBinaryPart& SDMDataObject::DataStruct::zeroLags() const { 
     282        4109 :     if (owner_ && owner_->isTP()) Utils::invalidCall("SDMDataObject::DataStruct::zeroLags", owner_);
     283        4109 :     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        3212 :   const SDMDataObject::BinaryPart& SDMDataObject::DataStruct::crossData() const { return crossData_;}
     292             :   //  void SDMDataObject::DataStruct::crossData(const SDMDataObject::BinaryPart& value) { crossData_ = value; }
     293             :   
     294        3578 :   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             :   }
     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             :   }
     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             :   }
     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        2518 :   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             :     startTime_(startTime),
     449             :     dataOID_(dataOID),
     450             :     dimensionality_(dimensionality),
     451             :     numTime_(0),
     452             :     execBlockUID_(execBlockUID),
     453             :     execBlockNum_(execBlockNum),
     454             :     scanNum_(scanNum),
     455             :     subscanNum_(subscanNum),
     456             :     numAntenna_(numAntenna),
     457             :     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             :     startTime_(startTime),
     475             :     dataOID_(dataOID),
     476             :     dimensionality_(dimensionality),
     477             :     numTime_(numTime),
     478             :     execBlockUID_(execBlockUID),
     479             :     execBlockNum_(execBlockNum),
     480             :     scanNum_(scanNum),
     481             :     subscanNum_(subscanNum),
     482             :     numAntenna_(numAntenna),
     483           0 :     dataStruct_(dataStruct)
     484           0 :   { valid_ = true; aborted_ = false;}
     485             :   
     486           0 :   string SDMDataObject::title() const { TSTVALID(); return title_; }
     487        2881 :   void SDMDataObject::title(const string& value) { title_ = value; }
     488             : 
     489          29 :   const ByteOrder* SDMDataObject::byteOrder() const { TSTVALID(); return byteOrder_; }
     490             : 
     491           0 :   unsigned long long SDMDataObject::startTime() const {TSTVALID(); return startTime_; }
     492        2881 :   void SDMDataObject::startTime(unsigned long long value) { startTime_ = value; }
     493             :   
     494        5690 :   unsigned int SDMDataObject::numTime() const  {TSTVALID(); return numTime_; }
     495         861 :   void SDMDataObject::numTime(unsigned int value) { numTime_ = value; }
     496             :   
     497           0 :   string SDMDataObject::dataOID() const {TSTVALID(); return dataOID_; }
     498        2881 :   void SDMDataObject::dataOID(const string& value) { dataOID_ = value; }
     499             :   
     500        3358 :   unsigned int SDMDataObject::dimensionality() const  {TSTVALID(); return dimensionality_; }
     501        2881 :   void SDMDataObject::dimensionality( unsigned int value ) { dimensionality_ = value; }
     502             : 
     503           0 :   string SDMDataObject::execBlockUID() const {TSTVALID(); return execBlockUID_; }
     504        2881 :   void SDMDataObject::execBlockUID (const string& value) { execBlockUID_ = value; }
     505             :   
     506       40914 :   unsigned int SDMDataObject::execBlockNum() const  {TSTVALID(); return execBlockNum_; }
     507           0 :   void SDMDataObject::execBlockNum (unsigned int value ) { execBlockNum_ = value; }
     508             :   
     509       40914 :   unsigned int SDMDataObject::scanNum() const  {TSTVALID(); return scanNum_ ; }
     510           0 :   void SDMDataObject::scanNum( unsigned int value) { scanNum_ = value; }
     511             :   
     512       40914 :   unsigned int SDMDataObject::subscanNum() const {TSTVALID(); return subscanNum_; }
     513           0 :   void SDMDataObject::subscanNum(int value) { subscanNum_ = value; }
     514             :   
     515        1438 :   string SDMDataObject::projectPath() const {
     516        1438 :     TSTVALID();
     517        2876 :     ostringstream oss;
     518        1438 :     oss << execBlockNum_ << "/" << scanNum_ << "/" << subscanNum_ << "/";
     519        2876 :     return oss.str();
     520             :   }
     521             : 
     522        1760 :   unsigned int SDMDataObject::numAntenna() const  {TSTVALID();  return numAntenna_; }
     523        2881 :   void SDMDataObject::numAntenna (unsigned int value) { numAntenna_ = value; }
     524             :   
     525       28032 :   const SDMDataObject::DataStruct& SDMDataObject::dataStruct() const {TSTVALID(); return dataStruct_; }
     526           0 :   void SDMDataObject::dataStruct(const SDMDataObject::DataStruct& value) {dataStruct_ = value; }
     527             : 
     528     4613260 :   CorrelationMode SDMDataObject::correlationMode() const  {TSTVALID(); return correlationMode_; }
     529             : 
     530           0 :   OptionalSpectralResolutionType SDMDataObject::spectralResolutionType() const {TSTVALID(); return spectralResolutionType_; }
     531       43396 :   ProcessorType SDMDataObject::processorType() const {TSTVALID(); return processorType_; }
     532       30311 :   CorrelatorType SDMDataObject::correlatorType() const {
     533       30311 :     TSTVALID(); 
     534       30311 :     if (processorType_ == CORRELATOR) 
     535       30311 :       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     3976132 :   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     3976132 :     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     3976132 :   bool SDMDataObject::isTP() const {TSTVALID(); return inTitle("Total Power");}
     555           0 :   bool SDMDataObject::isWVR() const {TSTVALID(); return inTitle("WVR");}
     556       41636 :   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        2497 :   bool SDMDataObject::hasPackedData() const {TSTVALID(); return dimensionality() == 0;}
     564             :   
     565         356 :   const vector<SDMDataSubset>& SDMDataObject::sdmDataSubsets() const {
     566         356 :     TSTVALID();
     567         356 :     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         356 :   const SDMDataSubset& SDMDataObject::tpDataSubset() const {
     609         356 :     TSTVALID();
     610         356 :     if (isCorrelation()) Utils::invalidCall("tpDataSubset", this);
     611         356 :     return dataSubsets_.at(0);
     612             :     //return str2index_.begin()->second;
     613             :   }
     614             : 
     615         366 :   void SDMDataObject::tpDataSubset(const SDMDataSubset& value) {
     616         366 :     if (isCorrelation()) Utils::invalidCall("tpDataSubset", this);
     617         366 :     dataSubsets_.push_back(value);
     618             : 
     619         366 :     string projectPath = value.projectPath();
     620         366 :     if (SDMDataObjectParser::trim(projectPath).size() == 0)
     621           0 :       throw (SDMDataObjectException("can't accept a data subset without a project path"));
     622             : 
     623         366 :     str2index_[projectPath] = dataSubsets_.size() - 1;
     624         366 :   }
     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             :   }
     636             :  
     637         445 :   void SDMDataObject::done() {
     638         445 :     valid_ = false;
     639             :     
     640         445 :     str2index_.clear();
     641         445 :     dataSubsets_.clear();
     642         445 :   }
     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        2881 :   void SDMDataObject::owns() {
     652             :     // I own my correlationMode
     653        2881 :     dataStruct_.owner_ = this;
     654             : 
     655             :     // I own my basebands and their spectral windows
     656       11336 :     for (unsigned int i = 0; i < dataStruct_.basebands_.size(); i++) {
     657        8455 :       Baseband& bb = dataStruct_.basebands_.at(i);
     658        8455 :       bb.owner_ = this;
     659             :       
     660       17179 :       for (unsigned int j = 0 ; j < bb.spectralWindows_.size(); j++) {
     661        8724 :         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        2881 :     dataStruct_.flags_.owner_   = this;
     668        2881 :     dataStruct_.actualTimes_.owner_     = this;
     669        2881 :     dataStruct_.actualDurations_.owner_ = this;
     670        2881 :     dataStruct_.zeroLags_.owner_        = this;
     671        2881 :     dataStruct_.crossData_.owner_       = this;
     672        2881 :     dataStruct_.autoData_.owner_        = this;
     673             : 
     674             :     // I own my dataSubsets
     675        3247 :     for (unsigned int i = 0; i < dataSubsets_.size(); i++)
     676         366 :       dataSubsets_.at(i).owner_ = this;
     677        2881 :   }
     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             :       }
     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             :   }
     802             : 
     803             : 
     804        1072 :   void SDMDataObject::toXML(const BinaryPart& binaryPart, const string& elementName, ostringstream& oss) const {
     805        1072 :     oss << "<" << elementName ;
     806        1072 :     oss << " " << HeaderParser::SIZE << "=" << QUOTE(binaryPart.size())
     807        2144 :         << " " << HeaderParser::AXES << "=" << QUOTE<AxisName, CAxisName>(binaryPart.axes())
     808        3216 :         << "/>"
     809        1072 :         << endl;
     810        1072 :   }
     811             : 
     812          24 :   void SDMDataObject::toXML(const AutoDataBinaryPart& autoDataBinaryPart, const string& elementName, ostringstream& oss) const {
     813          24 :     oss << "<" << elementName ;
     814          24 :     oss << " " << HeaderParser::SIZE << "=" << QUOTE(autoDataBinaryPart.size())
     815          48 :         << " " << HeaderParser::AXES << "=" << QUOTE<AxisName, CAxisName>(autoDataBinaryPart.axes())
     816          48 :         << " " << HeaderParser::NORMALIZED << "=" << QUOTE(autoDataBinaryPart.normalized())
     817          96 :         << "/>"
     818          24 :         << endl;
     819          24 :   }
     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         536 :   void SDMDataObject::spectralWindowsToXML(const vector<Baseband>& basebands,unsigned int ibb,  ostringstream& oss) const {
     831         536 :     const vector<SDMDataObject::SpectralWindow>& spectralWindows = basebands.at(ibb).spectralWindows();
     832        1072 :     for (unsigned int i = 0; i < spectralWindows.size(); i++) {
     833         536 :       const SpectralWindow& spectralWindow = spectralWindows.at(i);
     834         536 :       oss << "<" << HeaderParser::SPECTRALWINDOW;
     835         536 :       oss << " " << HeaderParser::SW << "=" << QUOTE(i+1);
     836         536 :       oss << " " << HeaderParser::SWBB << "=" << QUOTE(CBasebandName::name(basebands.at(ibb).name()));
     837             :       
     838         536 :       switch (correlationMode_) {
     839         512 :       case CROSS_ONLY:
     840         512 :         oss << " " << HeaderParser::CROSSPOLPRODUCTS << "=" << QUOTE<StokesParameter, CStokesParameter>(spectralWindow.crossPolProducts()) ;
     841         512 :         oss << " " << HeaderParser::SCALEFACTOR << "=" << QUOTE(spectralWindow.scaleFactor()) ;
     842         512 :         oss << " " << HeaderParser::NUMSPECTRALPOINT << "=" << QUOTE(spectralWindow.numSpectralPoint()) ;
     843         512 :         oss << " " << HeaderParser::NUMBIN << "=" << QUOTE(spectralWindow.numBin()) ;
     844         512 :         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          24 :       case CROSS_AND_AUTO:
     853          24 :         oss << " " << HeaderParser::CROSSPOLPRODUCTS << "=" << QUOTE<StokesParameter, CStokesParameter>(spectralWindow.crossPolProducts()) ;
     854          24 :         oss << " " << HeaderParser::SDPOLPRODUCTS << "=" << QUOTE<StokesParameter, CStokesParameter>(spectralWindow.sdPolProducts()) ;
     855          24 :         oss << " " << HeaderParser::SCALEFACTOR << "=" << QUOTE(spectralWindow.scaleFactor()) ;
     856          24 :         oss << " " << HeaderParser::NUMSPECTRALPOINT << "=" << QUOTE(spectralWindow.numSpectralPoint()) ;
     857          24 :         oss << " " << HeaderParser::NUMBIN << "=" << QUOTE(spectralWindow.numBin()) ;
     858          24 :         break;
     859             :       }
     860             : 
     861         536 :       oss << " " << HeaderParser::SIDEBAND << "=" << QUOTE<NetSideband, CNetSideband>(spectralWindow.sideband());
     862             : 
     863         536 :       if (spectralWindow.strImage().size() > 0) oss << " " << HeaderParser::IMAGE << "=" << QUOTE(::atoi(spectralWindow.strImage().c_str()));
     864             :       
     865         536 :       oss << "/>" << endl;
     866             :     }
     867         536 :   }
     868             : 
     869         536 :   void SDMDataObject::basebandsToXML(ostringstream& oss) const {
     870        1072 :     for (unsigned int ibb = 0; ibb < dataStruct_.basebands_.size(); ibb++) {
     871         536 :       oss << "<" << HeaderParser::BASEBAND << " " << HeaderParser::NAME << "=" << QUOTE(CBasebandName::name(dataStruct_.basebands_.at(ibb).name())) << ">" << endl;
     872         536 :       spectralWindowsToXML(dataStruct_.basebands_, ibb, oss);
     873         536 :       oss << "</" << HeaderParser::BASEBAND << ">" << endl;
     874             :     }
     875         536 :   }
     876             : 
     877         536 :   void SDMDataObject::dataStructToXML(ostringstream& oss) {
     878         536 :     oss << "<" << HeaderParser::DATASTRUCT ;
     879             : 
     880             :     // The xsi:type attribute.
     881         536 :     oss << " xsi:type=" ;
     882         536 :     switch (correlationMode_) {
     883         512 :     case CROSS_ONLY:
     884         512 :       oss << QUOTE("CrossDataFullResolution");
     885         512 :       break;
     886           0 :     case AUTO_ONLY:
     887           0 :       oss << QUOTE("AutoDataFullResolution");
     888           0 :       break;
     889          24 :     case CROSS_AND_AUTO:
     890          24 :       oss << QUOTE("CrossAndAutoDataFullResolution");
     891          24 :       break;
     892             :     }
     893             :     
     894             :     // the apc attribute
     895         536 :     switch (correlationMode_) {
     896         536 :     case CROSS_ONLY:
     897             :     case CROSS_AND_AUTO:
     898         536 :       oss << " apc=" ;
     899         536 :       oss << QUOTE<AtmPhaseCorrection, CAtmPhaseCorrection>(dataStruct_.apc_);
     900         536 :       break;
     901           0 :     case AUTO_ONLY: 
     902           0 :       break;
     903             :     }
     904             :     
     905         536 :     oss << ">" << endl;
     906             :     
     907             :     // Before unrolling the basebands let's prepare the id_ and image_ private fields of the spectral windows.
     908         536 :     updateIdImageSPW();
     909             :     
     910             :     // Now unroll the basebands.    
     911         536 :     basebandsToXML(oss);
     912             :     
     913         536 :     if ( dataStruct_.flags_.size() )          toXML(dataStruct_.flags_, HeaderParser::FLAGS, oss);
     914         536 :     if ( dataStruct_.actualTimes_.size() )    toXML(dataStruct_.actualTimes_, HeaderParser::ACTUALTIMES, oss);
     915         536 :     if ( dataStruct_.actualDurations_.size() )toXML(dataStruct_.actualDurations_, HeaderParser::ACTUALDURATIONS, oss);
     916             :     
     917         536 :     switch (correlationMode_) {
     918         512 :     case CROSS_ONLY:
     919         512 :       toXML(dataStruct_.crossData_, HeaderParser::CROSSDATA, oss);
     920         512 :       break;
     921           0 :     case AUTO_ONLY:
     922           0 :       toXML(dataStruct_.autoData_, HeaderParser::AUTODATA, oss);
     923           0 :       break;
     924          24 :     case CROSS_AND_AUTO:
     925          24 :       toXML(dataStruct_.crossData_, HeaderParser::CROSSDATA, oss);
     926          24 :       toXML(dataStruct_.autoData_, HeaderParser::AUTODATA, oss);
     927          24 :       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         536 :     if (dataStruct_.zeroLags().size() != 0) {
     939           0 :       toXML(dataStruct_.zeroLags_, HeaderParser::ZEROLAGS, oss);
     940             :     }
     941             :     
     942         536 :     oss << "</" << HeaderParser::DATASTRUCT << ">" << endl;
     943         536 :   }
     944             : 
     945         536 :   string SDMDataObject::toXML()  {
     946         536 :     TSTVALID();
     947        1072 :     ostringstream result;
     948             :   
     949         536 :     result << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
     950             :   
     951             :     result << "<" << HeaderParser::SDMDATAHEADER 
     952           0 :            << " " << HeaderParser::BYTEORDER << "=\"" << byteOrder_->toString() << "\""
     953         536 :            << " " << 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        1072 :            << " " << HeaderParser::PROJECTPATH << "=" << QUOTE(projectPath())
     961             :            << " " << "xvers:schemaVersion=\"0\""
     962             :            << " " << "xvers:revision=\"0.0.96\""
     963        1072 :            << ">" << endl;
     964             :   
     965             :     // startTime...
     966         536 :     TOXML(HeaderParser::STARTTIME, startTime_, result);   
     967             :   
     968             :     // dataOID...
     969             :     result << "<" << HeaderParser::DATAOID
     970             :            << " xlink:type=\"locator\""
     971           0 :            << " xlink:" << HeaderParser::XLINKHREF  << "=" << QUOTE(dataOID_)
     972         536 :            << " xlink:" << HeaderParser::XLINKTITLE << "=" << QUOTE(title_)
     973         536 :            << "/>" << endl;
     974             :   
     975             :     // dimensionality or numTime ...
     976         536 :     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         536 :              << ">"
     987         536 :              << dimensionality_
     988         536 :              << "</" << HeaderParser::DIMENSIONALITY << ">"
     989         536 :              << endl;
     990             :     }
     991             :   
     992             :     // execBlock...
     993         536 :     result << "<" << HeaderParser::EXECBLOCK << " " << HeaderParser::XLINKHREF << "=" << QUOTE(execBlockUID_) << "/>" << endl;
     994             :   
     995             :     // numAntenna
     996         536 :     TOXML(HeaderParser::NUMANTENNA, numAntenna_, result);
     997             :   
     998             :     //correlationMode
     999         536 :     TOXML<CorrelationMode, CCorrelationMode>(HeaderParser::CORRELATIONMODE,
    1000             :                                              correlationMode_,
    1001             :                                              result);
    1002             : 
    1003             :     // spectralResolutionType ... if present.
    1004         536 :     if (spectralResolutionType_.present())
    1005         536 :       TOXML<SpectralResolutionType, CSpectralResolutionType>(HeaderParser::SPECTRALRESOLUTION,
    1006             :                                                              spectralResolutionType_.literal(),
    1007             :                                                              result);
    1008             :   
    1009             :     // processorType
    1010         536 :     TOXML<ProcessorType, CProcessorType>(HeaderParser::PROCESSORTYPE,
    1011             :                                          processorType_,
    1012             :                                          result);
    1013             :   
    1014             :     // dataStruct
    1015         536 :     dataStructToXML(result);
    1016             :   
    1017         536 :     result << "</" << HeaderParser::SDMDATAHEADER << ">";
    1018             :   
    1019             :   
    1020        1072 :     return result.str();
    1021             :   }
    1022             : 
    1023         536 :   void SDMDataObject::updateIdImageSPW() {
    1024        1072 :     ostringstream oss;
    1025        1072 :     for (unsigned int ibb = 0; ibb < dataStruct_.basebands_.size(); ibb++) {
    1026         536 :       vector<SDMDataObject::SpectralWindow>& spws = dataStruct_.basebands_.at(ibb).spectralWindows_;
    1027        1072 :       for (unsigned int ispw = 0; ispw < spws.size(); ispw++) {
    1028         536 :         oss.str("");
    1029         536 :         oss << ispw+1;
    1030         536 :         spws.at(ispw).strSw(oss.str());
    1031         536 :         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        1072 :     string key, value;
    1041         536 :     map<string, string>::const_iterator iter;
    1042        1072 :     istringstream iss;
    1043             : 
    1044             :     
    1045         536 :     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         536 :   }
    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           2 :   ByteOrder::ByteOrder(const string& name):
    1069           2 :     name_(name) {;}
    1070             : 
    1071           0 :   ByteOrder::~ByteOrder() {;}
    1072             : 
    1073           1 :   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           1 :       return Little_Endian;
    1080             :     else
    1081             :       return Big_Endian;
    1082             :   }
    1083             :   
    1084         536 :   string ByteOrder::toString() const {
    1085         536 :     return name_;
    1086             :   }
    1087             : 
    1088             :   // SDMDataObject::
    1089             : 
    1090             :   // SDMDataSubset:: methods
    1091             :   //
    1092       26492 :   SDMDataSubset::SDMDataSubset(SDMDataObject* owner) {
    1093       26492 :     owner_             = owner ;
    1094       26492 :     integrationNum_    = 0;
    1095       26492 :     subintegrationNum_ = 0;
    1096       26492 :     time_              = 0;
    1097       26492 :     interval_          = 0;
    1098       26492 :     actualTimes_       = 0;
    1099       26492 :     nActualTimes_      = 0;
    1100       26492 :     actualDurations_   = 0;
    1101       26492 :     nActualDurations_  = 0;
    1102       26492 :     zeroLags_          = 0;
    1103       26492 :     nZeroLags_         = 0;
    1104       26492 :     flags_             = 0;
    1105       26492 :     nFlags_            = 0;
    1106       26492 :     longCrossData_     = 0;
    1107       26492 :     shortCrossData_    = 0;
    1108       26492 :     floatCrossData_    = 0;
    1109       26492 :     nCrossData_        = 0;
    1110       26492 :     autoData_          = 0;
    1111       26492 :     nAutoData_         = 0;
    1112       26492 :     aborted_           = false;
    1113       26492 :   }
    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             :     owner_(owner),
    1121             :     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       20921 :   SDMDataSubset::SDMDataSubset(const SDMDataSubset& sdmDataSubset) {
    1149       20921 :     owner_             = sdmDataSubset.owner_ ;
    1150       20921 :     integrationNum_    = sdmDataSubset.integrationNum_;
    1151       20921 :     subintegrationNum_ = sdmDataSubset.subintegrationNum_;
    1152       20921 :     ref_               = sdmDataSubset.ref_;
    1153       20921 :     time_              = sdmDataSubset.time_;
    1154       20921 :     interval_          = sdmDataSubset.interval_;
    1155       20921 :     dataStruct_        = sdmDataSubset.dataStruct_;
    1156       20921 :     flagsREF_          = sdmDataSubset.flagsREF_;
    1157       20921 :     actualTimesREF_    = sdmDataSubset.actualTimesREF_;
    1158       20921 :     actualDurationsREF_= sdmDataSubset.actualDurationsREF_;
    1159       20921 :     zeroLagsREF_       = sdmDataSubset.zeroLagsREF_;
    1160       20921 :     crossDataREF_      = sdmDataSubset.crossDataREF_;
    1161       20921 :     crossDataType_     = sdmDataSubset.crossDataType_;
    1162       20921 :     autoDataREF_       = sdmDataSubset.autoDataREF_;
    1163       20921 :     actualTimes_       = sdmDataSubset.actualTimes_;
    1164       20921 :     nActualTimes_      = sdmDataSubset.nActualTimes_;
    1165       20921 :     actualDurations_   = sdmDataSubset.actualDurations_;
    1166       20921 :     nActualDurations_  = sdmDataSubset.nActualDurations_;
    1167       20921 :     zeroLags_          = sdmDataSubset.zeroLags_;
    1168       20921 :     nZeroLags_         = sdmDataSubset.nZeroLags_;
    1169       20921 :     flags_             = sdmDataSubset.flags_;
    1170       20921 :     nFlags_            = sdmDataSubset.nFlags_;
    1171       20921 :     longCrossData_     = sdmDataSubset.longCrossData_;
    1172       20921 :     shortCrossData_    = sdmDataSubset.shortCrossData_;
    1173       20921 :     floatCrossData_    = sdmDataSubset.floatCrossData_;
    1174       20921 :     nCrossData_        = sdmDataSubset.nCrossData_;
    1175       20921 :     autoData_          = sdmDataSubset.autoData_;
    1176       20921 :     nAutoData_         = sdmDataSubset.nAutoData_;
    1177       20921 :     aborted_           = sdmDataSubset.aborted_;
    1178       20921 :     abortTime_         = sdmDataSubset.abortTime_;
    1179       20921 :     abortReason_       = sdmDataSubset.abortReason_;
    1180       20921 :   }
    1181             : 
    1182        1903 :   SDMDataSubset& SDMDataSubset::operator=(const SDMDataSubset& sdmDataSubset) {
    1183        1903 :     owner_             = sdmDataSubset.owner_ ;
    1184        1903 :     integrationNum_    = sdmDataSubset.integrationNum_;
    1185        1903 :     subintegrationNum_ = sdmDataSubset.subintegrationNum_;
    1186        1903 :     ref_               = sdmDataSubset.ref_;
    1187        1903 :     time_              = sdmDataSubset.time_;
    1188        1903 :     interval_          = sdmDataSubset.interval_;
    1189        1903 :     dataStruct_        = sdmDataSubset.dataStruct_;
    1190        1903 :     flagsREF_          = sdmDataSubset.flagsREF_;
    1191        1903 :     actualTimesREF_    = sdmDataSubset.actualTimesREF_;
    1192        1903 :     actualDurationsREF_= sdmDataSubset.actualDurationsREF_;
    1193        1903 :     zeroLagsREF_       = sdmDataSubset.zeroLagsREF_;
    1194        1903 :     crossDataREF_      = sdmDataSubset.crossDataREF_;
    1195        1903 :     crossDataType_     = sdmDataSubset.crossDataType_;
    1196        1903 :     autoDataREF_       = sdmDataSubset.autoDataREF_;
    1197        1903 :     actualTimes_       = sdmDataSubset.actualTimes_;
    1198        1903 :     nActualTimes_      = sdmDataSubset.nActualTimes_;
    1199        1903 :     actualDurations_   = sdmDataSubset.actualDurations_;
    1200        1903 :     nActualDurations_  = sdmDataSubset.nActualDurations_;
    1201        1903 :     zeroLags_          = sdmDataSubset.zeroLags_;
    1202        1903 :     nZeroLags_         = sdmDataSubset.nZeroLags_;
    1203        1903 :     flags_             = sdmDataSubset.flags_;
    1204        1903 :     nFlags_            = sdmDataSubset.nFlags_;
    1205        1903 :     longCrossData_     = sdmDataSubset.longCrossData_;
    1206        1903 :     shortCrossData_    = sdmDataSubset.shortCrossData_;
    1207        1903 :     floatCrossData_    = sdmDataSubset.floatCrossData_;
    1208        1903 :     nCrossData_        = sdmDataSubset.nCrossData_;
    1209        1903 :     autoData_          = sdmDataSubset.autoData_;
    1210        1903 :     nAutoData_         = sdmDataSubset.nAutoData_;
    1211        1903 :     aborted_           = sdmDataSubset.aborted_;
    1212        1903 :     abortTime_         = sdmDataSubset.abortTime_;
    1213        1903 :     abortReason_       = sdmDataSubset.abortReason_;
    1214        1903 :     return *this;
    1215             :   }
    1216             : 
    1217       47413 :   SDMDataSubset::~SDMDataSubset() {;}
    1218             : 
    1219       60466 :   string SDMDataSubset::projectPath() const {
    1220       60466 :     if (owner_ == 0) return "";
    1221             : 
    1222      120932 :     ostringstream oss;
    1223       60466 :     oss << owner_->execBlockNum_ << "/" << owner_->scanNum_ << "/" << owner_->subscanNum_ << "/"; 
    1224             : 
    1225       60466 :     if (integrationNum_ > 0) oss << integrationNum_ << "/";
    1226       60466 :     if (subintegrationNum_ > 0) oss << subintegrationNum_ << "/";
    1227             : 
    1228       60466 :     return oss.str();
    1229             :   }
    1230             :   
    1231             : 
    1232           0 :   unsigned int SDMDataSubset::integrationNum() const { return integrationNum_; }
    1233             : 
    1234           0 :   unsigned int SDMDataSubset::subintegrationNum() const { return subintegrationNum_; }
    1235             : 
    1236       64355 :   unsigned long long SDMDataSubset::time() const { return time_; }
    1237             :   
    1238       33292 :   unsigned long long SDMDataSubset::interval() const { 
    1239             :     // if (owner_ && !owner_->isTP()) Utils::invalidCall("SDMDataSubset::interval", owner_);
    1240       33292 :     return interval_; 
    1241             :   }
    1242             : 
    1243             :    
    1244       17676 :   unsigned long int SDMDataSubset::actualDurations(const ACTUALDURATIONSTYPE* & ptr) const {ptr = actualDurations_; return nActualDurations_;}
    1245           0 :   uint64_t SDMDataSubset::actualDurationsPosition() const { return actualDurationsPosition_; }
    1246       17676 :   unsigned long int SDMDataSubset::actualTimes(const ACTUALTIMESTYPE* & ptr) const { ptr = actualTimes_; return nActualTimes_;}
    1247           0 :   uint64_t SDMDataSubset::actualTimesPosition() const { return actualTimesPosition_; }
    1248       17838 :   unsigned long int SDMDataSubset::autoData(const AUTODATATYPE* & ptr)const  { ptr = autoData_; return nAutoData_; }
    1249       54202 :   uint64_t SDMDataSubset::autoDataPosition() const { return autoDataPosition_; }
    1250       14052 :   unsigned long int SDMDataSubset::crossData(const SHORTCROSSDATATYPE* & ptr) const { 
    1251       14052 :     if (owner_ && (owner_->isTP() || owner_->correlationMode() == AUTO_ONLY)) Utils::invalidCall("SDMDataSubset::crossData", owner_);
    1252       14052 :     ptr = shortCrossData_; return nCrossData_; 
    1253             :   }
    1254       70415 :   PrimitiveDataType SDMDataSubset::crossDataType() const { return crossDataType_; }
    1255           0 :   void SDMDataSubset::crossDataType(PrimitiveDataType value) { crossDataType_ = value;}
    1256             : 
    1257         900 :   unsigned long int SDMDataSubset::crossData(const INTCROSSDATATYPE* & ptr) const { 
    1258         900 :     if (owner_ && (owner_->isTP() || owner_->correlationMode() == AUTO_ONLY)) Utils::invalidCall("SDMDataSubset::crossData", owner_);
    1259         900 :     ptr = longCrossData_; return nCrossData_; 
    1260             :   }
    1261             : 
    1262             : 
    1263        1016 :   unsigned long int SDMDataSubset::crossData(const FLOATCROSSDATATYPE* & ptr) const { 
    1264        1016 :     if (owner_ && (owner_->isTP() || owner_->correlationMode() == AUTO_ONLY)) Utils::invalidCall("SDMDataSubset::crossData", owner_);
    1265        1016 :     ptr = floatCrossData_; return nCrossData_; 
    1266             :   }
    1267             : 
    1268       27764 :   uint64_t SDMDataSubset::crossDataPosition() const { return crossDataPosition_; }
    1269       26555 :   unsigned long int SDMDataSubset::flags(const FLAGSTYPE* & ptr) const { ptr = flags_; return nFlags_; }
    1270           0 :   uint64_t SDMDataSubset::flagsPosition() const { return flagsPosition_; }
    1271             : 
    1272       13140 :   unsigned long int SDMDataSubset::zeroLags(const ZEROLAGSTYPE* & ptr) const { 
    1273       13140 :     if (owner_ && owner_->isTP()) Utils::invalidCall("SDMDataSubset::zeroLags", owner_);
    1274       13140 :     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             :   }
    1370             : 
    1371             : 
    1372       16580 :   void SDMDataSubset::binAttachToXML(const string& name, ostringstream& oss) {
    1373       16580 :     oss << "<" << name << " xlink:href= \"" << projectPath() << "/" << name << ".bin\"";
    1374       16580 :     if (name == "crossData") 
    1375        4532 :       oss << " type=\"" <<  CPrimitiveDataType::name(crossDataType_) << "\"";
    1376       16580 :     oss << "/>" << endl;
    1377       16580 :   }
    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        4532 :   void SDMDataSubset::corrBinAttachToXML(ostringstream& oss) {    
    1390             :     // The binaryAttachments elements
    1391             : 
    1392        4532 :     if (nFlags_)
    1393        4532 :       binAttachToXML(CorrSubsetHeaderParser::FLAGSREF, oss);
    1394        4532 :     if (nActualTimes_)
    1395           0 :       binAttachToXML(CorrSubsetHeaderParser::ACTUALTIMESREF, oss);
    1396        4532 :     if (nActualDurations_)
    1397           0 :       binAttachToXML(CorrSubsetHeaderParser::ACTUALDURATIONSREF, oss);
    1398             : 
    1399        4532 :     switch (owner_->correlationMode_) {
    1400        1508 :     case CROSS_ONLY:
    1401             :       
    1402        1508 :       binAttachToXML(CorrSubsetHeaderParser::CROSSDATAREF, oss);
    1403        1508 :       break;
    1404             :       
    1405           0 :     case AUTO_ONLY:
    1406           0 :       binAttachToXML(CorrSubsetHeaderParser::AUTODATAREF, oss);          
    1407           0 :       break;
    1408             : 
    1409        3024 :     case CROSS_AND_AUTO:
    1410        3024 :       binAttachToXML(CorrSubsetHeaderParser::CROSSDATAREF, oss);            
    1411        3024 :       binAttachToXML(CorrSubsetHeaderParser::AUTODATAREF, oss);          
    1412        3024 :       break;
    1413             :     }
    1414             : 
    1415        4532 :     if ((owner_->processorType_ == CORRELATOR) && (owner_->correlatorType() != FX))
    1416        4492 :         binAttachToXML(CorrSubsetHeaderParser::ZEROLAGSREF, oss);            
    1417        4532 :   }
    1418             :  
    1419             : 
    1420        4532 :   string SDMDataSubset::xsiType() const {
    1421        4532 :     string result;
    1422             :     
    1423        4532 :     switch (owner_->correlationMode_) {
    1424        1508 :     case CROSS_ONLY:     result = "BinaryCrossData" ; break;
    1425           0 :     case AUTO_ONLY:      result = "BinaryAutoData" ; break;
    1426        3024 :     case CROSS_AND_AUTO: result = "BinaryCrossAndAutoData" ; break;
    1427             :     }
    1428             :         
    1429        4532 :     return result;
    1430             :   }
    1431             : 
    1432             : 
    1433        4532 :   string SDMDataSubset::toXML() {
    1434        9064 :     ostringstream oss;
    1435             :     
    1436             :     //oss << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
    1437        4532 :     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        9064 :           << " projectPath="<< QUOTE(projectPath())
    1443        9064 :           << ">" << endl;
    1444             :       
    1445        4532 :       OXML(CorrSubsetHeaderParser::SCHEDULEPERIODTIME, oss);
    1446        4532 :       TOXML(CorrSubsetHeaderParser::TIME, time_, oss);
    1447        4532 :       TOXML(CorrSubsetHeaderParser::INTERVAL, interval_, oss);
    1448        4532 :       CXML(CorrSubsetHeaderParser::SCHEDULEPERIODTIME, oss);
    1449             :       
    1450        4532 :       oss << "<" << CorrSubsetHeaderParser::DATASTRUCT << " ref =" << QUOTE("sdmDataHeader") << "/>" << endl;
    1451        4532 :       corrBinAttachToXML(oss);
    1452        4532 :       oss << "</" << CorrSubsetHeaderParser::SDMDATASUBSETHEADER << ">";
    1453        4532 :       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             :       throw SDMDataObjectException("no XML representation defined for an SDMDataSubset with a processor type defined as '"
    1475           0 :                                    + CProcessorType::name(owner_->processorType_));
    1476             :   }
    1477             :   
    1478             : 
    1479      163656 :   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        7748 :   string Utils::quote(const string& s) {
    1487        7748 :     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             :   }
    1502             : 
    1503        5092 :   string Utils::quote(bool b) {
    1504       10184 :     ostringstream oss;
    1505        5092 :     oss << "\"" << (b?"true":"false") << "\"";
    1506       10184 :     return oss.str();
    1507             :   }
    1508             : 
    1509           0 :   string Utils::quote(int i) {
    1510           0 :     ostringstream oss;
    1511           0 :     oss << "\"" << i << "\"";
    1512           0 :     return oss.str();
    1513             :   }
    1514             : 
    1515        2704 :   string Utils::quote(unsigned int ui) {
    1516        5408 :     ostringstream oss;
    1517        2704 :     oss << "\"" << ui << "\"";
    1518        5408 :     return oss.str();
    1519             :   }
    1520             : 
    1521             : 
    1522           0 :   string Utils::quote(long long l) {
    1523           0 :     ostringstream oss;
    1524           0 :     oss << "\"" << l << "\"";
    1525           0 :     return oss.str();
    1526             :   }
    1527             : 
    1528         536 :   string Utils::quote(float f) {
    1529        1072 :     ostringstream oss;
    1530         536 :     oss << "\"" << f << "\"";
    1531        1072 :     return oss.str();
    1532             :   }
    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             :   }
    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             :   }
    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         536 :   void  Utils::toXML(const string& elementName, unsigned int value, ostringstream& oss){
    1557         536 :     oss << "<" << elementName << ">" << value << "</" << elementName << ">" << endl;
    1558         536 :   }
    1559             : 
    1560         536 :   void  Utils::toXML(const string& elementName, long long value, ostringstream& oss){
    1561         536 :     oss << "<" << elementName << ">" << value << "</" << elementName << ">" << endl;
    1562         536 :   }
    1563             : 
    1564        9064 :   void  Utils::toXML(const string& elementName, unsigned long long value, ostringstream& oss){
    1565        9064 :     oss << "<" << elementName << ">" << value << "</" << elementName << ">" << endl;
    1566        9064 :   }
    1567             : 
    1568        4532 :   void Utils::oXML(const string& elementName, ostringstream& oss) {
    1569        4532 :     oss << "<" << elementName << ">" << endl;
    1570        4532 :   }
    1571             : 
    1572        4532 :   void Utils::cXML(const string& elementName, ostringstream& oss) {
    1573        4532 :     oss << "</" << elementName << ">" << endl;
    1574        4532 :   }
    1575             : 
    1576             :   // Utils::
    1577             : 
    1578             : 
    1579             : } // asdmbinaries

Generated by: LCOV version 1.16