Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JAANET::JMultiHead Struct Reference

Auxiliary data structure to store multiple headers
and bookkeep event-weight normalisations. More...

#include <JMultiHead.hh>

Inheritance diagram for JAANET::JMultiHead:
MultiHead std::vector< Head > TObject

Public Types

typedef std::map< JUUID, JAANET::JEvtWeightNormalisationmap_type
 

Public Member Functions

 JMultiHead ()
 Default constructor.
 
void merge (const JHead &header)
 Merge the given header into this object.
 
bool insert (const JHead &header)
 Insert the given header.
 
bool isMerged (const JUUID &UUID) const
 Check if given header UUID correspond to a file which has been merged.
 
JUUID getHeaderUUID (const Evt &event) const
 Get the header UUID corresponding to the given event.
 
double getNormalisation (const JUUID &UUID) const
 Get normalisation for given header UUID.
 
double getNormalisation (const Evt &event) const
 Get normalisation for given event.
 
void merge ()
 Merge all matching headers.
 
const_iterator find (const uuid_t &uuid, const bool useCache=false) const
 Find header with given UUID.
 
const_iterator find (const Evt &event, const bool useCache=false) const
 Find the header corresponding to the given event.
 
bool insert (const Head &header)
 Insert the given header.
 
size_t join (const MultiHead &multiHead)
 Join given MultiHead object with this MultiHead object.
 
 ClassDef (MultiHead, 1)
 

Static Public Member Functions

static void actionAtFileOpen (int version)
 Action method at file open.
 

Public Attributes

map_type normalisationMap
 Map between header UUIDs and event-weight normalisations.
 

Static Public Attributes

static int ROOT_IO_VERSION = -1
 Streamer version as obtained from ROOT file.
 

Detailed Description

Auxiliary data structure to store multiple headers
and bookkeep event-weight normalisations.

Definition at line 37 of file JMultiHead.hh.

Member Typedef Documentation

◆ map_type

Constructor & Destructor Documentation

◆ JMultiHead()

JAANET::JMultiHead::JMultiHead ( )
inline

Default constructor.

Definition at line 46 of file JMultiHead.hh.

46 :
47 MultiHead()
48 {}
MultiHead()
Default constructor.
Definition MultiHead.hh:24

Member Function Documentation

◆ merge() [1/2]

void JAANET::JMultiHead::merge ( const JHead & header)
inline

Merge the given header into this object.

Parameters
headerheader

Definition at line 56 of file JMultiHead.hh.

57 {
58 insert(header);
59 merge();
60 }
bool insert(const JHead &header)
Insert the given header.
Definition JMultiHead.hh:69
void merge()
Merge all matching headers.

◆ insert() [1/2]

bool JAANET::JMultiHead::insert ( const JHead & header)
inline

Insert the given header.

Parameters
headerheader
Returns
true if insertion was successful; else false

Definition at line 69 of file JMultiHead.hh.

70 {
71 using namespace std;
72
73 Head head;
74 JAANET::copy(header, head);
75
76 uuid_t uuid;
77 uuid_clear(uuid);
78
79 Head::iterator i = head.find(Head::tags::UUID);
80
81 if (i != head.end()) {
82 uuid_parse(i->second.c_str(), uuid);
83 }
84
85 if (uuid_is_null(uuid) != 0) {
86 uuid_generate_random(uuid); // Ensure valid UUID
87 }
88
89 char buffer[JUUID::BUFFER_SIZE + 1];
90 uuid_unparse_lower(uuid, buffer);
91
92 head.insert(make_pair(Head::tags::UUID, buffer));
93
94 return MultiHead::insert(head);
95 }
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
static constexpr const char *const UUID
Definition Head.hh:67
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
static const int BUFFER_SIZE
number of characters for I/O of uuid_t without trailing '\0', see e.g. man uuid_parse
Definition JUUID.hh:26
bool insert(const Head &header)
Insert the given header.
Definition MultiHead.hh:111

◆ isMerged()

bool JAANET::JMultiHead::isMerged ( const JUUID & UUID) const
inline

Check if given header UUID correspond to a file which has been merged.

Parameters
UUIDheader UUID
Returns
true if given header UUID correspond to file which has been merged

Definition at line 104 of file JMultiHead.hh.

105 {
106 using namespace JPP;
107
108 map_type::const_iterator i = normalisationMap.find(UUID);
109
110 if (i != normalisationMap.end()) {
111 return i->first != i->second.UUID;
112 } else {
113 THROW(JValueOutOfRange, "JMultiHead::isMerged(): Given header UUID " << UUID << " not found.");
114 }
115 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for accessing a value in a collection that is outside of its range.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
map_type normalisationMap
Map between header UUIDs and event-weight normalisations.

◆ getHeaderUUID()

JUUID JAANET::JMultiHead::getHeaderUUID ( const Evt & event) const
inline

Get the header UUID corresponding to the given event.

Parameters
eventevent
Returns
header UUID

Definition at line 124 of file JMultiHead.hh.

125 {
126 using namespace JPP;
127
128 const JUUID UUID = event.header_uuid;
129
130 map_type::const_iterator i = normalisationMap.find(UUID);
131
132 if (i != normalisationMap.cend()) {
133 return i->second.UUID;
134 } else {
135 THROW(JValueOutOfRange, "JMultiHead::getHeaderUUID(): Header UUID " << UUID << " for given event not found.");
136 }
137 }
Simple wrapper for UUID.
Definition JUUID.hh:24

◆ getNormalisation() [1/2]

double JAANET::JMultiHead::getNormalisation ( const JUUID & UUID) const
inline

Get normalisation for given header UUID.

Parameters
UUIDheader UUID
Returns
event-weight normalisation factor

Definition at line 146 of file JMultiHead.hh.

147 {
148 using namespace JPP;
149
150 map_type::const_iterator i = normalisationMap.find(UUID);
151
152 if (i != normalisationMap.end()) {
153 return i->second.normalisation;
154 } else {
155 THROW(JValueOutOfRange, "JMultiHead::getNormalisation(): Given header UUID " << UUID << " not found.");
156 }
157 }

◆ getNormalisation() [2/2]

double JAANET::JMultiHead::getNormalisation ( const Evt & event) const
inline

Get normalisation for given event.

Parameters
eventevent
Returns
event-weight normalisation factor

Definition at line 166 of file JMultiHead.hh.

167 {
168 return getNormalisation(event.header_uuid);
169 }
uuid_t header_uuid
UUID of header containing the event-weight information.
Definition Evt.hh:35
double getNormalisation(const JUUID &UUID) const
Get normalisation for given header UUID.

◆ merge() [2/2]

void JAANET::JMultiHead::merge ( )
inline

Merge all matching headers.

Definition at line 175 of file JMultiHead.hh.

176 {
177 using namespace std;
178 using namespace JPP;
179
180 const MultiHead copy = static_cast<const MultiHead&>(*this);
181 this->clear();
182
183 for (const_iterator i = copy.cbegin(); i != copy.cend(); ++i) {
184
185 JHead header1 = *i;
186 header1.createUUID(); // Ensure header UUID is set
187
188 const JUUID UUID = header1.UUID; // Initial header UUID
189
190 // Merge matching headers following this header in the container
191
192 vector<JUUID> mergedHeaders; // Track all headers involved in mergers
193
194 for (const_iterator j = next(i); j != copy.end(); ++j) {
195
196 const JHead header2 = *j;
197
198 if (header1.match(header2)) {
199
200 header1.add(header2);
201 mergedHeaders.push_back(header2.UUID);
202 }
203 }
204
205 // Retrieve event-weight normalisation for merged header
206
207 const JEvtWeight& weighter = getEventWeighter(header1);
208
209 JEvtWeightHelper helper(weighter);
210 helper.add(header1);
211
212 const double norm = helper->getNormalisation();
213
214 // Set event-weight normalisations for headers involved in mergers
215
216 for (vector<JUUID>::const_iterator j = mergedHeaders.cbegin(); j != mergedHeaders.cend(); ++j) {
218 }
219
220 // Set event-weight normalisation for original header
221
222 normalisationMap[UUID] = JEvtWeightNormalisation(header1.UUID, norm);
223
224 insert(header1); // Add merged header to buffer
225 }
226 }
Monte Carlo run header.
Definition JHead.hh:1236
JHead & add(const JHead &header)
Addition of headers.
Definition JHead.hh:1532
void createUUID()
Create UUID if not already set.
Definition JHead.hh:1301
bool match(const JHead &header) const
Test match of headers.
Definition JHead.hh:1474
JEvtWeighter getEventWeighter
Function object for mapping header to event weighter.
int j
Definition JPolint.hh:801
Helper class for event weighing.
Auxiliary data structure for storing pairs of header UUIDs and event-weight normalisations.

◆ find() [1/2]

const_iterator MultiHead::find ( const uuid_t & uuid,
const bool useCache = false ) const
inlineinherited

Find header with given UUID.


Note: The parameter useCache can be toggled on for faster lookup.
This should not be used if your MultiHead object is modified between look-ups.

Parameters
uuidheader UUID
useCacheuse caching for faster look-up
Returns
header with given UUID

Definition at line 47 of file MultiHead.hh.

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 }
const_iterator find(const uuid_t &uuid, const bool useCache=false) const
Find header with given UUID.
Definition MultiHead.hh:47

◆ find() [2/2]

const_iterator MultiHead::find ( const Evt & event,
const bool useCache = false ) const
inlineinherited

Find the header corresponding to the given event.

Note: The parameter useCache can be toggled on for faster lookup.
This should not be used if your MultiHead object is modified between look-ups.

Parameters
eventevent
useCacheuse caching for faster look-up
Returns
header corresponding to the given event

Definition at line 98 of file MultiHead.hh.

100 {
101 return find(event.header_uuid, useCache);
102 }

◆ insert() [2/2]

bool MultiHead::insert ( const Head & header)
inlineinherited

Insert the given header.

Parameters
headerheader
Returns
true if insertion was successful; else false

Definition at line 111 of file MultiHead.hh.

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 }

◆ join()

size_t MultiHead::join ( const MultiHead & multiHead)
inlineinherited

Join given MultiHead object with this MultiHead object.

Parameters
multiHeadMultiHead object
Returns
number of inserted headers

Definition at line 138 of file MultiHead.hh.

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 }
const int n
Definition JPolint.hh:791

◆ actionAtFileOpen()

static void MultiHead::actionAtFileOpen ( int version)
inlinestaticinherited

Action method at file open.

Parameters
versionversion

Definition at line 157 of file MultiHead.hh.

158 {
159 ROOT_IO_VERSION = version;
160 }
static int ROOT_IO_VERSION
Streamer version as obtained from ROOT file.
Definition MultiHead.hh:163

◆ ClassDef()

MultiHead::ClassDef ( MultiHead ,
1  )
inherited

Member Data Documentation

◆ normalisationMap

map_type JAANET::JMultiHead::normalisationMap

Map between header UUIDs and event-weight normalisations.

Definition at line 229 of file JMultiHead.hh.

◆ ROOT_IO_VERSION

int MultiHead::ROOT_IO_VERSION = -1
staticinherited

Streamer version as obtained from ROOT file.

Definition at line 163 of file MultiHead.hh.


The documentation for this struct was generated from the following file: