ifbProcRoto Class Reference

Inheritance diagram for ifbProcRoto:
ifbProcBase

List of all members.

Public Member Functions

 ifbProcRoto (ifbConfig cfgIn)
virtual ~ifbProcRoto ()
virtual int Init ()
virtual int SpillInit (double when)
virtual int SpillDevice (double when, std::string device)
virtual int SpillFinish (double when)
virtual int Finish ()
std::map< std::string, size_t > & DeviceCount ()

Private Member Functions

void CompareSpillDeviceTimes (const std::string &devname, int spillSec, int spillMSec, int devSec, int devMSec)

Private Attributes

BeamData bd
std::map< std::string, size_t > devcnt
int maxDt
int minDt

Detailed Description

Definition at line 123 of file ifbtorr.cc.


Constructor & Destructor Documentation

ifbProcRoto::ifbProcRoto ( ifbConfig  cfgIn  )  [inline]

Definition at line 125 of file ifbtorr.cc.

00125 : ifbProcBase(cfgIn), maxDt(-99999999), minDt(999999) { ; }

virtual ifbProcRoto::~ifbProcRoto (  )  [inline, virtual]

Definition at line 126 of file ifbtorr.cc.

00126 { ; }


Member Function Documentation

void ifbProcRoto::CompareSpillDeviceTimes ( const std::string &  devname,
int  spillSec,
int  spillMSec,
int  devSec,
int  devMSec 
) [private]

Definition at line 858 of file ifbtorr.cc.

References ifbProcBase::cfg, ifbConfig::DtTolerance, maxDt, and minDt.

Referenced by SpillDevice().

00861 {
00862   int diff = ( spillSec - devSec )*1000 + ( spillMSec - devMSec );
00863   if ( abs(diff) > cfg.DtTolerance ) {
00864     std::cout << "CompareSpillDeviceTimes " 
00865               << std::setw(12) << devname 
00866               << " sec " << std::setw(10) << spillSec 
00867               << "|" << std::setw(10) <<devSec
00868               << " msec " << std::setw(3) << spillMSec 
00869               << "|" << std::setw(3) << devMSec << " (delta " 
00870               << (diff) << ") " << std::endl;
00871   }
00872   if ( diff < minDt ) minDt = diff;
00873   if ( diff > maxDt ) maxDt = diff;
00874 
00875 }

std::map<std::string,size_t>& ifbProcRoto::DeviceCount (  )  [inline]

Definition at line 134 of file ifbtorr.cc.

References devcnt.

00134 { return devcnt; }

int ifbProcRoto::Finish (  )  [virtual]

Reimplemented from ifbProcBase.

Definition at line 803 of file ifbtorr.cc.

References bd, ifbProcBase::cfg, BeamData::close_connection(), BeamData::close_file(), devcnt, exename, maxDt, minDt, ifbProcBase::nspills, and ifbConfig::PrintOpts.

00804 {
00805   //
00806   // Close the file
00807   //
00808   bd.close_file();
00809 
00810   //
00811   // Close the connection to the rotorooter
00812   //
00813   bd.close_connection();
00814 
00815   //
00816   // optional print information
00817   //
00818   bool printDt = ( cfg.PrintOpts.find("times") != std::string::npos );
00819   if ( printDt ) {
00820     std::cout << exename << ": excursions spill vs. device time ( "
00821               << minDt << " " << maxDt << " )" << std::endl;
00822   }
00823   bool printDevices = ( cfg.PrintOpts.find("devices") != std::string::npos );
00824   bool printMissing = ( cfg.PrintOpts.find("missing") != std::string::npos );
00825   if ( printDevices || printMissing ) {
00826     std::cout << exename << ": " 
00827               << devcnt.size() << " devices " << nspills 
00828               << " spills";
00829     if ( ! printDevices ) cout << ", print only those missing from "
00830                                << "1 or more spills";
00831     std::cout << std::endl;
00832     int nMissingDevices = 0;
00833     std::map<std::string,size_t>::const_iterator itr = devcnt.begin();
00834     for ( ; itr != devcnt.end(); ++itr ) {
00835       size_t devSpills = itr->second;
00836       size_t missedSpills = ( nspills - devSpills);
00837       bool printDev = printDevices || ( missedSpills != 0 );
00838       if ( printDev ) {
00839         std::cout << "   " 
00840                   << std::left << std::setw(12) << itr->first << std::right
00841                   << " " << std::setw(6) << devSpills;
00842         if ( missedSpills > 0 ) {
00843           std::cout << ", missing from " << missedSpills;
00844           ++nMissingDevices;
00845         }
00846         std::cout << std::endl;
00847       }
00848     }
00849     std::cout << exename << ": " << nMissingDevices
00850               << " of " << devcnt.size() 
00851               << " devices missed at least one spill" << std::endl;
00852       
00853   }
00854 
00855   return 0;
00856 }

int ifbProcRoto::Init ( void   )  [virtual]

time of window start

Reimplemented from ifbProcBase.

Definition at line 675 of file ifbtorr.cc.

References ifbConfig::AllowRotoErrors, bd, ifbProcBase::cfg, exename, BeamData::open_connection(), BeamData::open_file(), ifbConfig::RotoNode, and ifbConfig::TimeStamp.

00676 {
00677   //
00678   // Now, we need to start talking with the rotorooter by opening
00679   // the connection, send the data and close the connection.
00680   //
00681   int conn_status = bd.open_connection(cfg.RotoNode.c_str());
00682   if ( conn_status != 0 ) {
00683     std::cerr << exename << ": failed to make rotorooter connection (" 
00684               << conn_status << ")" << std::endl << std::flush;
00685     if ( ! cfg.AllowRotoErrors ) return conn_status;
00686   }
00687 
00688   //
00689   // Open a file in the rotorooter
00690   //
00691   // Do not use time of first spill in the window to name file
00692   // but instead use the start of the requested time window
00693 
00694   //int file_status = bd.open_file(sec, nsec);         /// time of first spill
00695   int file_status = bd.open_file((int)cfg.TimeStamp,0);
00696 
00697   if ( file_status != 0 ) {
00698     std::cerr << exename << ": failed to open rotorooter file (" 
00699               << file_status << ")" << std::endl << std::flush;
00700     if ( ! cfg.AllowRotoErrors ) return file_status;
00701   }
00702 
00703   return 0;
00704 }

int ifbProcRoto::SpillDevice ( double  when,
std::string  device 
) [virtual]

Reimplemented from ifbProcBase.

Definition at line 718 of file ifbtorr.cc.

References BeamData::add_device_value(), bd, ifbProcBase::bf, ifbProcBase::cfg, CompareSpillDeviceTimes(), devcnt, DoubleToSecMSec(), BeamData::set_device_header(), and ifbConfig::Verbose.

00719 {
00720   int spillSec, spillMSec;
00721   DoubleToSecMSec(tstamp,spillSec,spillMSec);
00722 
00723   if ( devName.find("[]") != std::string::npos ) {
00724     //
00725     // Vector device (has "[]" in the name)
00726     //
00727     std::vector<double> vDeviceValue;
00728     try {
00729       // GetNamed[Vector|Data] method uses 'double when' for the
00730       // 1st arg to pick closest time.
00731       double devTime;
00732       vDeviceValue = bf->GetNamedVector(tstamp,devName,&devTime);
00733       devcnt[devName]++;  // keep track of how often we succeeded
00734       
00735       int devSec, devMSec;
00736       DoubleToSecMSec(devTime,devSec,devMSec);
00737       CompareSpillDeviceTimes(devName,spillSec,spillMSec,devSec,devMSec);
00738 
00739       // 
00740       // Start the record entry for this device
00741       //
00742       bd.set_device_header(devName.c_str(), devSec, devMSec);
00743 
00744       // Add device's values to the record
00745       for ( size_t ih=0; ih < vDeviceValue.size(); ++ih ) {
00746         bd.add_device_value(devName.c_str(),vDeviceValue[ih]);
00747       }
00748       
00749     } catch(WebAPIException we) {
00750       // Device couldn't be read. we skip it and continue
00751       if ( cfg.Verbose > 3 ) {
00752         std::cout << "... skipping device " << devName
00753                   << " (" << (int)tstamp << " - not able to read)"
00754                   << std::endl;
00755       }
00756     }
00757     
00758   } else {
00759     //
00760     // Single valued device
00761     //
00762     double DeviceValue;
00763     try {
00764       // GetNamed[Vector|Data] method uses 'double when' for the
00765       // 1st arg to pick closest time.  Add "@" to name to get 
00766       // the associated time
00767 
00768       std::string devNameAndTime = devName + "@";
00769       double devTime;
00770       bf->GetNamedData(tstamp,devNameAndTime,&DeviceValue,&devTime);
00771       devcnt[devName]++;  // keep track of how often we succeeded
00772 
00773       int devSec, devMSec;
00774       DoubleToSecMSec(devTime,devSec,devMSec);
00775       CompareSpillDeviceTimes(devName,spillSec,spillMSec,devSec,devMSec);
00776       // 
00777       // Start the record entry for this device
00778       //
00779       bd.set_device_header(devName.c_str(), devSec, devMSec);
00780 
00781       // Add device's value to the record
00782       bd.add_device_value(devName.c_str(),DeviceValue);
00783       
00784     } catch(WebAPIException we) {
00785       // Device couldn't be read. we skip it and continue
00786       if ( cfg.Verbose > 3 ) {
00787         std::cout << "... skipping device " << devName 
00788                   << " (" << (int)tstamp << " - not able to read)"
00789                   << std::endl;
00790       }
00791     }
00792   }
00793   return 0;
00794 }

int ifbProcRoto::SpillFinish ( double  when  )  [virtual]

Reimplemented from ifbProcBase.

Definition at line 795 of file ifbtorr.cc.

References bd, and BeamData::send_data().

00796 {
00797   //
00798   // Send the record to the rotorooter
00799   //
00800   bd.send_data();
00801   return 0;
00802 }

int ifbProcRoto::SpillInit ( double  when  )  [virtual]

Reimplemented from ifbProcBase.

Definition at line 705 of file ifbtorr.cc.

References bd, ifbProcBase::cfg, ifbProcBase::nspills, BeamData::start_block(), ifbConfig::TClkTriggerDelay, and ifbConfig::TClkTriggerEvent.

00706 {
00707     int secs = (int)tstamp;
00708     int secs_2ns = (tstamp - (int)tstamp)*1e9;
00709     //int secs_2ms = (tstamp - (int)tstamp)*1e3;
00710 
00711     // 3rd arg is 'tclk_event'   [169]
00712     // 4th arg is 'tclk_delay'   [500]
00713     bd.start_block(secs, secs_2ns, nspills, //spillcnt,
00714                     cfg.TClkTriggerEvent, cfg.TClkTriggerDelay);
00715 
00716   return 0;
00717 }


Member Data Documentation

Definition at line 141 of file ifbtorr.cc.

Referenced by Finish(), Init(), SpillDevice(), SpillFinish(), and SpillInit().

std::map<std::string,size_t> ifbProcRoto::devcnt [private]

Definition at line 143 of file ifbtorr.cc.

Referenced by DeviceCount(), Finish(), and SpillDevice().

int ifbProcRoto::maxDt [private]

Definition at line 145 of file ifbtorr.cc.

Referenced by CompareSpillDeviceTimes(), and Finish().

int ifbProcRoto::minDt [private]

Definition at line 146 of file ifbtorr.cc.

Referenced by CompareSpillDeviceTimes(), and Finish().


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

Generated on 15 Jul 2018 for loon by  doxygen 1.6.1