Difference between revisions of "PropertiesExample"

From Atlas Wiki
Jump to navigation Jump to search
 
Line 10: Line 10:
 
<pre>
 
<pre>
 
class DummyTrackCollection;
 
class DummyTrackCollection;
 +
class StoreGateSvc;
 
class ExampleAlg : public Algorithm{
 
class ExampleAlg : public Algorithm{
 
   ...
 
   ...
 
   private :
 
   private :
 
   DummyTrackCollection* m_tracks;
 
   DummyTrackCollection* m_tracks;
 +
  StoreGateSvc*    m_storeGate;
 
</pre>
 
</pre>
  
 
In the source file, retrieve the StoregateService and retrieve the collection:
 
In the source file, retrieve the StoregateService and retrieve the collection:
 
<pre>
 
<pre>
 
+
  sc=service("StoreGateSvc",m_StoreGate);
 +
  if (sc.isFailure()) {
 +
    mLog << MSG::FATAL << "StoreGate service not found !" << endreq;
 +
    return StatusCode::FAILURE;
 +
  }
 
</pre>
 
</pre>

Revision as of 15:43, 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 source file, retrieve the StoregateService and retrieve the collection:

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