Difference between revisions of "PropertiesExample"

From Atlas Wiki
Jump to navigation Jump to search
Line 22: Line 22:
 
   sc=service("StoreGateSvc",m_StoreGate);
 
   sc=service("StoreGateSvc",m_StoreGate);
 
   if (sc.isFailure()) {
 
   if (sc.isFailure()) {
     mLog << MSG::FATAL << "StoreGate service not found !" << endreq;
+
     log << MSG::FATAL << "StoreGate service not found !" << endreq;
 
     return StatusCode::FAILURE;
 
     return StatusCode::FAILURE;
 
   }  
 
   }  
Line 31: Line 31:
 
   StatusCode ExampleAlg::execute(){
 
   StatusCode ExampleAlg::execute(){
 
     StatusCode sc = m_storeGate->retrieve( m_tracks, "DummyTrackCollection" );
 
     StatusCode sc = m_storeGate->retrieve( m_tracks, "DummyTrackCollection" );
 +
    if (sc.isFailure()) {
 +
      log << MSG::FATAL << "Could not find DummyTrackCollection at location DummyTrackCollection !" << endreq;
 +
    } else log << MSG::INFO << "Found a DummyTrackCollection containing " << m_tracks->size() << " tracks." << endreq;
 +
    return sc;
 
   }  
 
   }  
 
</pre>
 
</pre>

Revision as of 13:48, 25 October 2006

Introduction

Setting properties allows the user to steer the Algorithms with help of the jobOptions.py. The advantage of this that you don't need to recompile your algorithms/tool every time you think of a change. Properties are handy too if one wants to set cut-offs, point to different files in CASTOR, use different names for ntuples and trees, and the like.

Accessing StoreGate

To let your Algorithm point to StoreGate, one should first concider two things:

  • What kind of DataObject do I want to retrieve? (answer: a DummyTrackCollection)
  • What is the key under what StoreGate has recorded it? (answer: "DummyTrackCollection")

So the ExampleAlg should have an instance of the DummyTrackCollection (to store the DummyTracks in): declare this in the header ExampleAlg.h:

class DummyTrackCollection;
class StoreGateSvc;
class ExampleAlg : public Algorithm{
  ...
  private :
  DummyTrackCollection* m_tracks;
  StoreGateSvc*     m_storeGate;

In the implementation of ExampleAlg::initialize(), retrieve the StoregateService:

  sc=service("StoreGateSvc",m_StoreGate);
  if (sc.isFailure()) {
    log << MSG::FATAL << "StoreGate service not found !" << endreq;
    return StatusCode::FAILURE;
  } 

Every event, we want to retrieve the collection of DummyTracks:

  StatusCode ExampleAlg::execute(){
    StatusCode sc = m_storeGate->retrieve( m_tracks, "DummyTrackCollection" );
    if (sc.isFailure()) {
      log << MSG::FATAL << "Could not find DummyTrackCollection at location DummyTrackCollection !" << endreq;
    } else log << MSG::INFO << "Found a DummyTrackCollection containing " << m_tracks->size() << " tracks." << endreq;
    return sc;
  }