Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MultiHead.hh
Go to the documentation of this file.
1 #ifndef MULTIHEAD_HH_INCLUDED
2 #define MULTIHEAD_HH_INCLUDED
3 
4 #include <vector>
5 #include <uuid/uuid.h>
6 
10 
11 #include "TObject.h"
12 
13 
14 /**
15  * \author bjung
16  */
17 
18 struct MultiHead :
19  public std::vector<Head>,
20  public TObject
21 {
22  /**
23  * Default constructor.
24  */
26  std::vector<Head>(),
27  TObject()
28  {}
29 
30 
31  /**
32  * Virtual destructor.
33  */
34  virtual ~MultiHead()
35  {}
36 
37 
38  /**
39  * Find header with given UUID.\n
40  * Note: The parameter useCache can be toggled on for faster lookup.\n
41  * This should not be used if your `MultiHead` object is modified between look-ups.
42  *
43  *
44  * \param uuid header UUID
45  * \param useCache use caching for faster look-up
46  * \return header with given UUID
47  */
48  const Head& find(const uuid_t& uuid,
49  const bool useCache = false) const
50  {
51  using namespace std;
52 
53  static struct
54  {
55  size_t index;
56  uuid_t uuid;
57  } cache;
58 
59  if (!useCache) {
60 
61  for (cache.index = 0; cache.index < this->size(); ++cache.index) {
62 
63  const Head& head = (*this)[cache.index];
64  const string& uuid_str = head.at(Head::tags::UUID);
65 
66  uuid_parse(uuid_str.c_str(), cache.uuid);
67 
68  if (uuid_compare(uuid, cache.uuid)) {
69  return head;
70  }
71  }
72 
73  THROW(Exception, "MultiHead::find(const uuid_t&, const bool): Could not find header with UUID " << uuid);
74 
75  } else {
76 
77  if (uuid_compare(uuid, cache.uuid)) {
78  return this->at(cache.index);
79  } else {
80  return find(uuid, false);
81  }
82  }
83  }
84 
85 
86  /**
87  * Find the header corresponding to the given event.
88  * Note: The parameter useCache can be toggled on for faster lookup.\n
89  * This should not be used if your `MultiHead` object is modified between look-ups.
90  *
91  * \param event event
92  * \param useCache use caching for faster look-up
93  * \return header corresponding to the given event
94  */
95  const Head& find(const Evt& event,
96  const bool useCache = false) const
97  {
98  return find(event.header_uuid, useCache);
99  }
100 
101 
102  /**
103  * Action method at file open.
104  *
105  * \param version version
106  */
107  static void actionAtFileOpen(int version)
108  {
110  }
111 
112  static int ROOT_IO_VERSION; //!< Streamer version as obtained from ROOT file.
113 
114  ClassDef(MultiHead, 1);
115 };
116 
117 #endif
static int ROOT_IO_VERSION
Streamer version as obtained from ROOT file.
Definition: MultiHead.hh:112
static constexpr const char *const UUID
Definition: Head.hh:68
version
Definition: JEditTuneHV.sh:5
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
Definition: JRoot.hh:19
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
const Head & find(const Evt &event, const bool useCache=false) const
Find the header corresponding to the given event.
Definition: MultiHead.hh:95
uuid_t header_uuid
UUID of header containing the event-weight information.
Definition: Evt.hh:35
ClassDef(MultiHead, 1)
MultiHead()
Default constructor.
Definition: MultiHead.hh:25
static void actionAtFileOpen(int version)
Action method at file open.
Definition: MultiHead.hh:107
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
General exception.
Definition: Exception.hh:13
const Head & find(const uuid_t &uuid, const bool useCache=false) const
Find header with given UUID.
Definition: MultiHead.hh:48
virtual ~MultiHead()
Virtual destructor.
Definition: MultiHead.hh:34
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20