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

In This Package:

RunChangeHandlerSvc.cpp

Go to the documentation of this file.
00001 // $Id: RunChangeHandlerSvc.cpp,v 1.2 2009/02/04 18:02:28 marcocle Exp $
00002 // Include files
00003 #include "GaudiKernel/SvcFactory.h"
00004 #include "GaudiKernel/IRegistry.h"
00005 #include "GaudiKernel/IOpaqueAddress.h"
00006 
00007 #include "DetDesc/ValidDataObject.h"
00008 #include "DetDesc/RunChangeIncident.h"
00009 
00010 #include <boost/format.hpp>
00011 
00012 // local
00013 #include "RunChangeHandlerSvc.h"
00014 
00015 DECLARE_SERVICE_FACTORY( RunChangeHandlerSvc );
00016 
00017 //-----------------------------------------------------------------------------
00018 // Implementation file for class : RunChangeHandlerSvc
00019 //
00020 // 2008-07-24 : Marco Clemencic
00021 //-----------------------------------------------------------------------------
00022 
00023 //=============================================================================
00024 // Standard constructor, initializes variables
00025 //=============================================================================
00026 RunChangeHandlerSvc::RunChangeHandlerSvc(const std::string &name, ISvcLocator *svcLoc):
00027   Service(name,svcLoc),
00028   m_currentRun(0),
00029   m_evtSvc(0),m_detSvc(0),m_incSvc(0),m_ums(0),m_evtProc(0)
00030 {
00031   declareProperty("Conditions", m_condDesc,
00032    "Map defining what to use to replace the location of the source XML files.");
00033 }
00034 
00035 //=============================================================================
00036 // Destructor
00037 //=============================================================================
00038 RunChangeHandlerSvc::~RunChangeHandlerSvc() {}
00039 
00040 //=============================================================================
00041 // IInterface implementation
00042 //=============================================================================
00043 StatusCode RunChangeHandlerSvc::queryInterface(const InterfaceID& riid, void** ppvUnknown){
00044   if ( IIncidentListener::interfaceID().versionMatch(riid) ) {
00045     *ppvUnknown = (IIncidentListener*)this;
00046     addRef();
00047     return StatusCode::SUCCESS;
00048   }
00049   return Service::queryInterface(riid,ppvUnknown);
00050 }
00051 
00052 //=============================================================================
00053 // Initialize
00054 //=============================================================================
00055 StatusCode RunChangeHandlerSvc::initialize(){
00056   // base class initialization
00057   StatusCode sc = Service::initialize();
00058   if (!sc.isSuccess()) return sc;
00059   // local initialization
00060   MsgStream log(msgSvc(),name());
00061   log << MSG::DEBUG << "--- initialize ---" << endmsg;
00062 
00063   incidentSvc()->addListener(this, IncidentType::RunChange);
00064   // ensure that we can call evtProc() and updMgrSvc() while in handle
00065   evtProc();
00066   updMgrSvc();
00067 
00068   // Prepare the list of conditions
00069   CondDescMap::iterator condDesc;
00070   for (condDesc = m_condDesc.begin(); condDesc != m_condDesc.end(); ++condDesc) {
00071     m_conditions.push_back(CondData(detectorSvc(),condDesc->first,condDesc->second));
00072     updMgrSvc()->registerCondition(this,condDesc->first);
00073   }
00074   // FIXME: (MCl) This is a hack to be sure that the UMS knows about all the
00075   // objects we have to modify before we get to the first event.
00076   return updMgrSvc()->update(this);
00077 }
00078 
00079 //=============================================================================
00080 // Finalize
00081 //=============================================================================
00082 StatusCode RunChangeHandlerSvc::finalize(){
00083   // local finalization
00084   MsgStream log(msgSvc(),name());
00085   log << MSG::DEBUG << "--- finalize ---" << endmsg;
00086 
00087   if (m_incSvc)
00088     incidentSvc()->removeListener(this, IncidentType::RunChange);
00089 
00090   // release acquired interfaces
00091   release(m_evtSvc);
00092   release(m_detSvc);
00093   release(m_incSvc);
00094   release(m_ums);
00095   release(m_evtProc);
00096 
00097   // base class finalization
00098   return Service::finalize();
00099 }
00100 
00101 //=========================================================================
00102 // Handle RunChange incident
00103 //=========================================================================
00104 void RunChangeHandlerSvc::handle(const Incident &inc) {
00105   MsgStream log( msgSvc(), name() );
00106   log << MSG::DEBUG << inc.type() << " incident received" << endmsg;
00107 
00108   const RunChangeIncident* rci = dynamic_cast<const RunChangeIncident*>(&inc);
00109   if (!rci) {
00110     log << MSG::ERROR << "Cannot dynamic_cast the incident to RunChangeIncident, "
00111                          " run change ignored" << endmsg;
00112     return;
00113   }
00114   
00115   if (m_currentRun != rci->runNumber()) {
00116     log << MSG::DEBUG << "Change of run number detected " << m_currentRun;
00117     m_currentRun = rci->runNumber();
00118     log << "->" << m_currentRun << endmsg;
00119 
00120     // loop over the object to update
00121     Conditions::iterator cond;
00122     for (cond = m_conditions.begin(); cond != m_conditions.end(); ++cond) {
00123       update(*cond);
00124     }
00125   }
00126 }
00127 
00128 //=========================================================================
00129 // Handle RunChange incident
00130 //=========================================================================
00131 void RunChangeHandlerSvc::update(CondData &cond){
00132   // get the object and its registry
00133   if (cond.object) {
00134     IRegistry *reg = cond.object->registry();
00135     if (reg) {
00136       // get the opaque address
00137       IOpaqueAddress *addr = reg->address();
00138       if (addr) {
00139         // This is a bit of a hack, but it is the only way of replacing the
00140         // URL to use for an object.
00141         std::string* par = const_cast<std::string*>(addr->par());
00142         par[0] = (boost::format(cond.pathTemplate) % m_currentRun).str();
00143         // notify the UMS and the object that they have to be updated.
00144         cond.object->forceUpdateMode();
00145         updMgrSvc()->invalidate(cond.object.ptr());
00146         // exit to avoid the trap at the end of the function
00147         return;
00148       }
00149     }
00150   }
00151   // If we get here, it means that we cannot manipulate the address
00152   evtProc()->stopRun(); // schedule a stop
00153   throw GaudiException("Cannot modify address for object at " + cond.object.path(), name(), StatusCode::FAILURE);
00154 }
| 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