#ifndef MULTIHEAD_HH_INCLUDED #define MULTIHEAD_HH_INCLUDED #include #include #include "km3net-dataformat/offline/Evt.hh" #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/Exception.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 Head& find(const uuid_t& uuid, const bool useCache = false) const { using namespace std; static struct { size_t index; uuid_t uuid; } cache; if (!useCache) { for (cache.index = 0; cache.index < this->size(); ++cache.index) { const Head& head = (*this)[cache.index]; const string& uuid_str = head.at(Head::tags::UUID); uuid_parse(uuid_str.c_str(), cache.uuid); if (uuid_compare(uuid, cache.uuid)) { return head; } } THROW(Exception, "MultiHead::find(const uuid_t&, const bool): Could not find header with UUID " << uuid); } else { if (uuid_compare(uuid, cache.uuid)) { return this->at(cache.index); } 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 Head& find(const Evt& event, const bool useCache = false) const { return find(event.header_uuid, useCache); } ClassDef(MultiHead, 1); }; #endif