/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Protected Member Functions | Protected Attributes
DybAlgorithm< HeaderType > Class Template Reference

#include <DybAlgorithm.h>

Inheritance diagram for DybAlgorithm< HeaderType >:
Inheritance graph
[legend]
Collaboration diagram for DybAlgorithm< HeaderType >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DybAlgorithm (const std::string &name, ISvcLocator *pSvcLocator)
 The ctor. Base classes must call this in their own ctor.
virtual ~DybAlgorithm ()
HeaderType * GetCurrentHeaderObject () const
 Access last HeaderType HeaderObject made.
virtual StatusCode sysInitialize ()
 Will call initialize().
virtual StatusCode sysExecute ()
 Will call preExecute() execute() and postExecute().
virtual StatusCode preExecute ()
 be called before execute().
virtual StatusCode postExecute ()
 be called after execute().
virtual StatusCode sysFinalize ()
 Will call finalize().
IDataProviderSvc * arcSvc () const
 Utility methods for subclasses:
void putTES (DataObject *obj, std::string location) const
 Put data in the TES.
template<class TYPE >
TYPE * getTES (std::string location) const
 Access data from the TES.
template<class TYPE >
TYPE * getAES (std::string location, int index) const
 Access data from the Archive Event service at the given index.
std::vector< DataObject * > getAEScollection (std::string location) const
 Return the list of archived data objects at the given location.
int getExecNum ()
 Access current execution ("event") number.
std::string Location () const
 Access the TES location.

Protected Member Functions

HeaderType * MakeHeaderObject ()
 Sub classes should call this towards the beginning of execute(), and certainly before any random numbers are consumed.
void InitializeHeader (DayaBay::HeaderObject *header)
 Initialize new header object. Set exec number, job id, etc.
template<class TYPE >
TYPE * MakeHeader ()
template<class TYPE >
TYPE * MakeHeader (std::vector< const DayaBay::IHeader * > &inputHeaders)
template<class TYPE >
TYPE * MakeHeader (const DayaBay::IHeader *referenceHeader)
void AppendInputHeader (const DayaBay::HeaderObject *header) const
 Explicitly add an input header that was retrieved directly instead of through this classes get* methods.

Protected Attributes

DayaBay::HeaderObjectm_headerObject
bool m_pullMode
 runing mode, push or pull
std::string m_location
 Property: Location.

Detailed Description

template<class HeaderType>
class DybAlgorithm< HeaderType >

Definition at line 8 of file DybAlgorithm.h.


Constructor & Destructor Documentation

template<class HeaderType >
DybAlgorithm< HeaderType >::DybAlgorithm ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

The ctor. Base classes must call this in their own ctor.

Definition at line 7 of file DybAlgorithmImp.h.

    : DybBaseAlg(name,pSvcLocator)
{
    declareProperty("Location",m_location = HeaderType::defaultLocation(),
                    "TES path location for the HeaderObject this algorithm produces.");

    m_pullMode = false;
}
template<class HeaderType >
DybAlgorithm< HeaderType >::~DybAlgorithm ( ) [virtual]

Definition at line 17 of file DybAlgorithmImp.h.

{
}

Member Function Documentation

template<class HeaderType >
HeaderType * DybAlgorithm< HeaderType >::GetCurrentHeaderObject ( ) const

Access last HeaderType HeaderObject made.

Definition at line 38 of file DybAlgorithmImp.h.

{ 
    return dynamic_cast<HeaderType*>(m_headerObject);
}
template<class HeaderType >
HeaderType * DybAlgorithm< HeaderType >::MakeHeaderObject ( ) [protected]

Sub classes should call this towards the beginning of execute(), and certainly before any random numbers are consumed.

It makes and returns a new object of HeaderType, registers it in the TES and sets all the HeaderObject base class values it can (everything except for the TimeStamp and the input HeaderObjects which the subclass must take care of).

Definition at line 22 of file DybAlgorithmImp.h.

{
    if (m_headerObject) {
        debug () << "MakeHeaderObject, returning cached" << endreq;
        return GetCurrentHeaderObject();
    }
    
    HeaderType *typed_header = new HeaderType;
    m_headerObject = typed_header;
    this->InitializeHeader(m_headerObject);
    
    debug() << "MakeHeaderObject with exec num " << getExecNum() << endreq;
    return typed_header;
}
StatusCode DybBaseAlg::sysInitialize ( ) [virtual, inherited]

Will call initialize().

Definition at line 29 of file DybBaseAlg.cc.

{
    // Call parent
    StatusCode sc = this->GaudiAlgorithm::initialize();
    if (sc.isFailure()) return sc;

    // This insinuates on GaudiAlgorithm's operation in order to do
    // any "dybish" initialization:
    // do_dybstuff_init();

    // Trigger calling subclass, back to your regularly scheduled operations
    sc = this->Algorithm::sysInitialize();    
    if (sc.isFailure()) return sc;

    return StatusCode::SUCCESS;
}
StatusCode DybBaseAlg::sysExecute ( ) [virtual, inherited]

Will call preExecute() execute() and postExecute().

Definition at line 46 of file DybBaseAlg.cc.

{
  if(!m_pullMode) {
    if(preExecute().isFailure()) return StatusCode::FAILURE;
  }

  // Trigger subclass's execute();                                                                             
  if (this->Algorithm::sysExecute().isFailure()) return StatusCode::FAILURE;

  if(!m_pullMode) {
    if(postExecute().isFailure()) return StatusCode::FAILURE;
  }

  return StatusCode::SUCCESS;
}
StatusCode DybBaseAlg::preExecute ( ) [virtual, inherited]

be called before execute().

Definition at line 62 of file DybBaseAlg.cc.

{
    if (!m_saveRandomState) return StatusCode::SUCCESS;

    // Get random state
    IRndmEngine *engine = 0;
    if (randSvc()->queryInterface(IID_IRndmEngine,(void**)&engine).isFailure()) {
        warning() << "Could not get IRndmEngine interace from random service, "
            "no state saved!" << endreq;
    }
    else {
        engine->rndmState(m_state);
        debug () << "Storing random state: [";
        for (size_t ind=0; ind<m_state.size(); ++ind) {
            debug () << " " << m_state[ind];
        }
        debug () << " ]" << endreq;
    }
    
    return StatusCode::SUCCESS;
}
StatusCode DybBaseAlg::postExecute ( ) [virtual, inherited]

be called after execute().

Definition at line 84 of file DybBaseAlg.cc.

{
    // Set some base HeaderObject values
    if (m_headerObject) {
        m_headerObject->setRandomState(m_state);
        const std::vector<const DayaBay::IHeader*> iheaders(m_inputHeaders.begin(),m_inputHeaders.end());
        m_headerObject->setInputHeaders(iheaders);


        // Add to TES.  This must be done after algorithm has chance to
        // fill earliest/latest with non-default values as this put()
        // triggers an insert() into the RegistrationSequence.
        
        if (!m_pullMode) {
            put(m_headerObject,m_location);
        }
    }

    // Prepare alg for next execution cycle
    debug() <<"Clearing " << m_inputHeaders.size() << " cached input headers" << endreq;
    m_inputHeaders.clear();
    ++m_execNum;
    m_headerObject = 0;               // owned by TES

    return StatusCode::SUCCESS;
}
StatusCode DybBaseAlg::sysFinalize ( ) [virtual, inherited]

Will call finalize().

Definition at line 111 of file DybBaseAlg.cc.

{
    if (this->finalize().isFailure()) {
        return StatusCode::FAILURE;
    }
    return this->GaudiAlgorithm::finalize();
}
IDataProviderSvc * DybBaseAlg::arcSvc ( ) const [inherited]

Utility methods for subclasses:

Access the archive Event Service

Definition at line 148 of file DybBaseAlg.cc.

{
    return 0;                   // fixme
}
void DybBaseAlg::putTES ( DataObject *  obj,
std::string  location 
) const [inherited]

Put data in the TES.

It is like a normal put<>() but will build up the full path leading to the location with DataObjects.

Definition at line 153 of file DybBaseAlg.cc.

{
    // Look for pre-existing header object or make new one, creating
    // the supporting path as we go.
    std::string::size_type ind = location.find("/"); // skip initial "/".
    while (true) {
        ind = location.find("/",ind+1);
        if (ind == std::string::npos) {
            debug() << "Putting final: " << location << endreq;
            put(obj,location);
            break;
        }
        else {
            // make the supporting path from simple DataObjects
            debug() << "Making intermediate: " << location.substr(0,ind)
                   << endreq;
            getOrCreate<DataObject,DataObject>(location.substr(0,ind));
        }
    }
}
template<class TYPE >
TYPE * DybBaseAlg::getTES ( std::string  location) const [inherited]

Access data from the TES.

As a side effect, if this data is a HeaderObject it will be recorded into the current header objects list of input header objects.

Definition at line 142 of file DybBaseAlg.h.

{
    TYPE* obj = get<TYPE>(location);
    // If object happens to be a HeaderObject, save it in the intputHeaders
    DayaBay::HeaderObject* header = dynamic_cast<DayaBay::HeaderObject*>(obj);
    if (header) {
        if (std::find(m_inputHeaders.begin(),m_inputHeaders.end(),header) == m_inputHeaders.end()) {
            this->AppendInputHeader(header);
            debug() << "Saved " << m_inputHeaders.size() 
                   << " input headers from TES, latest: " 
                   << header->name() 
                   << endreq;
        }
    }
    return obj;
}
template<class TYPE >
TYPE * DybBaseAlg::getAES ( std::string  location,
int  index 
) const [inherited]

Access data from the Archive Event service at the given index.

Index==0 is the most recent. As a side effect, if this data is a HeaderObject it will be recorded into the current header objects list of input header objects.

Definition at line 160 of file DybBaseAlg.h.

{
    if (index<0) return 0;

    std::vector<DataObject*> vec = this->getAEScollection(location);
    if (!vec.size() || index >= vec.size()) return 0;
    DataObject* dobj = vec[index];
    TYPE* obj = dynamic_cast<TYPE*>(dobj);
    if (!obj) return 0;

    DayaBay::HeaderObject* header = dynamic_cast<DayaBay::HeaderObject*>(obj);
    if (header) {
        if (std::find(m_inputHeaders.begin(),m_inputHeaders.end(),header) == m_inputHeaders.end()) {
            this->AppendInputHeader(header);
            debug() << "Saved " << m_inputHeaders.size() 
                   << " input headers from TES, latest: " 
                   << header->name() 
                   << endreq;
        }
    }

    return obj;
}
std::vector< DataObject * > DybBaseAlg::getAEScollection ( std::string  location) const [inherited]

Return the list of archived data objects at the given location.

Note: this does NOT automatically add anything into the list of input headers for this algorithm's output. If your subclass uses anything from this list you MUST add it to the input headers manually or people will not know what when in to your output.

Definition at line 175 of file DybBaseAlg.cc.

{
    DybArchiveList* lst = get<DybArchiveList>(arcSvc(),location);
    if (!lst) return std::vector<DataObject*>();
    return std::vector<DataObject*>(lst->begin(),lst->end());
}
int DybBaseAlg::getExecNum ( ) [inline, inherited]

Access current execution ("event") number.

Definition at line 76 of file DybBaseAlg.h.

{ return m_execNum; }
std::string DybBaseAlg::Location ( ) const [inline, inherited]

Access the TES location.

Definition at line 79 of file DybBaseAlg.h.

{ return m_location; }
void DybBaseAlg::InitializeHeader ( DayaBay::HeaderObject header) [protected, inherited]

Initialize new header object. Set exec number, job id, etc.

Definition at line 120 of file DybBaseAlg.cc.

{
  // Set some standard parameters for this header

  // Set execution number
  header->setExecNumber(m_execNum);    
  
  // Document the ID of the job which made this header
  if(!m_jobInfoSvc){
    // Get the job information service
    m_jobInfoSvc = svc<IJobInfoSvc>("JobInfoSvc",true);
  }
  if(m_jobInfoSvc){
    header->setJobId(m_jobInfoSvc->currentJobInfo()->jobId());
  }else{
    warning() << "MakeHeaderObject, failed to get current job ID" << endreq;
  }
  // Set the header time range
  header->setEarliest(TimeStamp::GetBOT());
  header->setLatest(TimeStamp::GetBOT());
}
template<class TYPE >
TYPE * DybBaseAlg::MakeHeader ( ) [protected, inherited]

Definition at line 185 of file DybBaseAlg.h.

{
    TYPE* obj = new TYPE();
    InitializeHeader(obj);
    return obj;
}
template<class TYPE >
TYPE * DybBaseAlg::MakeHeader ( std::vector< const DayaBay::IHeader * > &  inputHeaders) [protected, inherited]

Definition at line 193 of file DybBaseAlg.h.

{
    TYPE* obj = MakeHeader<TYPE>();
    obj->setInputHeaders(inputHeaders);
    size_t size = inputHeaders.size();
    if (size == 0) {
        warning() << "input header has zero size" << endreq;
        return obj; 
    }
    const DayaBay::HeaderObject* firstHeader = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[0]);
    obj->setContext(firstHeader->context());
    obj->setEarliest(firstHeader->earliest());
    if (size > 1) {
        const DayaBay::HeaderObject* lastHeader = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[size-1]);
        obj->setLatest(lastHeader->latest());
    }
    else {
        obj->setLatest(firstHeader->latest());
    }
    
    // make sure the time span covers inputHeaders' range
    for (size_t i=1; i<inputHeaders.size(); i++) {
        const DayaBay::HeaderObject* inputHdr = dynamic_cast<const DayaBay::HeaderObject*>(inputHeaders[i]);
        if (inputHdr->earliest() < obj->earliest()) {
            obj->setEarliest(inputHdr->earliest());
        }
        if (inputHdr->latest() > obj->latest()) {
            obj->setLatest(inputHdr->latest());
        }
    }
    
    return obj;
}
template<class TYPE >
TYPE * DybBaseAlg::MakeHeader ( const DayaBay::IHeader referenceHeader) [protected, inherited]

Definition at line 228 of file DybBaseAlg.h.

{
    std::vector<const DayaBay::IHeader*> inputHeaders = std::vector<const DayaBay::IHeader*>();
    inputHeaders.push_back(referenceHeader);
    TYPE* obj = MakeHeader<TYPE>(inputHeaders);
    return obj;
}
void DybBaseAlg::AppendInputHeader ( const DayaBay::HeaderObject header) const [protected, inherited]

Explicitly add an input header that was retrieved directly instead of through this classes get* methods.

Definition at line 142 of file DybBaseAlg.cc.

{
    m_inputHeaders.push_back(header);
}

Member Data Documentation

Definition at line 108 of file DybBaseAlg.h.

bool DybBaseAlg::m_pullMode [protected, inherited]

runing mode, push or pull

Definition at line 111 of file DybBaseAlg.h.

std::string DybBaseAlg::m_location [protected, inherited]

Property: Location.

Set non-standard TES location for the object this algorithm produces. Default is result of class method HeaderType::defaultLocation().

Definition at line 137 of file DybBaseAlg.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:09:44 for DybAlg by doxygen 1.7.4