Jpp  18.2.1-ARCA-DF-PATCH
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 
9 
10 #include "TObject.h"
11 
12 
13 /**
14  * \author bjung
15  */
16 
17 struct MultiHead :
18  public std::vector<Head>,
19  public TObject
20 {
21  /**
22  * Default constructor.
23  */
25  std::vector<Head>(),
26  TObject()
27  {}
28 
29 
30  /**
31  * Virtual destructor.
32  */
33  virtual ~MultiHead()
34  {}
35 
36 
37  /**
38  * Find header with given UUID.\n
39  * Note: The parameter useCache can be toggled on for faster lookup.\n
40  * This should not be used if your `MultiHead` object is modified between look-ups.
41  *
42  *
43  * \param uuid header UUID
44  * \param useCache use caching for faster look-up
45  * \return header with given UUID
46  */
47  const_iterator find(const uuid_t& uuid,
48  const bool useCache = false) const
49  {
50  using namespace std;
51 
52  static struct Cache
53  {
54  Cache() { uuid_clear(this->uuid); }
55 
56  const_iterator it;
57  uuid_t uuid;
58  } cache;
59 
60  if (!useCache) {
61 
62  for (cache.it = this->cbegin(); cache.it != this->cend(); ++cache.it) {
63 
64  const Head& head = *cache.it;
65  string uuid_str = head.at(Head::tags::UUID);
66 
67  uuid_str.erase(remove_if(uuid_str.begin(), uuid_str.end(), ::isspace), uuid_str.end());
68 
69  uuid_parse(uuid_str.c_str(), cache.uuid);
70 
71  if (uuid_compare(uuid, cache.uuid) == 0) {
72  return cache.it;
73  }
74  }
75 
76  return this->end();
77 
78  } else {
79 
80  if (uuid_compare(uuid, cache.uuid) == 0) {
81  return cache.it;
82  } else {
83  return find(uuid, false);
84  }
85  }
86  }
87 
88 
89  /**
90  * Find the header corresponding to the given event.
91  * Note: The parameter useCache can be toggled on for faster lookup.\n
92  * This should not be used if your `MultiHead` object is modified between look-ups.
93  *
94  * \param event event
95  * \param useCache use caching for faster look-up
96  * \return header corresponding to the given event
97  */
98  const_iterator find(const Evt& event,
99  const bool useCache = false) const
100  {
101  return find(event.header_uuid, useCache);
102  }
103 
104 
105  /**
106  * Insert the given header.
107  *
108  * \param header header
109  * \return true if insertion was successful; else false
110  */
111  bool insert(const Head& header)
112  {
113  using namespace std;
114 
115  string uuid_str = header.at(Head::tags::UUID);
116  uuid_str.erase(remove_if(uuid_str.begin(), uuid_str.end(), ::isspace), uuid_str.end());
117 
118  uuid_t uuid;
119  uuid_parse(uuid_str.c_str(), uuid);
120 
121  if (uuid_is_null(uuid) == 0 && find(uuid) == this->cend()) {
122 
123  this->push_back(header);
124 
125  return true;
126  }
127 
128  return false;
129  }
130 
131 
132  /**
133  * Join given `MultiHead` object with this `MultiHead` object.
134  *
135  * \param multiHead `MultiHead` object
136  * \return number of inserted headers
137  */
138  size_t join(const MultiHead& multiHead)
139  {
140  using namespace std;
141 
142  size_t n = 0;
143 
144  for (const_iterator i = multiHead.cbegin(); i != multiHead.cend(); ++i) {
145  n += (size_t) this->insert(*i);
146  }
147 
148  return n;
149  }
150 
151 
152  /**
153  * Action method at file open.
154  *
155  * \param version version
156  */
157  static void actionAtFileOpen(int version)
158  {
160  }
161 
162 
163  static int ROOT_IO_VERSION; //!< Streamer version as obtained from ROOT file.
164 
165  ClassDef(MultiHead, 1);
166 };
167 
168 #endif
const_iterator find(const Evt &event, const bool useCache=false) const
Find the header corresponding to the given event.
Definition: MultiHead.hh:98
static int ROOT_IO_VERSION
Streamer version as obtained from ROOT file.
Definition: MultiHead.hh:163
static constexpr const char *const UUID
Definition: Head.hh:68
version
Definition: JEditTuneHV.sh:5
size_t join(const MultiHead &multiHead)
Join given MultiHead object with this MultiHead object.
Definition: MultiHead.hh:138
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 int n
Definition: JPolint.hh:786
uuid_t header_uuid
UUID of header containing the event-weight information.
Definition: Evt.hh:35
ClassDef(MultiHead, 1)
bool insert(const Head &header)
Insert the given header.
Definition: MultiHead.hh:111
MultiHead()
Default constructor.
Definition: MultiHead.hh:24
static void actionAtFileOpen(int version)
Action method at file open.
Definition: MultiHead.hh:157
const_iterator find(const uuid_t &uuid, const bool useCache=false) const
Find header with given UUID.
Definition: MultiHead.hh:47
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
virtual ~MultiHead()
Virtual destructor.
Definition: MultiHead.hh:33
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20