Jpp master_rocky-44-g75b7c4f75
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
10#include <TROOT.h>
11#include <TObject.h>
12
14
15#include "JROOT/JRoot.hh"
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 * Constructor.
47 *
48 * \param type application type
49 */
50 JEvent(const int type)
51 {
52 using namespace JPP;
53
54 this->type = type;
55 this->uuid = JUUID::rndm();
56 this->git = getGITVersion();
57 this->date = getDateAndTime();
58 }
59
60
61 /**
62 * Virtual destructor.
63 */
64 virtual ~JEvent()
65 {}
66
67
68 /**
69 * Write event to output stream.
70 *
71 * \param out output stream
72 * \param event event
73 * \return output stream
74 */
75 friend std::ostream& operator<<(std::ostream& out, const JEvent& event)
76 {
77 using namespace std;
78
79 out << setw(3) << right << event.type << ' '
80 << setw(36) << left << event.uuid << ' '
81 << setw(20) << left << event.git << ' '
82 << setw(20) << left << event.date << right;
83
84 return out;
85 }
86
88
89 int type; ///< application type
90 JUUID uuid; ///< UUID
91 std::string git; ///< GIT revision
92 std::string date; ///< date
93 };
94
95
96 /**
97 * Container for historical events.
98 */
99 struct JHistory :
100 public std::vector<JEvent>
101 {
102 /**
103 * Auxiliary class to test history.
104 */
105 struct is_event {
106 /**
107 * Constructor.
108 *
109 * \param type application type
110 */
112 {
113 this->type = type;
114 }
115
116
117 /**
118 * Constructor.
119 *
120 * \param history history
121 */
122 is_event(const JHistory& history)
123 {
124 if (!history.empty())
125 this->type = history.rbegin()->type;
126 else
127 this->type = -1;
128 }
129
130
131 /**
132 * Test history.
133 *
134 * \param history history
135 * \return true if given history ends with specified event type; else false
136 */
137 bool operator()(const JHistory& history) const
138 {
139 if (!history.empty()) {
140 return history.rbegin()->type == this->type;
141 }
142
143 return false;
144 }
145
146 int type;
147 };
148
149
150 /**
151 * Auxiliary class to test history.
152 */
154 /**
155 * Constructor.
156 *
157 * \param type application type
158 */
160 {
161 this->type = type;
162 }
163
164
165 /**
166 * Test history.
167 *
168 * \param history history
169 * \return true if given history does not contain specified event type; else false
170 */
171 bool operator()(const JHistory& history) const
172 {
173 using namespace std;
174 using namespace JPP;
175
176 return count_if(history.begin(), history.end(), make_predicate(&JEvent::type, this->type)) == 0;
177 }
178
179 int type;
180 };
181
182
183 /**
184 * Default constructor.
185 */
187 std::vector<JEvent>()
188 {}
189
190
191 /**
192 * Constructor.
193 *
194 * \param type application type
195 */
196 JHistory(const int type) :
197 std::vector<JEvent>()
198 {
199 add(type);
200 }
201
202
203 /**
204 * Constructor.
205 *
206 * \param history history
207 * \param type application type
208 */
209 JHistory(const JHistory& history,
210 const int type) :
211 std::vector<JEvent>(history)
212 {
213 add(type);
214 }
215
216
217 /**
218 * Virtual destructor.
219 */
220 virtual ~JHistory()
221 {}
222
223
224 /**
225 * Get history.
226 *
227 * \return histtory
228 */
229 const JHistory& getHistory() const
230 {
231 return static_cast<const JHistory&>(*this);
232 }
233
234
235 /**
236 * Get history.
237 *
238 * \return histtory
239 */
241 {
242 return static_cast<JHistory&>(*this);
243 }
244
245
246 /**
247 * Has event in history.
248 *
249 * \param type application type
250 * \return true if given event in history; else false
251 */
252 bool has(const int type) const
253 {
254 for (const_iterator i = this->begin(); i != this->end(); ++i) {
255 if (i->type == type) {
256 return true;
257 }
258 }
259
260 return false;
261 }
262
263
264 /**
265 * Get status.
266 *
267 * \param types application types
268 * \return true if history matches appplication types; else false
269 */
270 bool getStatus(const std::vector<int>& types) const
271 {
272 if (this->size() == types.size()) {
273
274 for (size_t i = 0; i != this->size(); ++i) {
275 if ((*this)[i].type != types[i]) {
276 return false;
277 }
278 }
279
280 return true;
281
282 } else {
283
284 return false;
285 }
286 }
287
288
289 /**
290 * Add event to history.
291 *
292 * \param type application type
293 * \return this history
294 */
295 JHistory& add(const int type)
296 {
297 push_back(JEvent(type));
298
299 return *this;
300 }
301
302
303 /**
304 * Has parent UUID.
305 */
306 bool hasParentUUID() const
307 {
308 return this->size() >= 2u;
309 }
310
311
312 /**
313 * Get UUID.
314 */
315 const JUUID& getUUID() const
316 {
317 return this->at(this->size() - 1).uuid;
318 }
319
320
321 /**
322 * Get parent UUID.
323 */
324 const JUUID& getParentUUID() const
325 {
326 return this->at(this->size() - 2).uuid;
327 }
328
329
330 /**
331 * Write history to output stream.
332 *
333 * \param out output stream
334 * \param history history
335 * \return output stream
336 */
337 friend std::ostream& operator<<(std::ostream& out, const JHistory& history)
338 {
339 using namespace std;
340
341 for (const_iterator i = history.begin(); i != history.end(); ++i) {
342 out << *i << endl;
343 }
344
345 return out;
346 }
347
349 };
350}
351
352namespace JRECONSTRUCTION {
355}
356
357#endif
Date and time functions.
This include file serves the purpose of hiding ROOT dependencies and circumphere namespace problems w...
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:354
JFIT::JEvent JEvent
Definition JHistory.hh:353
Auxiliary class for historical event.
Definition JHistory.hh:36
virtual ~JEvent()
Virtual destructor.
Definition JHistory.hh:64
JEvent(const int type)
Constructor.
Definition JHistory.hh:50
int type
application type
Definition JHistory.hh:89
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:75
JUUID uuid
UUID.
Definition JHistory.hh:90
std::string date
date
Definition JHistory.hh:92
std::string git
GIT revision.
Definition JHistory.hh:91
Auxiliary class to test history.
Definition JHistory.hh:105
bool operator()(const JHistory &history) const
Test history.
Definition JHistory.hh:137
is_event(int type)
Constructor.
Definition JHistory.hh:111
is_event(const JHistory &history)
Constructor.
Definition JHistory.hh:122
Auxiliary class to test history.
Definition JHistory.hh:153
bool operator()(const JHistory &history) const
Test history.
Definition JHistory.hh:171
is_not_event(int type)
Constructor.
Definition JHistory.hh:159
Container for historical events.
Definition JHistory.hh:101
const JUUID & getUUID() const
Get UUID.
Definition JHistory.hh:315
bool getStatus(const std::vector< int > &types) const
Get status.
Definition JHistory.hh:270
bool hasParentUUID() const
Has parent UUID.
Definition JHistory.hh:306
JHistory()
Default constructor.
Definition JHistory.hh:186
const JUUID & getParentUUID() const
Get parent UUID.
Definition JHistory.hh:324
JHistory(const JHistory &history, const int type)
Constructor.
Definition JHistory.hh:209
const JHistory & getHistory() const
Get history.
Definition JHistory.hh:229
ClassDef(JHistory, 2)
JHistory & getHistory()
Get history.
Definition JHistory.hh:240
JHistory(const int type)
Constructor.
Definition JHistory.hh:196
virtual ~JHistory()
Virtual destructor.
Definition JHistory.hh:220
friend std::ostream & operator<<(std::ostream &out, const JHistory &history)
Write history to output stream.
Definition JHistory.hh:337
JHistory & add(const int type)
Add event to history.
Definition JHistory.hh:295
bool has(const int type) const
Has event in history.
Definition JHistory.hh:252
Simple wrapper for UUID.
Definition JUUID.hh:24
uuid_t uuid
Definition JUUID.hh:172
static const JUUID & rndm()
Generate random UUID.
Definition JUUID.hh:78