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

AnalysisNtupleAlg Class Reference

fills the ntuple from the XxxValsTools More...

Collaboration diagram for AnalysisNtupleAlg:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AnalysisNtupleAlg (const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize ()
 set parameters and attach to various perhaps useful services.

StatusCode execute ()
 process one event

StatusCode finalize ()
 clean up


Private Member Functions

void fixLoadOrder ()
 local utility methods

void removeMc ()
void printHeader (MsgStream &log)

Private Attributes

double m_count
 number of times called

INTupleWriterSvc * m_ntupleSvc
 access the ntupleWriter service to write out to ROOT ntuples

std::string m_tupleName
 parameter to store the logical name of the ROOT file to write to

std::vector< IValsTool * > m_toolvec
 Common interface to analysis tools.

std::vector< std::string > m_toolnames
 tool names

bool m_doNtuple
 switch to turn on ntupleWriterSvc, for test purposes

bool m_doDebug
bool m_countCalcs
bool m_realData
IDataProviderSvc * m_pEventSvc
IValsTool::Visitorm_visitor

Detailed Description

fills the ntuple from the XxxValsTools

Author:
Leon Rochester

Definition at line 139 of file AnalysisNtupleAlg.cxx.


Constructor & Destructor Documentation

AnalysisNtupleAlg::AnalysisNtupleAlg const std::string &  name,
ISvcLocator *  pSvcLocator
 

Definition at line 181 of file AnalysisNtupleAlg.cxx.

References m_countCalcs, m_doDebug, m_doNtuple, m_realData, m_toolnames, and m_tupleName.

00182 :Algorithm(name, pSvcLocator)
00183 ,m_count(0)
00184 {
00185     // declare properties with setProperties calls
00186     declareProperty("tupleName",  m_tupleName="MeritTuple"); 
00187     // so it looks like NTupleWriterSvc property, no harm having both!
00188     //declareProperty("tuple_name",  m_tupleName="");   
00189     // List of tools to use -- maybe a bit kludgy, since the spelling needs to be correct!
00190     declareProperty("toolList", m_toolnames);
00191     declareProperty("doNtuple", m_doNtuple=true);
00192     declareProperty("enableDebugCalc", m_doDebug=false);
00193     declareProperty("countCalcs", m_countCalcs=false);  
00194     declareProperty("realData", m_realData=false);  
00195 }


Member Function Documentation

StatusCode AnalysisNtupleAlg::execute  ) 
 

process one event

we can call them with the no-calculate flag

Definition at line 320 of file AnalysisNtupleAlg.cxx.

References m_count, m_countCalcs, m_doDebug, m_ntupleSvc, m_pEventSvc, m_toolnames, m_toolvec, m_tupleName, NOCALC, and printHeader().

00321 {
00322     StatusCode   sc = StatusCode::SUCCESS;
00323     //StatusCode fail = StatusCode::FAILURE;
00324     
00325     MsgStream   log( msgSvc(), name() );
00326 
00327     bool countCalc = m_countCalcs;
00328 
00329 
00330     ++m_count;
00331     m_ntupleSvc->storeRowFlag(m_tupleName, true);  // needed to save the event with RootTupleSvc
00332 
00333 
00334     int toolCounter = 0;
00335     bool isException = false;
00336     std::vector<IValsTool*>::iterator i = m_toolvec.begin();
00337     for( ; i != m_toolvec.end(); ++i, ++toolCounter){
00338         try {
00339             (*i)->doCalcIfNotDone();
00340         } catch( std::exception& e) {
00341             printHeader(log);
00342             log << "Non-propagator exception from " << m_toolnames[toolCounter]<< endreq; 
00343             log << e.what() << endreq;
00344         } catch (...) {
00345             printHeader(log);
00346             log << "Non-propagator exception from " << m_toolnames[toolCounter]<< endreq;
00347             isException = true;
00348         }
00349     }
00350     if(isException) {
00351 
00352       SmartDataPtr<Event::EventHeader> header(m_pEventSvc, EventModel::EventHeader);
00353       if (header) header->setAnalysisNtupleError();
00354 
00355         for(i=m_toolvec.begin() ; i != m_toolvec.end(); ++i){
00356             (*i)->zeroVals();
00357         }
00358         return sc;
00359     }
00360 
00361 
00362     // all the tools have been called at this point, so from now on,
00364     
00365     bool debugStuff = m_doDebug;
00366 
00367     if (countCalc || debugStuff) {
00368         if (m_count < 5) {
00369             log << MSG::INFO << "number of calculations per event: " << endreq; 
00370             unsigned int i;
00371             for(i =0; i<m_toolvec.size(); ++i){
00372                 log << MSG::INFO << m_toolnames[i] << ": " << m_toolvec[i]->getCalcCount()<< endreq;
00373             }
00374             log << MSG::INFO << endreq;
00375         }else {
00376             log << MSG::INFO << "call count message suppressed. " << endreq;
00377         } 
00378     }
00379 
00380     if(debugStuff) {
00381 
00382         int namesSize = m_toolnames.size();
00383         int i;
00384 
00385         //do a browse
00386 
00387         for (i=0;i<namesSize; ++i) {
00388             log << MSG::INFO << "Dump of variables in " << m_toolnames[i] << endreq;
00389             m_toolvec[i]->browse(log);
00390         }
00391 
00392         std::string varname;
00393         std::vector<std::string> varnames;
00394         varnames.clear();
00395         for (i=0; i<namesSize; ++i) {
00396             std::string toolname = m_toolnames[i];
00397             if      (toolname=="McValsTool"     ) {varname = "McXErr";}
00398             else if (toolname=="GltValsTool"    ) {varname = "GltTotal";}
00399             else if (toolname=="TkrHitValsTool" ) {varname = "TkrHitsInLyr00";}
00400             else if (toolname=="TkrValsTool"    ) {varname = "TkrSumKalEne";}
00401             else if (toolname=="VtxValsTool"    ) {varname = "VtxZDir";}
00402             else if (toolname=="CalValsTool"    ) {varname = "CalEnergyRaw";}
00403             else if (toolname=="CalMipValsTool" ) {varname = "CalMipNum";}
00404             //else if (toolname=="GcrSelectValsTool" ) {varname = "GcrSelect[1536]","InferedZ";}
00405             //else if (toolname=="GcrReconValsTool" )  {varname = "GcrRecon[1536]";}
00406             else if (toolname=="AcdValsTool"    ) {varname = "AcdTileCount";}
00407             else if (toolname=="EvtValsTool"    ) {varname = "EvtEnergyRaw";}
00408             else if (toolname=="McAnalValsTool" ) {varname = "McaPrmEnegy";}
00409             else                                  {varname = "";}
00410             varnames.push_back(varname);
00411         }
00412                
00413         // check browse() against getVal() for each tool
00414                 
00415         int vecSize = m_toolvec.size();
00416         for(i=0; i<vecSize; ++i){
00417             varname = varnames[i];
00418             if (varname=="") continue;
00419             std::string answerString;
00420             sc = m_toolvec[i]->getVal(varname, answerString, NOCALC);
00421             log  << MSG::INFO << varname << " = " << answerString << " " << endreq;  
00422             m_toolvec[i]->browse(log, varnames[i]);
00423         }        
00424     }     
00425     log << MSG::DEBUG;
00426     if (log.isActive()) {
00427         log << MSG::DEBUG << "number of calculations per event: " << endreq; 
00428         unsigned int i;
00429         for(i =0; i<m_toolvec.size(); ++i){
00430             log << MSG::DEBUG << m_toolnames[i] << ": " << m_toolvec[i]->getCalcCount()<< endreq;
00431         }
00432     }
00433     log << endreq;
00434     return sc;
00435 }

StatusCode AnalysisNtupleAlg::finalize  ) 
 

clean up

Definition at line 437 of file AnalysisNtupleAlg.cxx.

References m_count.

00437                                       {
00438     StatusCode  sc = StatusCode::SUCCESS;
00439     MsgStream log(msgSvc(), name());
00440     log << MSG::INFO << "finalize after " << m_count << " calls." << endreq;
00441     
00442     return sc;
00443 }

void AnalysisNtupleAlg::fixLoadOrder  )  [private]
 

local utility methods

Definition at line 445 of file AnalysisNtupleAlg.cxx.

References m_toolnames.

Referenced by initialize().

00446 {
00447     MsgStream log(msgSvc(), name());
00448     std::vector<std::string>::iterator tkrIter, acdIter, endIter;
00449 
00450     tkrIter = find(m_toolnames.begin(), m_toolnames.end(), "Tkr");
00451     acdIter = find(m_toolnames.begin(), m_toolnames.end(), "Acd");
00452     endIter = m_toolnames.end();
00453 
00454     if(acdIter!=endIter&&tkrIter!=endIter&&acdIter-tkrIter>0) {
00455         m_toolnames.erase(acdIter);
00456         m_toolnames.insert(tkrIter, "Acd");
00457         log << MSG::WARNING << endreq << 
00458             "Load order of ValsTools changed" << endreq
00459             << "AcdValsTool inserted beforeTkrValsTool" << endreq;
00460         unsigned int i;
00461         unsigned int namesSize = m_toolnames.size();
00462         log << MSG::WARNING << "New order: " << endreq;
00463         for (i=0; i<namesSize; ++i) {
00464             log << m_toolnames[i]+"ValsTool" << " " ;
00465         }
00466         log << endreq;
00467     }
00468 }

StatusCode AnalysisNtupleAlg::initialize  ) 
 

set parameters and attach to various perhaps useful services.

Definition at line 197 of file AnalysisNtupleAlg.cxx.

References IValsTool::Visitor::ERROR, fixLoadOrder(), m_doNtuple, m_ntupleSvc, m_pEventSvc, m_realData, m_toolnames, m_toolvec, m_tupleName, m_visitor, and removeMc().

00197                                         {
00198     StatusCode   sc = StatusCode::SUCCESS;
00199     StatusCode fail = StatusCode::FAILURE;
00200     
00201     MsgStream log(msgSvc(), name());
00202     log << MSG::INFO << "initialize" << endreq;
00203 
00204     // calc tools - default is the full set!
00205 
00206     // Use the Job options service to set the Algorithm's parameters
00207     m_toolnames.clear();
00208 
00209     setProperties();
00210 
00211     //probably a better way to do this!
00212     // default set:
00213     std::string toolnames [] = {"Mc", "Glt", "Acd", "TkrHit", "Tkr", "Vtx",  "Cal",  "Evt", "Obf", "McTkrHit", ""};
00214     unsigned int i;
00215     unsigned int namesSize = m_toolnames.size();
00216 
00217     // use the default
00218     if(m_toolnames.empty()) {
00219         for (i=0; ; ++i) {
00220             if (toolnames[i]=="") break;
00221             m_toolnames.push_back(toolnames[i]);
00222         }
00223     // fresh list, use it
00224     } else if (m_toolnames.size()>0&&m_toolnames[0]!="+") {
00225         for (i=0; i<namesSize; ++i) {
00226             m_toolnames[i] = m_toolnames[i];
00227         }
00228     // add the input to the regular list
00229     } else if (namesSize>1&&m_toolnames[0]=="+") {
00230         m_toolnames.erase(m_toolnames.begin());
00231         // first the input
00232         namesSize = m_toolnames.size();
00233         for (i=0; i<namesSize; ++i) {
00234             m_toolnames[i] = m_toolnames[i];
00235         }
00236         // then the regulars
00237         for (i=0; ; ++i) {
00238             if (toolnames[i]=="") break;
00239             m_toolnames.push_back(toolnames[i]);
00240         }
00241     }
00242 
00243     log << MSG::INFO << endreq;
00244     namesSize = m_toolnames.size();
00245     log << MSG::INFO << namesSize << " Tools requested: ";
00246     for (i=0; i<namesSize; ++i) {
00247         log << m_toolnames[i]+"ValsTool" << " " ;
00248     }
00249     log << endreq;
00250     
00251     if( m_tupleName.empty()) {
00252         log << MSG::INFO << "tupleName property not set!  No ntuple output"<<endreq;
00253     }
00254     // set up tools
00255     IToolSvc* pToolSvc = 0;
00256     
00257     sc = service("ToolSvc", pToolSvc, true);
00258     if (!sc.isSuccess ()){
00259         log << MSG::ERROR << "Can't find ToolSvc, will quit now" << endreq;
00260         return StatusCode::FAILURE;
00261     }
00262 
00263     // take care of the Acd/Tkr load order: Acd comes first!
00264     // I wish we didn't have this restriction!
00265     fixLoadOrder();
00266 
00267     // now, fix up Mc stuff for real data
00268     // the plan is to substitute McKludgeValsTool for McValsTool
00269     // and remove any other tool with "Mc" in the name.
00270     if(m_realData) removeMc();
00271 
00272     namesSize = m_toolnames.size();
00273     for (i =0; i!=namesSize; ++i){
00274          m_toolvec.push_back(0);
00275          m_toolnames[i]+="ValsTool";
00276         sc = pToolSvc->retrieveTool(m_toolnames[i], m_toolvec.back());
00277         m_toolvec.back()->setLoadOrder(i);
00278         if( sc.isFailure() ) {
00279             log << MSG::ERROR << "Unable to find tool: " 
00280                 << m_toolnames[i] << endreq;
00281             return sc;
00282         }
00283     }
00284         
00285     // get a pointer to our ntupleWriterSvc
00286     m_ntupleSvc = 0;
00287     if (!m_tupleName.empty()&& m_doNtuple) {
00288         if (service("RootTupleSvc", m_ntupleSvc, true).isFailure()) {
00289             log << MSG::ERROR 
00290                 << "AnalysisNtupleAlg failed to get the RootTupleSvc" 
00291                 << endreq;
00292             return fail;
00293         }
00294     }
00295     
00296     m_visitor = new NtupleVisitor(m_ntupleSvc, m_tupleName);
00297     
00298     if (!m_tupleName.empty() && m_doNtuple) {
00299                 
00300         int size = m_toolvec.size();
00301         for( int i =0; i<size; ++i){
00302             if(m_toolvec[i]->traverse(m_visitor, false)==IValsTool::Visitor::ERROR) {
00303                 log << MSG::ERROR << m_toolvec[i] << " traversal failed" << endreq;
00304                 return fail;
00305             }
00306         }
00307         IDataProviderSvc* eventsvc = 0;
00308           sc = serviceLocator()->service( "EventDataSvc", eventsvc, true );
00309           if(sc.isFailure()){
00310               log << MSG::ERROR << "Could not find EventDataSvc" << std::endl;
00311               return sc;
00312           }
00313           m_pEventSvc = eventsvc;
00314 
00315     }
00316     
00317     return sc;
00318 }

void AnalysisNtupleAlg::printHeader MsgStream &  log  )  [private]
 

Definition at line 501 of file AnalysisNtupleAlg.cxx.

References m_pEventSvc.

Referenced by execute().

00502 {
00503       SmartDataPtr<Event::EventHeader> header(m_pEventSvc, EventModel::EventHeader);
00504       unsigned long evtId = (header) ? header->event() : 0;
00505       long runId = (header) ? header->run() : -1;
00506       log << MSG::WARNING << "Caught exception (run,event): ( " 
00507           << runId << ", " << evtId << " ) " << endreq;
00508 }

void AnalysisNtupleAlg::removeMc  )  [private]
 

Definition at line 470 of file AnalysisNtupleAlg.cxx.

References m_toolnames.

Referenced by initialize().

00471 {
00472     MsgStream log(msgSvc(), name());
00473     std::vector<std::string>::iterator  endIter, lastIter, listIter, thisIter, mckIter;
00474     mckIter = find(m_toolnames.begin(), m_toolnames.end(), "McKludge");
00475     endIter = m_toolnames.end();
00476     lastIter = endIter;
00477     --lastIter;
00478 
00479     for(listIter=lastIter; listIter!=--m_toolnames.begin(); --listIter) {
00480         if(*listIter=="Mc") {
00481             thisIter = m_toolnames.erase(listIter);
00482             if(mckIter==endIter)  { m_toolnames.insert(thisIter, "McKludge");}
00483         } else if (listIter->find("Mc")!=std::string::npos) {
00484             m_toolnames.erase(listIter);
00485         }
00486     }
00487     unsigned int namesSize = m_toolnames.size();
00488     unsigned int i;
00489     log << MSG::WARNING << endreq <<
00490         "Real Data Run: Mc tools removed or modified" << endreq
00491         << "Final Order: " << endreq;
00492     for (i=0; i<namesSize; ++i) {
00493         log << m_toolnames[i]+"ValsTool" << " " ;
00494     }
00495     log << endreq;
00496 
00497     log << endreq;
00498     return;
00499 }


Member Data Documentation

double AnalysisNtupleAlg::m_count [private]
 

number of times called

Definition at line 156 of file AnalysisNtupleAlg.cxx.

Referenced by execute(), and finalize().

bool AnalysisNtupleAlg::m_countCalcs [private]
 

Definition at line 170 of file AnalysisNtupleAlg.cxx.

Referenced by AnalysisNtupleAlg(), and execute().

bool AnalysisNtupleAlg::m_doDebug [private]
 

Definition at line 169 of file AnalysisNtupleAlg.cxx.

Referenced by AnalysisNtupleAlg(), and execute().

bool AnalysisNtupleAlg::m_doNtuple [private]
 

switch to turn on ntupleWriterSvc, for test purposes

Definition at line 168 of file AnalysisNtupleAlg.cxx.

Referenced by AnalysisNtupleAlg(), and initialize().

INTupleWriterSvc* AnalysisNtupleAlg::m_ntupleSvc [private]
 

access the ntupleWriter service to write out to ROOT ntuples

Definition at line 159 of file AnalysisNtupleAlg.cxx.

Referenced by execute(), and initialize().

IDataProviderSvc* AnalysisNtupleAlg::m_pEventSvc [private]
 

Definition at line 173 of file AnalysisNtupleAlg.cxx.

Referenced by execute(), initialize(), and printHeader().

bool AnalysisNtupleAlg::m_realData [private]
 

Definition at line 171 of file AnalysisNtupleAlg.cxx.

Referenced by AnalysisNtupleAlg(), and initialize().

std::vector<std::string> AnalysisNtupleAlg::m_toolnames [private]
 

tool names

Definition at line 166 of file AnalysisNtupleAlg.cxx.

Referenced by AnalysisNtupleAlg(), execute(), fixLoadOrder(), initialize(), and removeMc().

std::vector<IValsTool*> AnalysisNtupleAlg::m_toolvec [private]
 

Common interface to analysis tools.

Definition at line 164 of file AnalysisNtupleAlg.cxx.

Referenced by execute(), and initialize().

std::string AnalysisNtupleAlg::m_tupleName [private]
 

parameter to store the logical name of the ROOT file to write to

Definition at line 161 of file AnalysisNtupleAlg.cxx.

Referenced by AnalysisNtupleAlg(), execute(), and initialize().

IValsTool::Visitor* AnalysisNtupleAlg::m_visitor [private]
 

Definition at line 175 of file AnalysisNtupleAlg.cxx.

Referenced by initialize().


The documentation for this class was generated from the following file:
Generated on Mon Dec 1 20:09:09 2008 by doxygen 1.3.3