#ifndef MULTIHEAD_HH_INCLUDED #define MULTIHEAD_HH_INCLUDED #include #include #include "km3net-dataformat/offline/Evt.hh" #include "km3net-dataformat/offline/Head.hh" #include "TObject.h" /** * \author bjung */ struct MultiHead : public std::vector, public TObject { /** * Default constructor. */ MultiHead() : std::vector(), TObject() {} /** * Virtual destructor. */ virtual ~MultiHead() {} /** * Find header with given UUID.\n * Note: The parameter useCache can be toggled on for faster lookup.\n * This should not be used if your `MultiHead` object is modified between look-ups. * * * \param uuid header UUID * \param useCache use caching for faster look-up * \return header with given UUID */ const_iterator find(const uuid_t& uuid, const bool useCache = false) const { using namespace std; static struct { const_iterator it; uuid_t uuid; } cache; if (!useCache) { for (cache.it = this->cbegin(); cache.it != this->cend(); ++cache.it) { const Head& head = *cache.it; const string& uuid_str = head.at(Head::tags::UUID); uuid_parse(uuid_str.c_str(), cache.uuid); if (uuid_compare(uuid, cache.uuid)) { return cache.it; } } return this->end(); } else { if (uuid_compare(uuid, cache.uuid)) { return cache.it; } else { return find(uuid, false); } } } /** * Find the header corresponding to the given event. * Note: The parameter useCache can be toggled on for faster lookup.\n * This should not be used if your `MultiHead` object is modified between look-ups. * * \param event event * \param useCache use caching for faster look-up * \return header corresponding to the given event */ const_iterator find(const Evt& event, const bool useCache = false) const { return find(event.header_uuid, useCache); } /** * Join given `MultiHead` object with this `MultiHead` object. * * \param multiHead `MultiHead` object */ void join(const MultiHead& multiHead) { using namespace std; for (vector::const_iterator i = multiHead.cbegin(); i != multiHead.cend(); ++i) { uuid_t uuid; const string& uuid_str = i->at(Head::tags::UUID); uuid_parse(uuid_str.c_str(), uuid); vector::const_iterator j = this->find(uuid); if (j == this->cend()) { this->push_back(*i); } } } /** * Action method at file open. * * \param version version */ static void actionAtFileOpen(int version) { ROOT_IO_VERSION = version; } static int ROOT_IO_VERSION; //!< Streamer version as obtained from ROOT file. ClassDef(MultiHead, 1); }; #endif