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

In This Package:

EventClockSvc.cpp

Go to the documentation of this file.
00001 // $Id: EventClockSvc.cpp,v 1.10 2009/01/23 13:09:15 cattanem Exp $
00002 // Include files 
00003 #include "GaudiKernel/SvcFactory.h"
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/IDetDataSvc.h"
00006 #include "GaudiKernel/IToolSvc.h"
00007 #include "GaudiKernel/IIncidentSvc.h"
00008 #include "GaudiKernel/Time.h"
00009 #include "GaudiKernel/IEventTimeDecoder.h"
00010 
00011 // local
00012 #include "EventClockSvc.h"
00013 
00014 DECLARE_SERVICE_FACTORY( EventClockSvc );
00015 
00016 //-----------------------------------------------------------------------------
00017 // Implementation file for class : EventClockSvc
00018 //
00019 // 2005-07-08 : Marco CLEMENCIC
00020 //-----------------------------------------------------------------------------
00021 
00022 //=============================================================================
00023 // Standard constructor, initializes variables
00024 //=============================================================================
00025 EventClockSvc::EventClockSvc(const std::string& name, ISvcLocator* svcloc):
00026   Service(name,svcloc),m_incidentSvc(NULL),m_detDataSvc(NULL),m_toolSvc(NULL),
00027   m_eventTimeDecoder(NULL)
00028 {
00029   // service name
00030   declareProperty("DetectorDataSvc",  m_detDataSvcName       = "DetectorDataSvc" );
00031 
00032   // tool name
00033   declareProperty("EventTimeDecoder", m_eventTimeDecoderName = "FakeEventTime"   );
00034 
00035   declareProperty("InitialTime",      m_initialTime          = 0                 );
00036   
00037 }
00038 //=============================================================================
00039 // Destructor
00040 //=============================================================================
00041 EventClockSvc::~EventClockSvc() {}; 
00042 
00043 //=============================================================================
00044 // IInterface implementation
00045 //=============================================================================
00046 StatusCode EventClockSvc::queryInterface(const InterfaceID& riid, void** ppvUnknown){
00047   if ( IIncidentListener::interfaceID().versionMatch(riid) ) {
00048     *ppvUnknown = (IIncidentListener*)this;
00049     addRef();
00050     return StatusCode::SUCCESS;
00051   }
00052   return Service::queryInterface(riid,ppvUnknown);
00053 }
00054 //=========================================================================
00055 //  
00056 //=========================================================================
00057 StatusCode EventClockSvc::initialize() {
00058   // base class initialization
00059   StatusCode sc = Service::initialize();
00060   if (!sc.isSuccess()) return sc;
00061 
00062   // local initialization
00063   MsgStream log(msgSvc(),name());
00064   log << MSG::DEBUG << "--- initialize ---" << endmsg;
00065 
00066   // find the detector data svc
00067   sc = service(m_detDataSvcName,m_detDataSvc,true);
00068   if (!sc.isSuccess()) {
00069     log << MSG::ERROR << "Unable to get a handle to the detector data service" << endmsg;
00070     return sc;
00071   } else {
00072     log << MSG::DEBUG << "Got pointer to IDetDataSvc \"" << m_detDataSvcName << '"' << endmsg;
00073   }
00074 
00075   // get a pointer to the tool service
00076   sc = service( "ToolSvc", m_toolSvc, true );
00077   if (!sc.isSuccess()) {
00078     log << MSG::ERROR << "Unable to get a handle to the tool service" << endmsg;
00079     return sc;
00080   } else {
00081     log << MSG::DEBUG << "Got pointer to ToolSvc " << endmsg;
00082   }
00083 
00084   sc = m_toolSvc->retrieveTool(m_eventTimeDecoderName, m_eventTimeDecoder, this);
00085   if (!sc.isSuccess()) {
00086     log << MSG::ERROR << "Unable to get a handle to the IEventTimeDecoder \"" << m_eventTimeDecoderName << '"' << endmsg;
00087     return sc;
00088   } else {
00089     log << MSG::DEBUG << "Got pointer to " <<  m_eventTimeDecoderName << endmsg;
00090   }
00091 
00092   // Set the first event time at initialization.
00093   Gaudi::Time initTime;
00094   if (m_initialTime)
00095     initTime = Gaudi::Time(m_initialTime);
00096   else
00097     initTime = Gaudi::Time::current();
00098   log << MSG::DEBUG << "Initialize event time to " << initTime << endmsg;
00099   m_detDataSvc->setEventTime(initTime);
00100 
00101   // register to the incident service for BeginEvent incidents
00102   sc = service("IncidentSvc", m_incidentSvc, false);
00103   if ( sc.isSuccess() ) {
00104     m_incidentSvc->addListener(this,IncidentType::BeginEvent);
00105     log << MSG::DEBUG << "Got pointer to IncidentSvc" << endmsg;
00106   } else {
00107     log << MSG::WARNING << "Unable to register to the incident service." << endmsg;
00108     m_incidentSvc = NULL;
00109   }
00110   return StatusCode::SUCCESS;
00111 }
00112 
00113 //=========================================================================
00114 //  
00115 //=========================================================================
00116 StatusCode EventClockSvc::finalize ( ) {
00117   // local finalization
00118   MsgStream log(msgSvc(),name());
00119   log << MSG::DEBUG << "--- finalize ---" << endmsg;
00120 
00121   // release the interfaces used
00122   if (m_toolSvc         != NULL) {
00123     if ( m_eventTimeDecoder != NULL )
00124       m_toolSvc->releaseTool(m_eventTimeDecoder).ignore();
00125     m_toolSvc->release();
00126   }
00127   if (m_detDataSvc      != NULL) m_detDataSvc->release();
00128   if (m_incidentSvc     != NULL) {
00129     // unregister from the incident svc
00130     m_incidentSvc->removeListener(this,IncidentType::BeginEvent);
00131     m_incidentSvc->release();
00132   }
00133 
00134   return Service::finalize();
00135 }
00136 //=========================================================================
00137 //  Handle BeginEvent incident
00138 //=========================================================================
00139 void EventClockSvc::handle(const Incident &inc) {
00140   MsgStream log( msgSvc(), name() );
00141   if ( inc.type() == IncidentType::BeginEvent ) {
00142     log << MSG::DEBUG << "New BeginEvent incident received" << endmsg;
00143     m_detDataSvc->setEventTime(m_eventTimeDecoder->getTime());
00144     log << MSG::DEBUG << "DetDataSvc::eventTime() -> " << m_detDataSvc->eventTime() << endmsg;
00145   } else {
00146     log << MSG::WARNING << inc.type() << " incident ignored" << endmsg;
00147   }
00148 }
00149 //=============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:42 2011 for DetDescSvc by doxygen 1.4.7