FAQ:How to write a Header Object to TES

From Daya Bay

Jump to: navigation, search

To write a Header Object to TES in your own algorithm, one need to create it, set its context, jobid, earliest, latest, inputHeaders and put it into a TES location. This is commonly needed when one wants to create Tags, or UserData object. Here is an example take from http://dayabay.ihep.ac.cn/tracs/dybsvn/browser/dybgaudi/trunk/Tagging/ADCoincTagging/src/components/ADCoincTagging.cc?rev=14390

int execNumber = recHeader->execNumber();
Context context = dynamic_cast<const HeaderObject*>(inputHeaders.at(0))->context();
TimeStamp earliest = dynamic_cast<const HeaderObject*>(inputHeaders.at(0))->earliest();
TimeStamp latest = dynamic_cast<const HeaderObject*>(inputHeaders.at(inputHeaders.size()-1))->latest();
JobId jobid = m_jobInfoSvc->currentJobInfo()->jobId();

// save a redundant header object into the tag location
HeaderObject *tag = new HeaderObject();
tag->setInputHeaders(inputHeaders);
tag->setExecNumber(execNumber);
tag->setContext(context);
tag->setEarliest(earliest);
tag->setLatest(latest);
tag->setJobId(jobid);
put(tag, m_tagLocation);

This is a lot of work and is prone to mistakes. Since r14641 helper methods are added to the DybBaseAlg so that it's much easier (and cleaner) to make your own header objects. Below is the same algorithm but now uses the helper methods:

// save a (redundant) tag header object into the tag location               
HeaderObject *tag = MakeHeader<HeaderObject>(inputHeaders);               
put(tag, m_tagLocation);

In order to be able to use the MakeHeader() methods, you need to inherit your own algorithm from DybBaseAlg, instead of from GaudiAlgorithm. There are three overloaded MakeHeader() methods and one can use either that is more appropriate to your algorithms. These are defined in http://dayabay.ihep.ac.cn/tracs/dybsvn/browser/dybgaudi/trunk/DybAlg/DybAlg/DybBaseAlg.h

// wrapper of header object constructor, but intializes the header object.
// - MakeHeader()
//       : default initializtion, exec number, job id, E/L time set to BOT
// - MakeHeader(inputHeaders)
//       : set the inputHeaders and set E/L time to cover the time range of the inputHeaders
//       : also set the default context to be the same as the first inputHeader
// - MakeHeader(referenceHeader)
//       : set the inputHeaders to be a size 1 vector containing the ref Header
//       : and set everything to be the same as this single ref Header.
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);

By default the context of the created header object is set to be the same as the first element of the inputHeaders of this header object. This may or may not be appropriate. An example is that a muon tag may want to set the detector id to kAll. You should feel free to manually set the context to the appropriate value with the old setContext() method.

Personal tools