/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
RunDataSvc Class Reference

#include <RunDataSvc.h>

Inheritance diagram for RunDataSvc:
Inheritance graph
[legend]
Collaboration diagram for RunDataSvc:
Collaboration graph
[legend]

List of all members.

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.

Static Public Member Functions

static const InterfaceID & interfaceID ()

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

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.

                                               :
  Service(name,
          svc),
  m_fileIsInitialized(false)
{
  declareProperty("ReadFromFile",m_readFromFile=false,
                  "Load the run data from the current input file?");
  declareProperty("ReadFromDatabase",m_readFromDatabase=true,
                  "Check the database for run data?");
  declareProperty("RunDataLocation",
                  m_runDataLocation = DayaBay::RunHeaderLocation::Default,
                  "Path for run data if reading from file");
  declareProperty("SimRunNumber",m_simRunNumber = 0,
                  "Pass NuWa command-line run number to this service");
  declareProperty("SimRunType",m_simRunType = "Unknown",
                  "Set the simulation run type by name");
  declareProperty("SimStartTime",m_simStartTime = 0,
                  "Pass NuWa command-line start time to this service");
  declareProperty("SimCalibSources",m_simCalibSources,
                  "Active calibration sources in the simulation");
  declareProperty("SimCalibZPosition",m_simCalibZPosition,
                  "Calibration source Z position for movable AD sources");
  declareProperty("SimLedFrequency",m_simLedFrequency,
                  "Calibration LED pulsing frequency");
}

Member Function Documentation

StatusCode RunDataSvc::initialize ( ) [virtual]

Definition at line 56 of file RunDataSvc.cc.

                                  {
  StatusCode status = Service::initialize();
  if (status.isFailure()) {
    throw GaudiException("Could not initialize super class",
                         name(),
                         status);
  }
  return StatusCode::SUCCESS;
}
StatusCode RunDataSvc::finalize ( ) [virtual]

Definition at line 66 of file RunDataSvc.cc.

                                {
  // Clear run data list
  DayaBay::RunHeader::RunDataContainer::iterator it, done = m_runDataList.end();
  for (it = m_runDataList.begin(); it != done; ++it) {
    // boost::pool somehow owns the run data objects, so don't delete
    //delete *it;
  }
  m_runDataList.clear();
  return Service::finalize();
}
const DayaBay::RunData * RunDataSvc::runData ( const ServiceMode svcMode) [virtual]

IRunDataSvc method.

Implements IRunDataSvc.

Definition at line 77 of file RunDataSvc.cc.

                                                                    {
  // Return the Run Data based on the context
  // If task == 1, make new simulated Run Data if needed.

  MsgStream log(msgSvc(), "RunDataSvc");
  StatusCode sc = StatusCode::SUCCESS;
  // Catch new simulation, and make new run data if needed
  if(svcMode.task() == 1) return this->simRunData();

  // Check input sources if needed
  if( m_readFromDatabase ){
    sc = this->readDataFromDatabase(svcMode);
    if(!sc.isSuccess()) return 0;
  }
  if( m_readFromFile ){
    sc = this->readDataFromFile();
    if(!sc.isSuccess()) return 0;
  }

  DayaBay::RunData* runData = 0;
  int nRuns = m_runDataList.size();
  TimeStamp currentTime = svcMode.context().GetTimeStamp();
  DayaBay::Detector currentDet(svcMode.context().GetSite(),
                               svcMode.context().GetDetId());
  // Find correct run from current list of runs, based on the context
  for(int runIdx=0; runIdx<nRuns; runIdx++){
    DayaBay::RunData* currentRun = m_runDataList[runIdx];
    log << MSG::DEBUG << "Checking run data for run number " 
        << currentRun->runNumber() << endreq;
    if(currentRun->hasDetector(currentDet)
       && currentRun->startTime() <= currentTime 
       && (currentRun->endTime() >= currentTime
           || currentRun->endTime().IsNull())){
      // Run fits this context
      runData = currentRun;
    }
  }
  return runData;
}
StatusCode RunDataSvc::setRunData ( const DayaBay::RunData runData) [virtual]

Implements IRunDataSvc.

Definition at line 117 of file RunDataSvc.cc.

                                                              {
  // Add or update the Run Data for this run
  int nRuns = m_runDataList.size();
  bool updateRun = false;
  for(int runIdx=0; runIdx<nRuns; runIdx++){
    if( m_runDataList[runIdx]->runNumber() == runData.runNumber() ){
      // Found run in current list; update
      *(m_runDataList[runIdx]) = runData;
      updateRun = true;
      break;
    }
  }
  // Catch new run
  if( !updateRun ) m_runDataList.push_back(new DayaBay::RunData(runData));
  return StatusCode::SUCCESS;
}
const std::vector< DayaBay::RunData * > & RunDataSvc::cachedRunData ( ) [virtual]

Implements IRunDataSvc.

Definition at line 134 of file RunDataSvc.cc.

                                                           {
  // Return the current internal list of run data.
  // Use this for Database / File storage of run data
  if(m_readFromFile && !m_fileIsInitialized){
    StatusCode sc = this->readDataFromFile();
    sc.ignore();
  }
  return m_runDataList;
}
StatusCode RunDataSvc::queryInterface ( const InterfaceID &  id,
void **  interface 
) [virtual]

Methods required by ServiceManager.

Definition at line 41 of file RunDataSvc.cc.

                                                        {
  if (IRunDataSvc::interfaceID().versionMatch(id)) {
    // If good enough match return this object.
    *interface = (IRunDataSvc*)this;
    addRef();
  } else {
    // Interface is not directly available: try out a base class.
    return Service::queryInterface(id,
                                   interface);
  }

  return StatusCode::SUCCESS;
}
StatusCode RunDataSvc::readDataFromDatabase ( const ServiceMode svcMode) [private]

Definition at line 144 of file RunDataSvc.cc.

                                                               {
  // Read the run data from the DBI Database
  // FIXME: ADD code here
  MsgStream log(msgSvc(), "RunDataSvc");
  log << MSG::WARNING << "readDataFromDatabase: Loading data from DBI is not yet implemented." << endreq;
  return StatusCode::SUCCESS;
}
StatusCode RunDataSvc::readDataFromFile ( ) [private]

Definition at line 152 of file RunDataSvc.cc.

                                       {
  // Read run data from current input file

  // If file already read, don't read again
  if( m_fileIsInitialized ) return StatusCode::SUCCESS;

  MsgStream log(msgSvc(), "RunDataSvc");
  IService* isvc = 0; 
  StatusCode sc = this->service("RootIOCnvSvc",isvc,true);
  if(sc.isFailure()){
    log << MSG::ERROR << "Failed to get RootIOCnvSvc as IService" << endreq;
    return sc;
  }
  IRootIOSvc* m_rioSvc = 0;
  sc = isvc->queryInterface(IRootIOSvc::interfaceID(), (void**)&m_rioSvc);
  if (sc.isFailure()) {
    log << MSG::ERROR << "Conversion service RootIOCnvSvc"
        << " does not implement IRootIOCnvSvc" << endreq;
    return sc;
  }
  IConversionSvc* convSvc = 0;
  sc = isvc->queryInterface(IConversionSvc::interfaceID(), (void**)&convSvc);
  if (sc.isFailure()) {
    log << MSG::ERROR << "Conversion service RootIOCnvSvc"
        << " does not implement IConversionSvc" << endreq;
    return sc;
  }
  IRootIOSvc::InputStreamMap& ism = m_rioSvc->inputStreams();
  IRootIOSvc::InputStreamMap::iterator it, done = ism.end();
  for (it = ism.begin(); it != done; ++it) {
    log << MSG::DEBUG << "checking input stream: " << it->first << endreq;
    if( it->first == m_runDataLocation ){
      // Get Persistent RunHeader from file
      RootInputStream* ris = it->second;
      ris->setEntry(0);
      log << MSG::DEBUG << "Return status of read: " << ris->read() << "\t" 
          << ris->obj() << endreq;
      PerRunHeader* perRunHeader = (PerRunHeader*)(ris->obj());
      if(!perRunHeader){
        log << MSG::ERROR << "Failed to get persistent RunHeader" << endreq;
        return StatusCode::FAILURE;
      }
      log << MSG::DEBUG << "Got persistent run data for "
          << perRunHeader->runDataList.size() << " runs" << endreq;
      // Convert Persistent RunHeader to Transient
      DayaBay::RunHeader runHeader;
      IConverter* converter = convSvc->converter(runHeader.classID());
      if (!converter) {
        log << MSG::ERROR << "Failed to get RunHeader converter" << endreq;
        return StatusCode::FAILURE;
      }
      RootIOTypedCnv<PerRunHeader, DayaBay::RunHeader>* runHdrCnv = 0;
      runHdrCnv = dynamic_cast< RootIOTypedCnv<PerRunHeader, DayaBay::RunHeader>* >(converter);
      if (!runHdrCnv) {
        log << MSG::ERROR << "Failed to cast RunHeader converter" << endreq;
        return StatusCode::FAILURE;
      }
      sc = runHdrCnv->PerToTran(*perRunHeader, runHeader);
      if (sc.isFailure()) {
        log << MSG::ERROR << "Failed to translate persistent RunHeader" 
            << endreq;
        return sc;
      }
      const DayaBay::RunHeader::RunDataContainer& runDataList 
        = runHeader.runDataList();
      int nRuns = runDataList.size();
      log << MSG::DEBUG << "Got run data for " << nRuns << " runs" << endreq;
      for(int runIdx=0; runIdx < nRuns; runIdx++){
        // Add each run data to the current list
        m_runDataList.push_back(new DayaBay::RunData(*(runDataList[runIdx])));
      }
    }
  }
  m_fileIsInitialized = true;
  return StatusCode::SUCCESS;
}
const DayaBay::RunData * RunDataSvc::simRunData ( ) [private]

Definition at line 229 of file RunDataSvc.cc.

                                             {
  // Return the specified simulation Run Data.
  // If it doesn't exist, create it.
  MsgStream log(msgSvc(), "RunDataSvc");
  int nRuns = m_runDataList.size();
  // Find correct run from current list of runs, based on the sim run number
  for(int runIdx=0; runIdx<nRuns; runIdx++){
    DayaBay::RunData* currentRun = m_runDataList[runIdx];
    log << MSG::DEBUG << "Checking run data for run number " 
        << currentRun->runNumber() << endreq;
    if(currentRun->runNumber() == m_simRunNumber){
      // Found the simulation run, return it
      return currentRun;
    }
  }

  // Make a new run data, using the properties of RunDataSvc.  These
  // are automatically set by the nuwa.py command line options --run
  // and --time.
  DayaBay::RunData* runData = new DayaBay::RunData();
  runData->setRunNumber(m_simRunNumber);
  runData->setRunType( DayaBay::RunType::FromString(m_simRunType.c_str()) );
  runData->setStartTime(TimeStamp(m_simStartTime));
  // Set the simulated sources
  DayaBay::RunData::CalibSources calibSources;
  int nSources = m_simCalibSources.size();
  for(int srcIdx = 0; srcIdx<nSources; srcIdx++){
    std::string srcName = m_simCalibSources[srcIdx];
    DayaBay::CalibSourceId sourceId( srcName );
    DayaBay::CalibSource source;
    source.setId( sourceId );
    // Set AD Z position for movable sources
    std::map<std::string, double>::iterator zIter = 
      m_simCalibZPosition.find( srcName );
    if( zIter != m_simCalibZPosition.end() ) 
      source.setAdZPosition( zIter->second );
    // Set Frequency for LED sources
    std::map<std::string, double>::iterator freqIter = 
      m_simLedFrequency.find( srcName );
    if( freqIter != m_simLedFrequency.end() ) 
      source.setLedFrequency( freqIter->second );
    // Add to source list
    calibSources.push_back( source );
  }
  runData->setCalibSources( calibSources );
  m_runDataList.push_back( runData );
  return runData;
}

Member Data Documentation

Definition at line 39 of file RunDataSvc.h.

Definition at line 42 of file RunDataSvc.h.

std::string RunDataSvc::m_runDataLocation [private]

Definition at line 45 of file RunDataSvc.h.

Definition at line 48 of file RunDataSvc.h.

Definition at line 51 of file RunDataSvc.h.

Definition at line 54 of file RunDataSvc.h.

std::string RunDataSvc::m_simRunType [private]

Definition at line 57 of file RunDataSvc.h.

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 Fri May 16 2014 10:00:22 for RunDataSvc by doxygen 1.7.4