/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 | Private Attributes
DybBaseAlg Class Reference

Support for everything in DybAlgorithm not relying on knowing the HeaderObject type. More...

#include <DybBaseAlg.h>

Inheritance diagram for DybBaseAlg:
Inheritance graph
[legend]
Collaboration diagram for DybBaseAlg:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DybBaseAlg (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~DybBaseAlg ()
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

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.

Private Attributes

int m_execNum
 Property: ExecutionNumber.
int m_saveRandomState
 Property: SaveRandomState.
std::vector< const
DayaBay::HeaderObject * > 
m_inputHeaders
std::vector< unsigned long > m_state
 state of Random Engine
IJobInfoSvcm_jobInfoSvc
 handle to JobInfoSvc

Detailed Description

Support for everything in DybAlgorithm not relying on knowing the HeaderObject type.

Brett Viren <bv@bnl.gov> Thu Mar 24 12:58:11 2011

Definition at line 24 of file DybBaseAlg.h.


Constructor & Destructor Documentation

DybBaseAlg::DybBaseAlg ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

in simple, linear algorithm chain, it is always "push" only when using Fifteen package, is it "pull"

Definition at line 11 of file DybBaseAlg.cc.

    : GaudiAlgorithm(name,pSvcLocator)
    , m_headerObject(0)
    , m_jobInfoSvc(0)
{
    declareProperty("ExecutionNumber",m_execNum = 1,
                    "The starting execution number.");
    declareProperty("SaveRandomState",m_saveRandomState = false,
                    "Set true/false to save the random state.");

    m_pullMode=false;  

}
DybBaseAlg::~DybBaseAlg ( ) [virtual]

Definition at line 25 of file DybBaseAlg.cc.

{
}

Member Function Documentation

StatusCode DybBaseAlg::sysInitialize ( ) [virtual]

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]

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]

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]

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]

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

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

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

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

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

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]

Access current execution ("event") number.

Definition at line 76 of file DybBaseAlg.h.

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

Access the TES location.

Definition at line 79 of file DybBaseAlg.h.

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

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]

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]

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]

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]

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]

runing mode, push or pull

Definition at line 111 of file DybBaseAlg.h.

int DybBaseAlg::m_execNum [private]

Property: ExecutionNumber.

Set the starting execution number (like a generic event number). Starts at 1 (yes, 1, not 0) by default. This is incremented in the MakeHeader()

Definition at line 118 of file DybBaseAlg.h.

Property: SaveRandomState.

Set true/false to save / not save the random state into the header object. Set to FALSE by default.

Definition at line 123 of file DybBaseAlg.h.

std::vector<const DayaBay::HeaderObject*> DybBaseAlg::m_inputHeaders [mutable, private]

Definition at line 125 of file DybBaseAlg.h.

std::vector<unsigned long> DybBaseAlg::m_state [private]

state of Random Engine

Definition at line 128 of file DybBaseAlg.h.

handle to JobInfoSvc

Definition at line 130 of file DybBaseAlg.h.

std::string DybBaseAlg::m_location [protected]

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