Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JHistory.hh
Go to the documentation of this file.
1#ifndef __JRECONSTRUCTION__JHISTORY__
2#define __JRECONSTRUCTION__JHISTORY__
3
4#include <istream>
5#include <ostream>
6#include <iomanip>
7#include <vector>
8#include <algorithm>
9#include <random>
10#include <limits>
11
12#include <TObject.h>
13
15
16#include "JLang/Jpp.hh"
17#include "JLang/JUUID.hh"
18#include "JLang/JPredicate.hh"
20
21
22/**
23 * \author mdejong
24 */
25
26namespace JRECONSTRUCTION {}
27namespace JPP { using namespace JRECONSTRUCTION; }
28
29namespace JFIT {
30
31 using JLANG::JUUID;
32
33 /**
34 * Auxiliary class for historical event.
35 */
36 struct JEvent {
37 /**
38 * Default constructor.
39 */
41 type(-1),
42 uuid()
43 {}
44
45
46 /**
47 * Constructor.
48 *
49 * \param type application type
50 */
51 JEvent(const int type)
52 {
53 using namespace std;
54 using namespace JPP;
55
56 this->type = type;
57 this->git = getGITVersion();
58 this->date = getDateAndTime();
59
60 // UUID
61
62 random_device device;
63
64 uniform_int_distribution<uint32_t> generator(1, numeric_limits<uint32_t>::max());
65
66 uint32_t* value = reinterpret_cast<uint32_t*>(&(this->uuid.uuid));
67
68 for (int i = 0; i != 3; ++i) {
69 value[i] = generator(device);
70 }
71 }
72
73
74 /**
75 * Virtual destructor.
76 */
77 virtual ~JEvent()
78 {}
79
80
81 /**
82 * Make this event unique.
83 *
84 * \return event
85 */
87 {
88 uint32_t* value = reinterpret_cast<uint32_t*>(&(this->uuid.uuid));
89
90 value[3] = ++counter;
91
92 return *this;
93 }
94
95
96 /**
97 * Write event to output stream.
98 *
99 * \param out output stream
100 * \param event event
101 * \return output stream
102 */
103 friend std::ostream& operator<<(std::ostream& out, const JEvent& event)
104 {
105 using namespace std;
106
107 out << setw(3) << right << event.type << ' '
108 << setw(36) << left << event.uuid << ' '
109 << setw(20) << left << event.git << ' '
110 << setw(20) << left << event.date << right;
111
112 return out;
113 }
114
116
117 int type; ///< application type
118 JUUID uuid; ///< UUID
119 std::string git; ///< GIT revision
120 std::string date; ///< date
121 uint32_t counter = 0;//!< internal counter
122 };
123
124
125 /**
126 * Container for historical events.
127 */
128 struct JHistory :
129 public std::vector<JEvent>
130 {
131 /**
132 * Auxiliary class to test history.
133 */
134 struct is_event :
135 public std::vector<int>
136 {
137 /**
138 * Constructor.
139 *
140 * \param history history
141 */
142 is_event(const JHistory& history)
143 {
144 for (JHistory::const_iterator i = history.begin(); i != history.end(); ++i) {
145 this->push_back(i->type);
146 }
147 }
148
149
150 /**
151 * Test history.
152 *
153 * \param history history
154 * \return true if given history same as this history; else false
155 */
156 bool operator()(const JHistory& history) const
157 {
158 return history.getStatus(*this);
159 }
160 };
161
162
163 /**
164 * Auxiliary class to test history.
165 */
167 {
168 /**
169 * Constructor.
170 *
171 * \param type application type
172 */
174 type(type)
175 {}
176
177
178 /**
179 * Test history.
180 *
181 * \param history history
182 * \return true if given history ends with this application type; else false
183 */
184 bool operator()(const JHistory& history) const
185 {
186 return !history.empty() && history.rbegin()->type == this->type;
187 }
188
189 int type;
190 };
191
192
193 /**
194 * Auxiliary class to test history.
195 */
197 /**
198 * Constructor.
199 *
200 * \param type application type
201 */
203 {
204 this->type = type;
205 }
206
207
208 /**
209 * Test history.
210 *
211 * \param history history
212 * \return true if given history does not contain specified event type; else false
213 */
214 bool operator()(const JHistory& history) const
215 {
216 using namespace std;
217 using namespace JPP;
218
219 return count_if(history.begin(), history.end(), make_predicate(&JEvent::type, this->type)) == 0;
220 }
221
222 int type;
223 };
224
225
226 /**
227 * Default constructor.
228 */
230 std::vector<JEvent>()
231 {}
232
233
234 /**
235 * Constructor.
236 *
237 * \param event event
238 */
239 JHistory(const JEvent& event) :
240 std::vector<JEvent>(1, event)
241 {}
242
243
244 /**
245 * Constructor.
246 *
247 * \param type application type
248 */
249 JHistory(const int type) :
250 std::vector<JEvent>(1, JEvent(type))
251 {}
252
253
254 /**
255 * Constructor.
256 *
257 * \param history history
258 * \param event event
259 */
260 JHistory(const JHistory& history,
261 const JEvent& event) :
262 std::vector<JEvent>(history)
263 {
264 push_back(event);
265 }
266
267
268 /**
269 * Virtual destructor.
270 */
271 virtual ~JHistory()
272 {}
273
274
275 /**
276 * Get history.
277 *
278 * \return histtory
279 */
280 const JHistory& getHistory() const
281 {
282 return static_cast<const JHistory&>(*this);
283 }
284
285
286 /**
287 * Get history.
288 *
289 * \return histtory
290 */
292 {
293 return static_cast<JHistory&>(*this);
294 }
295
296
297 /**
298 * Has event in history.
299 *
300 * \param type application type
301 * \return true if given event in history; else false
302 */
303 bool has(const int type) const
304 {
305 for (const_iterator i = this->begin(); i != this->end(); ++i) {
306 if (i->type == type) {
307 return true;
308 }
309 }
310
311 return false;
312 }
313
314
315 /**
316 * Get status.
317 *
318 * \param types application types
319 * \return true if history matches appplication types; else false
320 */
321 bool getStatus(const std::vector<int>& types) const
322 {
323 if (this->size() == types.size()) {
324
325 for (size_t i = 0; i != this->size(); ++i) {
326 if ((*this)[i].type != types[i]) {
327 return false;
328 }
329 }
330
331 return true;
332
333 } else {
334
335 return false;
336 }
337 }
338
339
340 /**
341 * Add event to history.
342 *
343 * \param type application type
344 * \return this history
345 */
346 JHistory& add(const int type)
347 {
348 push_back(JEvent(type));
349
350 return *this;
351 }
352
353
354 /**
355 * Has parent UUID.
356 */
357 bool hasParentUUID() const
358 {
359 return this->size() >= 2u;
360 }
361
362
363 /**
364 * Get UUID.
365 */
366 const JUUID& getUUID() const
367 {
368 return this->at(this->size() - 1).uuid;
369 }
370
371
372 /**
373 * Get parent UUID.
374 */
375 const JUUID& getParentUUID() const
376 {
377 return this->at(this->size() - 2).uuid;
378 }
379
380
381 /**
382 * Write history to output stream.
383 *
384 * \param out output stream
385 * \param history history
386 * \return output stream
387 */
388 friend std::ostream& operator<<(std::ostream& out, const JHistory& history)
389 {
390 using namespace std;
391
392 for (const_iterator i = history.begin(); i != history.end(); ++i) {
393 out << *i << endl;
394 }
395
396 return out;
397 }
398
400 };
401}
402
403namespace JRECONSTRUCTION {
406}
407
408#endif
Date and time functions.
Jpp environment information.
Auxiliary classes and methods for linear and iterative data regression.
Definition JEnergy.hh:15
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Model fits to data.
JFIT::JHistory JHistory
Definition JHistory.hh:405
JFIT::JEvent JEvent
Definition JHistory.hh:404
Description of Monte Carlo event generation applications.
Definition JHead.hh:469
Auxiliary class for historical event.
Definition JHistory.hh:36
virtual ~JEvent()
Virtual destructor.
Definition JHistory.hh:77
JEvent(const int type)
Constructor.
Definition JHistory.hh:51
uint32_t counter
internal counter
Definition JHistory.hh:121
int type
application type
Definition JHistory.hh:117
JEvent()
Default constructor.
Definition JHistory.hh:40
ClassDef(JEvent, 2)
friend std::ostream & operator<<(std::ostream &out, const JEvent &event)
Write event to output stream.
Definition JHistory.hh:103
JUUID uuid
UUID.
Definition JHistory.hh:118
std::string date
date
Definition JHistory.hh:120
const JEvent & operator()()
Make this event unique.
Definition JHistory.hh:86
std::string git
GIT revision.
Definition JHistory.hh:119
Auxiliary class to test history.
Definition JHistory.hh:167
is_application(int type)
Constructor.
Definition JHistory.hh:173
bool operator()(const JHistory &history) const
Test history.
Definition JHistory.hh:184
Auxiliary class to test history.
Definition JHistory.hh:136
bool operator()(const JHistory &history) const
Test history.
Definition JHistory.hh:156
is_event(const JHistory &history)
Constructor.
Definition JHistory.hh:142
Auxiliary class to test history.
Definition JHistory.hh:196
bool operator()(const JHistory &history) const
Test history.
Definition JHistory.hh:214
is_not_event(int type)
Constructor.
Definition JHistory.hh:202
Container for historical events.
Definition JHistory.hh:130
JHistory(const JEvent &event)
Constructor.
Definition JHistory.hh:239
const JUUID & getUUID() const
Get UUID.
Definition JHistory.hh:366
bool getStatus(const std::vector< int > &types) const
Get status.
Definition JHistory.hh:321
bool hasParentUUID() const
Has parent UUID.
Definition JHistory.hh:357
JHistory()
Default constructor.
Definition JHistory.hh:229
const JUUID & getParentUUID() const
Get parent UUID.
Definition JHistory.hh:375
const JHistory & getHistory() const
Get history.
Definition JHistory.hh:280
ClassDef(JHistory, 2)
JHistory & getHistory()
Get history.
Definition JHistory.hh:291
JHistory(const int type)
Constructor.
Definition JHistory.hh:249
JHistory(const JHistory &history, const JEvent &event)
Constructor.
Definition JHistory.hh:260
virtual ~JHistory()
Virtual destructor.
Definition JHistory.hh:271
friend std::ostream & operator<<(std::ostream &out, const JHistory &history)
Write history to output stream.
Definition JHistory.hh:388
JHistory & add(const int type)
Add event to history.
Definition JHistory.hh:346
bool has(const int type) const
Has event in history.
Definition JHistory.hh:303
Simple wrapper for UUID.
Definition JUUID.hh:24
uuid_t uuid
Definition JUUID.hh:172