cfEventData Class Reference

List of all members.

Public Member Functions

 cfEventData (const std::string &fnameIn, int entryIn, const std::string &line, bool verboseIn=false)
virtual ~cfEventData ()
size_t NumMerged () const
std::string Filename (int indx=0) const
int32_t Entry (int indx=0) const
std::string Trigger (int indx=0) const
msTimeStamp_t TimeStamp (int indx=0) const
int32_t EventTriggerInt (int indx=0) const
int32_t Delay (int indx=0) const
bool PreSubT (int indx=0) const
msTimeStamp_t EarliestTime () const
const std::map< std::string,
cfDeviceData * > & 
Devices () const
void AdoptDeviceData (cfDeviceData *&dd)
void MergeEvent (cfEventData *&ed)

Protected Member Functions

void Unpack ()

Protected Attributes

std::vector< std::string > fname
std::vector< int32_t > entry
std::vector< std::string > edata
std::vector< std::string > label
std::vector< msTimeStamp_tts_ms
std::vector< int32_t > etint
std::vector< int32_t > delay
std::vector< bool > presubt
std::map< std::string,
cfDeviceData * > 
ddmap
bool verbose

Detailed Description

Definition at line 280 of file cf2rr.cc.


Constructor & Destructor Documentation

cfEventData::cfEventData ( const std::string &  fnameIn,
int  entryIn,
const std::string &  line,
bool  verboseIn = false 
) [inline]

Definition at line 282 of file cf2rr.cc.

References Basename(), edata, entry, fname, and Unpack().

00283                                                            : 
00284     verbose(verboseIn) { 
00285       fname.push_back(Basename(fnameIn));
00286       entry.push_back(entryIn);
00287       edata.push_back(line);
00288       Unpack(); 
00289   }

cfEventData::~cfEventData (  )  [virtual]

Definition at line 872 of file cf2rr.cc.

References ddmap.

00872                           {
00873   // need to clean up owned data
00874   //if ( verbose ) {
00875   //  std::cerr << "~cfEventData delete devices " << ddmap.size() << std::endl;
00876   //}
00877   std::map<std::string,cfDeviceData*>::reverse_iterator dditr = ddmap.rbegin();
00878   int32_t i = 0;
00879   for ( ; dditr != ddmap.rend(); ++dditr, ++i ) {
00880     cfDeviceData* dd = dditr->second;
00881     //if ( verbose ) std::cerr << " ... delete [" << std::setw(3) << i
00882     //                         << "] @ " << dd << std::endl;
00883     if ( ! dd ) continue;  // already gone
00884     //if ( verbose ) std::cerr << " .. delete [" << std::setw(3) << i << "] "
00885     //                         << dd->DeviceName() << std::endl;
00886     dditr->second = 0;
00887     delete dd;
00888   }
00889   //if ( verbose ) std::cerr << "~cfEventData done" << std::endl;
00890 }


Member Function Documentation

void cfEventData::AdoptDeviceData ( cfDeviceData *&  dd  ) 

Definition at line 1021 of file cf2rr.cc.

References cfDeviceData::Data(), ddmap, cfDeviceData::DeviceFullName(), and fname.

Referenced by MergeEvent(), and cfProcessor::ReadOneFile().

01021                                                    {
01022   std::string device = dd->DeviceFullName();
01023   std::map<std::string,cfDeviceData*>::iterator ddmapitr = ddmap.find(device);
01024   if ( ddmapitr == ddmap.end() ) {
01025     // device is not there, just add it
01026     ddmap.insert( std::pair<std::string,cfDeviceData*>(device,dd) );
01027   } else {
01028     // one already exists for this device
01029     //if ( verbose > 0 ) {
01030     //  std::cout << "AdoptDeviceData() merge for " << device << std::endl;
01031     //}
01032     bool same = ddmapitr->second->IsSame(*dd);
01033     if ( ! same ) {
01034       std::cout << "AdoptDeviceData() ... drop 2nd copy device " << device 
01035                 << " ... differs from 1st" << std::endl;
01036       std::cout << "files: ";
01037       for (size_t i=0; i<fname.size(); ++i) { 
01038         if ( i != 0 ) cout << "       ";
01039         std::cout << fname[i] << std::endl;
01040       }
01041       std::cout << "   \"" << dd->Data() << "\"" << std::endl
01042                 << "   \"" << ddmapitr->second->Data() << "\"" << std::endl;
01043     }
01044     delete dd;
01045   }
01046   dd = 0; // caller now longer owns this, make sure they don't use it
01047 }

int32_t cfEventData::Delay ( int  indx = 0  )  const [inline]

Definition at line 298 of file cf2rr.cc.

References delay.

Referenced by cfProcessor::ReadOneFile(), and cfProcessor::SendToRotorooter().

00298 { return delay[indx]; }

const std::map<std::string,cfDeviceData*>& cfEventData::Devices (  )  const [inline]

Definition at line 302 of file cf2rr.cc.

References ddmap.

Referenced by cfProcessor::AdoptEvent(), cfProcessor::PrintStatistics(), cfProcessor::ReadOneFile(), and cfProcessor::SendToRotorooter().

00302 { return ddmap; }

msTimeStamp_t cfEventData::EarliestTime (  )  const

Definition at line 1007 of file cf2rr.cc.

References ddmap.

Referenced by cfProcessor::AdoptEvent(), cfProcessor::MergeAdjacent(), cfProcessor::ReadOneFile(), and cfProcessor::SendToRotorooter().

01007                                               {
01008   msTimeStamp_t tearly = 0x7FFFFFFFFFFFFFFFLL;  // need LL for long long-ness
01009   // do not look over only the merged event times, but all the devices
01010   //for ( size_t indx=0; indx < ts_ms.size(); ++indx ) {
01011   //  if ( ts_ms[indx] < tearly ) tearly = ts_ms[indx];
01012   //}
01013   std::map<std::string,cfDeviceData*>::const_iterator ddmapitr = ddmap.begin();
01014   for ( ; ddmapitr != ddmap.end(); ++ddmapitr ) {
01015     msTimeStamp_t devtime = ddmapitr->second->TimeStamp();
01016     if ( devtime < tearly ) tearly = devtime;
01017   }
01018   return tearly;
01019 }

int32_t cfEventData::Entry ( int  indx = 0  )  const [inline]

Definition at line 294 of file cf2rr.cc.

References entry.

Referenced by cfProcessor::ReadOneFile().

00294 { return entry[indx];  }

int32_t cfEventData::EventTriggerInt ( int  indx = 0  )  const [inline]

Definition at line 297 of file cf2rr.cc.

References etint.

Referenced by cfProcessor::ReadOneFile(), and cfProcessor::SendToRotorooter().

00297 { return etint[indx]; }

std::string cfEventData::Filename ( int  indx = 0  )  const [inline]

Definition at line 293 of file cf2rr.cc.

References fname.

Referenced by cfProcessor::ReadOneFile().

00293 { return fname[indx];  }

void cfEventData::MergeEvent ( cfEventData *&  ed  ) 

Definition at line 1049 of file cf2rr.cc.

References AdoptDeviceData(), ddmap, delay, edata, entry, etint, fname, label, presubt, and ts_ms.

01049                                              {
01050   // adopt pointer, merge data into this one
01051   // a.insert(a.end(), b.begin(), b.end());
01052   fname.insert(fname.end(), ed->fname.begin(), ed->fname.end());
01053   entry.insert(entry.end(), ed->entry.begin(), ed->entry.end());
01054   edata.insert(edata.end(), ed->edata.begin(), ed->edata.end());
01055   label.insert(label.end(), ed->label.begin(), ed->label.end());
01056   ts_ms.insert(ts_ms.end(), ed->ts_ms.begin(), ed->ts_ms.end());
01057   etint.insert(etint.end(), ed->etint.begin(), ed->etint.end());
01058   delay.insert(delay.end(), ed->delay.begin(), ed->delay.end());
01059   presubt.insert(presubt.end(), ed->presubt.begin(), ed->presubt.end());
01060   std::map<std::string,cfDeviceData*>::iterator ddmapitr = ed->ddmap.begin();
01061   for ( ; ddmapitr != ed->ddmap.end(); ++ddmapitr ) {
01062     AdoptDeviceData(ddmapitr->second);
01063     ddmapitr->second = 0; // was adopted by previous call
01064   }
01065   // now destroy the object who's contents we've copied and/or adopted
01066   delete ed;
01067   ed = 0;
01068 }

size_t cfEventData::NumMerged (  )  const [inline]

Definition at line 292 of file cf2rr.cc.

References ts_ms.

Referenced by cfProcessor::PrintStatistics().

00292 { return ts_ms.size(); }

bool cfEventData::PreSubT ( int  indx = 0  )  const [inline]

Definition at line 299 of file cf2rr.cc.

References presubt.

Referenced by cfProcessor::ReadOneFile().

00299 { return presubt[indx]; }

msTimeStamp_t cfEventData::TimeStamp ( int  indx = 0  )  const [inline]

Definition at line 296 of file cf2rr.cc.

References ts_ms.

Referenced by cfProcessor::AdoptEvent(), and cfProcessor::ReadOneFile().

00296 { return ts_ms[indx];  }

std::string cfEventData::Trigger ( int  indx = 0  )  const [inline]

Definition at line 295 of file cf2rr.cc.

References label.

Referenced by cfProcessor::ReadOneFile().

00295 { return label[indx];  }

void cfEventData::Unpack (  )  [protected]

Definition at line 892 of file cf2rr.cc.

References cf2rr_ed_badevent, delay, edata, etint, exit(), label, presubt, TokenizeString(), ts_ms, UTCTimeString(), and verbose.

Referenced by cfEventData().

00892                          {
00893   // unpack the data line
00894   // lines should looks something like:
00895   //   *<label><space><time>[<space><delay>]
00896   // ala:
00897   //   *e,a9,e,500 <time>
00898   //   *e,a9 <time> 500
00899   // these should be space separated, but allow tabs to be used as well
00900   // suppress empty fields;  <delay> is optional.  Special cases like:
00901   //   *e,a9+500 <time>
00902   // should be treated as "*e,a9 <time> 500" but aren't really expected
00903   // to happen except in very unusual circumstances.
00904   std::vector<std::string> elements = TokenizeString(edata[0]," \t",false);
00905 
00906   if ( elements.size() < 2 ) {
00907     std::cerr << "cfEventData::Unpack() failed on reading \"" 
00908               << edata[0] << "\", need at least 2 fields" 
00909               << std::endl;
00910     exit(cf2rr_ed_badevent);
00911   }
00912 
00913   std::string label1 = elements[0];
00914   label.push_back(label1);
00915 
00916   istringstream isst(elements[1]);
00917   msTimeStamp_t ts_ms1;
00918   isst >> ts_ms1;
00919   ts_ms.push_back(ts_ms1);
00920 
00921   if ( isst.fail() ) {
00922     std::cerr << "cfEventData::Unpack() failed on reading \"" 
00923               << edata[0] << "\"" 
00924               << std::endl
00925               << label1 << " " << ts_ms1
00926               << std::endl;
00927     exit(cf2rr_ed_badevent);
00928   }
00929 
00930   std::vector<std::string> ebits = TokenizeString(label1,",+",false);
00931   // special case e,a9+500 should be treated as new format
00932   // make sure delay string gets put where it is expected (as 3rd element)
00933   size_t iplus = label1.find("+");
00934   if ( iplus != std::string::npos ) {
00935     elements.push_back(ebits[2]);
00936   }
00937 
00938   if ( ebits.size() < 2 ) {
00939     std::cerr << "cfEventData::Unpack() failed on reading \"" 
00940               << edata[0] << "\"" 
00941               << std::endl
00942               << " ebits.size " << ebits.size()
00943               << " \"" << label1 << "\" "
00944               << std::endl;
00945     exit(cf2rr_ed_badevent);
00946   }
00947 
00948   std::string etstr = "0x" + ebits[1];  // i.e. "0xa9" from "e,a9..."
00949   int32_t etintval = 0;
00950   istringstream isset(etstr);
00951   // need the std::hex here or parser stops at x and returns zero
00952   isset >> std::hex >> etintval;
00953   etint.push_back(etintval);
00954   //std::cerr << "cfEventData::Unpack() etstr \"" << etstr << "\" " << etintval << " size " << etint.size() << " etint[0] " << etint[0] << std::endl;
00955 
00956 
00957   if ( isset.fail() ) {
00958     std::cerr << "cfEventData::Unpack() failed on reading \"" 
00959               << edata[0] << "\"" 
00960               << std::endl
00961               << " etstr \"" << etstr << "\" " << etintval
00962               << std::endl;
00963     exit(cf2rr_ed_badevent);
00964   }
00965 
00966   std::string dstr = "0";
00967   if ( elements.size() > 2 ) {
00968     // new format:   e,a9  <time>  <delay>
00969     presubt.push_back(true);
00970     dstr = elements[2];
00971     // rejigger label to be +<delay>
00972     label[0] += "+" + dstr;
00973   } else {
00974     // normally old format e,a9,e,500  ... pick 500 as delay
00975     presubt.push_back(false);
00976     if ( ebits.size() >= 4 ) dstr = ebits[3];
00977   }
00978 
00979   istringstream issd(dstr);
00980   int32_t delayval;
00981   issd >> delayval;
00982   delay.push_back(delayval);
00983 
00984   if ( issd.fail() ) {
00985     std::cerr << "cfEventData::Unpack() failed on reading \"" 
00986               << edata[0] << "\"" 
00987               << std::endl
00988               << " presubt " << ((presubt[0])?"true":"false") 
00989               << " \"" << dstr << "\" " << delayval
00990               << std::endl;
00991     exit(cf2rr_ed_badevent);
00992   }
00993 
00994   // restore old behaviour by adding back in the delay if it's been subtracted
00995   if ( presubt[0] ) ts_ms1 += delayval;
00996 
00997   if ( verbose ) {
00998     std::cout << "cfEventData::Unpack() " << label1
00999               << " " << ts_ms1 
01000               << " " << UTCTimeString(ts_ms1)
01001               << std::endl; 
01002   }
01003   // done with data ... clear it
01004   edata.clear();
01005 }


Member Data Documentation

std::map<std::string,cfDeviceData*> cfEventData::ddmap [protected]

Definition at line 319 of file cf2rr.cc.

Referenced by AdoptDeviceData(), Devices(), EarliestTime(), MergeEvent(), and ~cfEventData().

std::vector<int32_t> cfEventData::delay [protected]

Definition at line 316 of file cf2rr.cc.

Referenced by Delay(), MergeEvent(), and Unpack().

std::vector<std::string> cfEventData::edata [protected]

Definition at line 312 of file cf2rr.cc.

Referenced by cfEventData(), MergeEvent(), and Unpack().

std::vector<int32_t> cfEventData::entry [protected]

Definition at line 311 of file cf2rr.cc.

Referenced by cfEventData(), Entry(), and MergeEvent().

std::vector<int32_t> cfEventData::etint [protected]

Definition at line 315 of file cf2rr.cc.

Referenced by EventTriggerInt(), MergeEvent(), and Unpack().

std::vector<std::string> cfEventData::fname [protected]

Definition at line 310 of file cf2rr.cc.

Referenced by AdoptDeviceData(), cfEventData(), Filename(), and MergeEvent().

std::vector<std::string> cfEventData::label [protected]

Definition at line 313 of file cf2rr.cc.

Referenced by MergeEvent(), Trigger(), and Unpack().

std::vector<bool> cfEventData::presubt [protected]

Definition at line 317 of file cf2rr.cc.

Referenced by MergeEvent(), PreSubT(), and Unpack().

std::vector< msTimeStamp_t> cfEventData::ts_ms [protected]

Definition at line 314 of file cf2rr.cc.

Referenced by MergeEvent(), NumMerged(), TimeStamp(), and Unpack().

bool cfEventData::verbose [protected]

Definition at line 321 of file cf2rr.cc.

Referenced by Unpack().


The documentation for this class was generated from the following file:

Generated on 17 Jun 2018 for loon by  doxygen 1.6.1