| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

RunDataSvc Class Reference

#include <RunDataSvc.h>

Inheritance diagram for RunDataSvc:

[legend]
Collaboration diagram for RunDataSvc:
[legend]
List of all members.

Public Types

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
enum  Status
 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR

Public Member Functions

 RunDataSvc (const std::string &name, ISvcLocator *svc)
 Standard Service Constructor.
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual const DayaBay::RunDatarunData (const ServiceMode &svcMode)
 IRunDataSvc method.
virtual StatusCode setRunData (const DayaBay::RunData &runData)
virtual const std::vector<
DayaBay::RunData * > & 
cachedRunData ()
virtual StatusCode queryInterface (const InterfaceID &id, void **interface)
 Methods required by ServiceManager.
virtual unsigned long addRef ()
virtual unsigned long release ()
virtual const std::string & name () const
virtual const InterfaceIDtype () const
virtual StatusCode configure ()
virtual StatusCode start ()
virtual StatusCode stop ()
virtual StatusCode terminate ()
virtual Gaudi::StateMachine::State FSMState () const
virtual Gaudi::StateMachine::State targetFSMState () const
virtual StatusCode reinitialize ()
virtual StatusCode restart ()
virtual StatusCode sysInitialize ()
virtual StatusCode sysStart ()
virtual StatusCode sysStop ()
virtual StatusCode sysFinalize ()
virtual StatusCode sysReinitialize ()
virtual StatusCode sysRestart ()
virtual StatusCode setProperty (const Property &p)
virtual StatusCode setProperty (const std::string &s)
virtual StatusCode setProperty (const std::string &n, const std::string &v)
StatusCode setProperty (const std::string &name, const TYPE &value)
virtual StatusCode getProperty (Property *p) const
virtual const PropertygetProperty (const std::string &name) const
virtual StatusCode getProperty (const std::string &n, std::string &v) const
virtual const std::vector<
Property * > & 
getProperties () const
ISvcLocatorserviceLocator () const
IMessageSvcmsgSvc ()
IMessageSvcmsgSvc () const
IMessageSvcmessageService ()
IMessageSvcmessageService () const
StatusCode setProperties ()
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
IAuditorSvcauditorSvc () const
virtual unsigned long addRef ()=0
virtual unsigned long release ()=0

Static Public Member Functions

static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()

Public Attributes

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR

Protected Member Functions

int outputLevel () const

Protected Attributes

IntegerProperty m_outputLevel
Gaudi::StateMachine::State m_state
Gaudi::StateMachine::State m_targetState
IMessageSvcm_messageSvc

Private Member Functions

StatusCode readDataFromDatabase (const ServiceMode &svcMode)
StatusCode readDataFromFile ()
const DayaBay::RunDatasimRunData ()

Private Attributes

bool m_readFromFile
bool m_readFromDatabase
std::string m_runDataLocation
std::vector< DayaBay::RunData * > m_runDataList
bool m_fileIsInitialized
int m_simRunNumber
std::string m_simRunType
int m_simStartTime
std::vector< std::string > m_simCalibSources
std::map< std::string, double > m_simCalibZPosition
std::map< std::string, double > m_simLedFrequency

Friends

friend class ServiceManager

Detailed Description

Definition at line 12 of file RunDataSvc.h.


Constructor & Destructor Documentation

RunDataSvc::RunDataSvc ( const std::string &  name,
ISvcLocator svc 
)

Standard Service Constructor.

Definition at line 14 of file RunDataSvc.cc.

00015                                                :
00016   Service(name,
00017           svc),
00018   m_fileIsInitialized(false)
00019 {
00020   declareProperty("ReadFromFile",m_readFromFile=false,
00021                   "Load the run data from the current input file?");
00022   declareProperty("ReadFromDatabase",m_readFromDatabase=true,
00023                   "Check the database for run data?");
00024   declareProperty("RunDataLocation",
00025                   m_runDataLocation = DayaBay::RunHeaderLocation::Default,
00026                   "Path for run data if reading from file");
00027   declareProperty("SimRunNumber",m_simRunNumber = 0,
00028                   "Pass NuWa command-line run number to this service");
00029   declareProperty("SimRunType",m_simRunType = "Unknown",
00030                   "Set the simulation run type by name");
00031   declareProperty("SimStartTime",m_simStartTime = 0,
00032                   "Pass NuWa command-line start time to this service");
00033   declareProperty("SimCalibSources",m_simCalibSources,
00034                   "Active calibration sources in the simulation");
00035   declareProperty("SimCalibZPosition",m_simCalibZPosition,
00036                   "Calibration source Z position for movable AD sources");
00037   declareProperty("SimLedFrequency",m_simLedFrequency,
00038                   "Calibration LED pulsing frequency");
00039 }


Member Function Documentation

StatusCode RunDataSvc::initialize (  )  [virtual]

Reimplemented from Service.

Definition at line 56 of file RunDataSvc.cc.

00056                                   {
00057   StatusCode status = Service::initialize();
00058   if (status.isFailure()) {
00059     throw GaudiException("Could not initialize super class",
00060                          name(),
00061                          status);
00062   }
00063   return StatusCode::SUCCESS;
00064 }

StatusCode RunDataSvc::finalize (  )  [virtual]

Reimplemented from Service.

Definition at line 66 of file RunDataSvc.cc.

00066                                 {
00067   // Clear run data list
00068   DayaBay::RunHeader::RunDataContainer::iterator it, done = m_runDataList.end();
00069   for (it = m_runDataList.begin(); it != done; ++it) {
00070     // boost::pool somehow owns the run data objects, so don't delete
00071     //delete *it;
00072   }
00073   m_runDataList.clear();
00074   return Service::finalize();
00075 }

const DayaBay::RunData * RunDataSvc::runData ( const ServiceMode svcMode  )  [virtual]

IRunDataSvc method.

Implements IRunDataSvc.

Definition at line 77 of file RunDataSvc.cc.

00077                                                                     {
00078   // Return the Run Data based on the context
00079   // If task == 1, make new simulated Run Data if needed.
00080 
00081   MsgStream log(msgSvc(), "RunDataSvc");
00082   StatusCode sc = StatusCode::SUCCESS;
00083   // Catch new simulation, and make new run data if needed
00084   if(svcMode.task() == 1) return this->simRunData();
00085 
00086   // Check input sources if needed
00087   if( m_readFromDatabase ){
00088     sc = this->readDataFromDatabase(svcMode);
00089     if(!sc.isSuccess()) return 0;
00090   }
00091   if( m_readFromFile ){
00092     sc = this->readDataFromFile();
00093     if(!sc.isSuccess()) return 0;
00094   }
00095 
00096   DayaBay::RunData* runData = 0;
00097   int nRuns = m_runDataList.size();
00098   TimeStamp currentTime = svcMode.context().GetTimeStamp();
00099   DayaBay::Detector currentDet(svcMode.context().GetSite(),
00100                                svcMode.context().GetDetId());
00101   // Find correct run from current list of runs, based on the context
00102   for(int runIdx=0; runIdx<nRuns; runIdx++){
00103     DayaBay::RunData* currentRun = m_runDataList[runIdx];
00104     log << MSG::DEBUG << "Checking run data for run number " 
00105         << currentRun->runNumber() << endreq;
00106     if(currentRun->hasDetector(currentDet)
00107        && currentRun->startTime() <= currentTime 
00108        && (currentRun->endTime() >= currentTime
00109            || currentRun->endTime().IsNull())){
00110       // Run fits this context
00111       runData = currentRun;
00112     }
00113   }
00114   return runData;
00115 }

StatusCode RunDataSvc::setRunData ( const DayaBay::RunData runData  )  [virtual]

Implements IRunDataSvc.

Definition at line 117 of file RunDataSvc.cc.

00117                                                               {
00118   // Add or update the Run Data for this run
00119   int nRuns = m_runDataList.size();
00120   bool updateRun = false;
00121   for(int runIdx=0; runIdx<nRuns; runIdx++){
00122     if( m_runDataList[runIdx]->runNumber() == runData.runNumber() ){
00123       // Found run in current list; update
00124       *(m_runDataList[runIdx]) = runData;
00125       updateRun = true;
00126       break;
00127     }
00128   }
00129   // Catch new run
00130   if( !updateRun ) m_runDataList.push_back(new DayaBay::RunData(runData));
00131   return StatusCode::SUCCESS;
00132 }

const std::vector< DayaBay::RunData * > & RunDataSvc::cachedRunData (  )  [virtual]

Implements IRunDataSvc.

Definition at line 134 of file RunDataSvc.cc.

00134                                                            {
00135   // Return the current internal list of run data.
00136   // Use this for Database / File storage of run data
00137   if(m_readFromFile && !m_fileIsInitialized){
00138     StatusCode sc = this->readDataFromFile();
00139     sc.ignore();
00140   }
00141   return m_runDataList;
00142 }

StatusCode RunDataSvc::queryInterface ( const InterfaceID id,
void **  interface 
) [virtual]

Methods required by ServiceManager.

Reimplemented from Service.

Definition at line 41 of file RunDataSvc.cc.

00042                                                         {
00043   if (IRunDataSvc::interfaceID().versionMatch(id)) {
00044     // If good enough match return this object.
00045     *interface = (IRunDataSvc*)this;
00046     addRef();
00047   } else {
00048     // Interface is not directly available: try out a base class.
00049     return Service::queryInterface(id,
00050                                    interface);
00051   }
00052 
00053   return StatusCode::SUCCESS;
00054 }

StatusCode RunDataSvc::readDataFromDatabase ( const ServiceMode svcMode  )  [private]

Definition at line 144 of file RunDataSvc.cc.

00144                                                                          {
00145   // Read the run data from the DBI Database
00146   // FIXME: ADD code here
00147   MsgStream log(msgSvc(), "RunDataSvc");
00148   log << MSG::WARNING << "readDataFromDatabase: Loading data from DBI is not yet implemented." << endreq;
00149   return StatusCode::SUCCESS;
00150 }

StatusCode RunDataSvc::readDataFromFile (  )  [private]

Definition at line 152 of file RunDataSvc.cc.

00152                                        {
00153   // Read run data from current input file
00154 
00155   // If file already read, don't read again
00156   if( m_fileIsInitialized ) return StatusCode::SUCCESS;
00157 
00158   MsgStream log(msgSvc(), "RunDataSvc");
00159   IService* isvc = 0; 
00160   StatusCode sc = this->service("RootIOCnvSvc",isvc,true);
00161   if(sc.isFailure()){
00162     log << MSG::ERROR << "Failed to get RootIOCnvSvc as IService" << endreq;
00163     return sc;
00164   }
00165   IRootIOSvc* m_rioSvc = 0;
00166   sc = isvc->queryInterface(IRootIOSvc::interfaceID(), (void**)&m_rioSvc);
00167   if (sc.isFailure()) {
00168     log << MSG::ERROR << "Conversion service RootIOCnvSvc"
00169         << " does not implement IRootIOCnvSvc" << endreq;
00170     return sc;
00171   }
00172   IConversionSvc* convSvc = 0;
00173   sc = isvc->queryInterface(IConversionSvc::interfaceID(), (void**)&convSvc);
00174   if (sc.isFailure()) {
00175     log << MSG::ERROR << "Conversion service RootIOCnvSvc"
00176         << " does not implement IConversionSvc" << endreq;
00177     return sc;
00178   }
00179   IRootIOSvc::InputStreamMap& ism = m_rioSvc->inputStreams();
00180   IRootIOSvc::InputStreamMap::iterator it, done = ism.end();
00181   for (it = ism.begin(); it != done; ++it) {
00182     log << MSG::DEBUG << "checking input stream: " << it->first << endreq;
00183     if( it->first == m_runDataLocation ){
00184       // Get Persistent RunHeader from file
00185       RootInputStream* ris = it->second;
00186       ris->setEntry(0);
00187       log << MSG::DEBUG << "Return status of read: " << ris->read() << "\t" 
00188           << ris->obj() << endreq;
00189       PerRunHeader* perRunHeader = (PerRunHeader*)(ris->obj());
00190       if(!perRunHeader){
00191         log << MSG::ERROR << "Failed to get persistent RunHeader" << endreq;
00192         return StatusCode::FAILURE;
00193       }
00194       log << MSG::DEBUG << "Got persistent run data for "
00195           << perRunHeader->runDataList.size() << " runs" << endreq;
00196       // Convert Persistent RunHeader to Transient
00197       DayaBay::RunHeader runHeader;
00198       IConverter* converter = convSvc->converter(runHeader.classID());
00199       if (!converter) {
00200         log << MSG::ERROR << "Failed to get RunHeader converter" << endreq;
00201         return StatusCode::FAILURE;
00202       }
00203       RootIOTypedCnv<PerRunHeader, DayaBay::RunHeader>* runHdrCnv = 0;
00204       runHdrCnv = dynamic_cast< RootIOTypedCnv<PerRunHeader, DayaBay::RunHeader>* >(converter);
00205       if (!runHdrCnv) {
00206         log << MSG::ERROR << "Failed to cast RunHeader converter" << endreq;
00207         return StatusCode::FAILURE;
00208       }
00209       sc = runHdrCnv->PerToTran(*perRunHeader, runHeader);
00210       if (sc.isFailure()) {
00211         log << MSG::ERROR << "Failed to translate persistent RunHeader" 
00212             << endreq;
00213         return sc;
00214       }
00215       const DayaBay::RunHeader::RunDataContainer& runDataList 
00216         = runHeader.runDataList();
00217       int nRuns = runDataList.size();
00218       log << MSG::DEBUG << "Got run data for " << nRuns << " runs" << endreq;
00219       for(int runIdx=0; runIdx < nRuns; runIdx++){
00220         // Add each run data to the current list
00221         m_runDataList.push_back(new DayaBay::RunData(*(runDataList[runIdx])));
00222       }
00223     }
00224   }
00225   m_fileIsInitialized = true;
00226   return StatusCode::SUCCESS;
00227 }

const DayaBay::RunData * RunDataSvc::simRunData (  )  [private]

Definition at line 229 of file RunDataSvc.cc.

00229                                              {
00230   // Return the specified simulation Run Data.
00231   // If it doesn't exist, create it.
00232   MsgStream log(msgSvc(), "RunDataSvc");
00233   int nRuns = m_runDataList.size();
00234   // Find correct run from current list of runs, based on the sim run number
00235   for(int runIdx=0; runIdx<nRuns; runIdx++){
00236     DayaBay::RunData* currentRun = m_runDataList[runIdx];
00237     log << MSG::DEBUG << "Checking run data for run number " 
00238         << currentRun->runNumber() << endreq;
00239     if(currentRun->runNumber() == m_simRunNumber){
00240       // Found the simulation run, return it
00241       return currentRun;
00242     }
00243   }
00244 
00245   // Make a new run data, using the properties of RunDataSvc.  These
00246   // are automatically set by the nuwa.py command line options --run
00247   // and --time.
00248   DayaBay::RunData* runData = new DayaBay::RunData();
00249   runData->setRunNumber(m_simRunNumber);
00250   runData->setRunType( DayaBay::RunType::FromString(m_simRunType.c_str()) );
00251   runData->setStartTime(TimeStamp(m_simStartTime));
00252   // Set the simulated sources
00253   DayaBay::RunData::CalibSources calibSources;
00254   int nSources = m_simCalibSources.size();
00255   for(int srcIdx = 0; srcIdx<nSources; srcIdx++){
00256     std::string srcName = m_simCalibSources[srcIdx];
00257     DayaBay::CalibSourceId sourceId( srcName );
00258     DayaBay::CalibSource source;
00259     source.setId( sourceId );
00260     // Set AD Z position for movable sources
00261     std::map<std::string, double>::iterator zIter = 
00262       m_simCalibZPosition.find( srcName );
00263     if( zIter != m_simCalibZPosition.end() ) 
00264       source.setAdZPosition( zIter->second );
00265     // Set Frequency for LED sources
00266     std::map<std::string, double>::iterator freqIter = 
00267       m_simLedFrequency.find( srcName );
00268     if( freqIter != m_simLedFrequency.end() ) 
00269       source.setLedFrequency( freqIter->second );
00270     // Add to source list
00271     calibSources.push_back( source );
00272   }
00273   runData->setCalibSources( calibSources );
00274   m_runDataList.push_back( runData );
00275   return runData;
00276 }


Member Data Documentation

bool RunDataSvc::m_readFromFile [private]

Definition at line 39 of file RunDataSvc.h.

bool RunDataSvc::m_readFromDatabase [private]

Definition at line 42 of file RunDataSvc.h.

std::string RunDataSvc::m_runDataLocation [private]

Definition at line 45 of file RunDataSvc.h.

std::vector<DayaBay::RunData*> RunDataSvc::m_runDataList [private]

Definition at line 48 of file RunDataSvc.h.

bool RunDataSvc::m_fileIsInitialized [private]

Definition at line 51 of file RunDataSvc.h.

int RunDataSvc::m_simRunNumber [private]

Definition at line 54 of file RunDataSvc.h.

std::string RunDataSvc::m_simRunType [private]

Definition at line 57 of file RunDataSvc.h.

int RunDataSvc::m_simStartTime [private]

Definition at line 60 of file RunDataSvc.h.

std::vector<std::string> RunDataSvc::m_simCalibSources [private]

Definition at line 63 of file RunDataSvc.h.

std::map<std::string, double> RunDataSvc::m_simCalibZPosition [private]

Definition at line 66 of file RunDataSvc.h.

std::map<std::string, double> RunDataSvc::m_simLedFrequency [private]

Definition at line 69 of file RunDataSvc.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:22:44 2011 for RunDataSvc by doxygen 1.4.7