Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

EventAuditor.cxx

Go to the documentation of this file.
00001 
00002 #include "GaudiKernel/Auditor.h"
00003 #include "GaudiKernel/MsgStream.h"
00004 #include "GaudiKernel/Chrono.h"
00005 #include "GaudiKernel/IAlgorithm.h"
00006 #include "GaudiKernel/DeclareFactoryEntries.h"
00007 
00008 #include "ntupleWriterSvc/INTupleWriterSvc.h"
00009 
00010 #include <map>
00011 #include <algorithm>
00012 
00021 class EventAuditor : virtual public Auditor
00022 {
00023 public:
00024 
00025     EventAuditor( const std::string &, ISvcLocator * ) ;
00026     virtual StatusCode initialize() ;
00027     virtual StatusCode finalize() ;
00028     virtual ~EventAuditor() ;
00029 
00030     //virtual StatusCode beforeInitialize( IAlgorithm * ) ;
00031     //virtual StatusCode afterInitialize( IAlgorithm * ) ;
00032     virtual StatusCode beforeExecute( IAlgorithm * ) ;
00033     virtual StatusCode afterExecute( IAlgorithm * ) ;
00034     //virtual StatusCode beforeFinalize( IAlgorithm * ) ;
00035     //virtual StatusCode afterFinalize( IAlgorithm * ) ;
00036 
00037 private :
00038 
00039     INTupleWriterSvc* m_rootTupleSvc;
00040     StringProperty m_root_tree;
00041     bool m_save_tuple;
00042 
00043 
00045     //StringArrayProperty  m_algoNames ;
00046     std::vector<std::string>  m_algoNames ;
00047     int m_nAlgs;
00048 
00049     // some pointers to services  
00050     MsgStream * m_log ;
00051     IChronoStatSvc * m_chronoSvc ;
00052 
00053     // internals
00054     std::map< IAlgorithm *, bool > m_algoStatus ;
00055 
00056     std::vector<float> m_timeVals;
00057 } ;
00058 
00059 //==========================================================
00060 // construction
00061 //==========================================================
00062 
00063 DECLARE_AUDITOR_FACTORY(EventAuditor) ;
00064 
00078 EventAuditor::EventAuditor( const std::string & name, ISvcLocator * svcLocator )
00079 : Auditor(name,svcLocator)
00080 {
00081     std::vector<std::string> algoNamesVec ;
00082     algoNamesVec.push_back("Event");
00083     algoNamesVec.push_back("Generation");
00084     algoNamesVec.push_back("Reconstruction");
00085     algoNamesVec.push_back("Tkr");
00086     algoNamesVec.push_back("Cal2");
00087 
00088     declareProperty("algoNames",m_algoNames=algoNamesVec);
00089     declareProperty("tree_name",  m_root_tree="MeritTuple");
00090 }
00091 
00092 StatusCode EventAuditor::initialize()
00093 {
00094     Auditor::initialize() ;
00095     StatusCode sc = StatusCode::SUCCESS;
00096 
00097     setProperties();
00098     std::vector<std::string>& algoNames = m_algoNames;
00099     // make sure that Event is one of the monitored algs
00100     // this is so that we know when there's a new event
00101     // and can set the times to a default value (-1 sec)
00102     std::vector< std::string >::const_iterator algoName ;
00103     algoName = std::find(algoNames.begin(), algoNames.end(), "Event");
00104     if(algoName==algoNames.end()) {
00105         algoNames.insert(algoNames.begin(),"Event");
00106     }
00107 
00108     m_nAlgs = algoNames.size();
00109     m_timeVals.assign(m_nAlgs, -1.0);
00110 
00111     // message stream
00112     IMessageSvc * messageSvc ;
00113     service("MessageSvc",messageSvc,true) ;
00114     m_log = new MsgStream(messageSvc,name()) ;
00115 
00116     // chrono stat svc
00117     if (service("ChronoStatSvc",m_chronoSvc,true).isFailure())
00118     {
00119         (*m_log)<<MSG::ERROR<<"Could not find TkrReconSvc"<<endreq ;
00120         return StatusCode::FAILURE ;
00121     }
00122 
00123     // get a pointer to RootTupleSvc
00124     if( (service("RootTupleSvc", m_rootTupleSvc, true) ). isFailure() ) {
00125         (*m_log) << MSG::ERROR << " RootTupleSvc is not available" << endreq;
00126         m_rootTupleSvc=0;
00127         return StatusCode::FAILURE;
00128     }
00129 
00130     if( m_rootTupleSvc==0 ) return sc;
00131 
00132     std::string tname = m_root_tree.value();
00133 
00134     int i;
00135     for(i=0;i<m_nAlgs;++i) {
00136         m_rootTupleSvc->addItem(tname, "Aud"+m_algoNames[i] , &m_timeVals[i]);
00137     }
00138 
00139     (*m_log)<<MSG::DEBUG<<"initialize() "<<endreq ;
00140     return StatusCode::SUCCESS ;
00141 }
00142 
00143 //==========================================================
00144 // events loop
00145 //==========================================================
00146 
00147 //StatusCode EventAuditor::beforeInitialize( IAlgorithm * alg )
00148 //{
00149 //    (*m_log)<<MSG::DEBUG<<"beforeInitialize("<<alg->name()<<") "<<endreq ;
00150 //    return StatusCode::SUCCESS ;
00151 //}
00152 //
00153 //
00154 //StatusCode EventAuditor::afterInitialize( IAlgorithm * algo )
00155 //{
00156 //    (*m_log)<<MSG::DEBUG<<"afterInitialize("<<algo->name()<<") "<<endreq ;
00157 //    return StatusCode::SUCCESS ;
00158 //}
00159 
00160 StatusCode EventAuditor::beforeExecute( IAlgorithm * algo )
00161 {
00162     // upgrade m_algoStatus
00163     std::string thisName = algo->name();
00164     if(thisName=="Event") {
00165         // initialize the timers
00166         m_timeVals.assign(m_nAlgs, -1.0);
00167     } 
00168 
00169     std::map< IAlgorithm *, bool >::iterator itr ;
00170     itr = m_algoStatus.find(algo) ;
00171     if ( itr == m_algoStatus.end() )
00172     {
00173         const std::vector< std::string > & algoNames = m_algoNames ;
00174         std::vector< std::string >::const_iterator algoName ;
00175 
00176         algoName = std::find(algoNames.begin(), algoNames.end(), thisName);
00177         if(algoName==algoNames.end()) {
00178             m_algoStatus[algo] = false ; 
00179             return StatusCode::SUCCESS ;
00180         } else {
00181             m_algoStatus[algo] = true ;
00182         }
00183     }
00184 
00185     if(m_algoStatus[algo]) {
00186         m_chronoSvc->chronoStart("EA_"+thisName) ;
00187         (*m_log) << MSG::DEBUG << "start " << thisName << std::endl;
00188     }
00189     return StatusCode::SUCCESS ;
00190 }
00191 
00192 StatusCode EventAuditor::afterExecute( IAlgorithm * algo )
00193 {
00194     // look if the algo is under monitoring
00195     if (m_algoStatus[algo]==false)
00196     { return StatusCode::SUCCESS ; }
00197 
00198     std::string thisName = algo->name();
00199 
00200     // stop chrono
00201     m_chronoSvc->chronoStop("EA_"+thisName) ;
00202 
00203     // retrieve and log the last time interval
00204     
00205     IChronoStatSvc::ChronoTime delta
00206         = m_chronoSvc->chronoDelta("EA_"+thisName,IChronoStatSvc::USER) ;
00207 
00208     float fDelta = static_cast<float>(delta)*0.000001;
00209     (*m_log) << MSG::DEBUG << thisName <<" user time: " << fDelta << " sec" << endreq ;
00210 
00211     const std::vector< std::string > & algoNames = m_algoNames ;
00212     int i;
00213     for(i=0;i<m_nAlgs;++i) {
00214         if(thisName==algoNames[i]) {
00215             m_timeVals[i] = fDelta;
00216             break;
00217         }
00218     }
00219 
00220 /* HMK Apr172008
00221     Do not want EventAuditor forcing events to be stored to the MeritTuple
00222     without meeting our trigger requirements.  Other algorithms will set
00223     this flag for us, such as AnalysisNtupleAlg
00224 
00225     m_save_tuple = true;
00226     if( m_rootTupleSvc!=0 && !m_root_tree.value().empty()){
00227         m_rootTupleSvc->storeRowFlag(m_root_tree.value(), m_save_tuple);
00228     }
00229 */
00230 
00231     return StatusCode::SUCCESS ;
00232 }
00233 
00234 //StatusCode EventAuditor::beforeFinalize( IAlgorithm * alg )
00235 // {
00236 //     (*m_log) << MSG::DEBUG << "beforeFinalize("<<alg->name()<<") "<< endreq ;
00237 //  return StatusCode::SUCCESS ;
00238 // }
00239 //
00240 //
00241 //StatusCode EventAuditor::afterFinalize( IAlgorithm * alg )
00242 // {
00243 //     (*m_log) << MSG::DEBUG << "afterFinalize("<<alg->name()<<") "<< endreq ;
00244 //  return StatusCode::SUCCESS ;
00245 // }
00246 //
00247 
00248 //==========================================================
00249 // destruction
00250 //==========================================================
00251 
00252 StatusCode EventAuditor::finalize()
00253 {
00254     (*m_log) << MSG::DEBUG <<"finalize() "<< endreq ;
00255 //    return Auditor::finalize() ;
00256   return StatusCode::SUCCESS;
00257 
00258 }
00259 
00260 EventAuditor::~EventAuditor()
00261 {}
00262 
00263 
00264 

Generated on Mon Dec 1 20:09:05 2008 by doxygen 1.3.3