Jpp  18.0.1-rc.2
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
53  {
54  const_iterator it;
55  uuid_t uuid;
56  } cache;
57 
58  if (!useCache) {
59 
60  for (cache.it = this->cbegin(); cache.it != this->cend(); ++cache.it) {
61 
62  const Head& head = *cache.it;
63  const string& uuid_str = head.at(Head::tags::UUID);
64 
65  uuid_parse(uuid_str.c_str(), cache.uuid);
66 
67  if (uuid_compare(uuid, cache.uuid)) {
68  return cache.it;
69  }
70  }
71 
72  return this->end();
73 
74  } else {
75 
76  if (uuid_compare(uuid, cache.uuid)) {
77  return cache.it;
78  } else {
79  return find(uuid, false);
80  }
81  }
82  }
83 
84 
85  /**
86  * Find the header corresponding to the given event.
87  * Note: The parameter useCache can be toggled on for faster lookup.\n
88  * This should not be used if your `MultiHead` object is modified between look-ups.
89  *
90  * \param event event
91  * \param useCache use caching for faster look-up
92  * \return header corresponding to the given event
93  */
94  const_iterator find(const Evt& event,
95  const bool useCache = false) const
96  {
97  return find(event.header_uuid, useCache);
98  }
99 
100 
101  /**
102  * Join given `MultiHead` object with this `MultiHead` object.
103  *
104  * \param multiHead `MultiHead` object
105  */
106  void join(const MultiHead& multiHead)
107  {
108  using namespace std;
109 
110  for (vector<Head>::const_iterator i = multiHead.cbegin(); i != multiHead.cend(); ++i) {
111 
112  uuid_t uuid;
113 
114  const string& uuid_str = i->at(Head::tags::UUID);
115 
116  uuid_parse(uuid_str.c_str(), uuid);
117 
118  vector<Head>::const_iterator j = this->find(uuid);
119 
120  if (j == this->cend()) { this->push_back(*i); }
121  }
122  }
123 
124 
125  /**
126  * Action method at file open.
127  *
128  * \param version version
129  */
130  static void actionAtFileOpen(int version)
131  {
133  }
134 
135 
136  static int ROOT_IO_VERSION; //!< Streamer version as obtained from ROOT file.
137 
138  ClassDef(MultiHead, 1);
139 };
140 
141 #endif
const_iterator find(const Evt &event, const bool useCache=false) const
Find the header corresponding to the given event.
Definition: MultiHead.hh:94
static int ROOT_IO_VERSION
Streamer version as obtained from ROOT file.
Definition: MultiHead.hh:136
static constexpr const char *const UUID
Definition: Head.hh:68
version
Definition: JEditTuneHV.sh:5
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
void join(const MultiHead &multiHead)
Join given MultiHead object with this MultiHead object.
Definition: MultiHead.hh:106
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:24
static void actionAtFileOpen(int version)
Action method at file open.
Definition: MultiHead.hh:130
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
int j
Definition: JPolint.hh:703
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