Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/JPredicate.hh"
18 #include "JSystem/JDate.hh"
19 
20 
21 /**
22  * \author mdejong
23  */
24 
25 namespace JRECONSTRUCTION {}
26 namespace JPP { using namespace JRECONSTRUCTION; }
27 
28 namespace JFIT {
29 
30  /**
31  * Auxiliary class for historical event.
32  */
33  struct JEvent {
34  /**
35  * Default constructor.
36  */
37  JEvent() :
38  type(-1),
39  id (-1)
40  {}
41 
42  /**
43  * Constructor.
44  *
45  * \param type application type
46  * \param id application identifier
47  */
48  JEvent(const int type,
49  const int id)
50  {
51  using namespace JPP;
52 
53  this->type = type;
54  this->id = id;
55  this->svn = getGITVersion();
56  this->date = getDateAndTime();
57  }
58 
59 
60  /**
61  * Virtual destructor.
62  */
63  virtual ~JEvent()
64  {}
65 
66 
67  /**
68  * Write event to output stream.
69  *
70  * \param out output stream
71  * \param event event
72  * \return output stream
73  */
74  friend std::ostream& operator<<(std::ostream& out, const JEvent& event)
75  {
76  using namespace std;
77 
78  out << setw(3) << right << event.id << ' '
79  << setw(2) << right << event.type << ' '
80  << setw(20) << left << event.svn << ' '
81  << setw(20) << left << event.date;
82 
83  return out;
84  }
85 
86  ClassDef(JEvent, 1);
87 
88  int type; ///< application type
89  int id; ///< application identifier
90  std::string svn; ///< SVN revision
91  std::string date; ///< date
92  };
93 
94 
95  /**
96  * Container for historical events.
97  */
98  struct JHistory :
99  public std::vector<JEvent>
100  {
101  /**
102  * Auxiliary class to test history.
103  */
104  struct is_event {
105  /**
106  * Constructor.
107  *
108  * \param type application type
109  */
111  {
112  this->type = type;
113  }
114 
115 
116  /**
117  * Constructor.
118  *
119  * \param history history
120  */
121  is_event(const JHistory& history)
122  {
123  if (!history.empty())
124  this->type = history.rbegin()->type;
125  else
126  this->type = -1;
127  }
128 
129 
130  /**
131  * Test history.
132  *
133  * \param history history
134  * \return true if given history ends with specified event type; else false
135  */
136  bool operator()(const JHistory& history) const
137  {
138  if (!history.empty()) {
139  return history.rbegin()->type == this->type;
140  }
141 
142  return false;
143  }
144 
145  int type;
146  };
147 
148 
149  /**
150  * Auxiliary class to test history.
151  */
152  struct is_not_event {
153  /**
154  * Constructor.
155  *
156  * \param type application type
157  */
159  {
160  this->type = type;
161  }
162 
163 
164  /**
165  * Test history.
166  *
167  * \param history history
168  * \return true if given history does not contain specified event type; else false
169  */
170  bool operator()(const JHistory& history) const
171  {
172  using namespace std;
173  using namespace JPP;
174 
175  return count_if(history.begin(), history.end(), make_predicate(&JEvent::type, this->type)) == 0;
176  }
177 
178  int type;
179  };
180 
181 
182  /**
183  * Default constructor.
184  */
186  std::vector<JEvent>()
187  {}
188 
189 
190  /**
191  * Constructor.
192  *
193  * \param type application type
194  */
195  JHistory(const int type) :
196  std::vector<JEvent>()
197  {
198  add(type);
199  }
200 
201 
202  /**
203  * Constructor.
204  *
205  * \param history history
206  * \param type application type
207  */
208  JHistory(const JHistory& history,
209  const int type) :
210  std::vector<JEvent>(history)
211  {
212  add(type);
213  }
214 
215 
216  /**
217  * Virtual destructor.
218  */
219  virtual ~JHistory()
220  {}
221 
222 
223  /**
224  * Get history.
225  *
226  * \return histtory
227  */
228  const JHistory& getHistory() const
229  {
230  return static_cast<const JHistory&>(*this);
231  }
232 
233 
234  /**
235  * Get history.
236  *
237  * \return histtory
238  */
240  {
241  return static_cast<JHistory&>(*this);
242  }
243 
244 
245  /**
246  * Add event to history.
247  *
248  * \param type application type
249  * \return this history
250  */
251  JHistory& add(const int type)
252  {
253  push_back(JEvent(type, this->size() + 1));
254 
255  return *this;
256  }
257 
258 
259  /**
260  * Write history to output stream.
261  *
262  * \param out output stream
263  * \param history history
264  * \return output stream
265  */
266  friend std::ostream& operator<<(std::ostream& out, const JHistory& history)
267  {
268  using namespace std;
269 
270  for (const_iterator i = history.begin(); i != history.end(); ++i) {
271  out << *i << endl;
272  }
273 
274  return out;
275  }
276 
277  ClassDef(JHistory, 1);
278  };
279 }
280 
281 namespace JRECONSTRUCTION {
284 }
285 
286 #endif
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
JHistory & add(const int type)
Add event to history.
Definition: JHistory.hh:251
ClassDef(JEvent, 1)
Auxiliary class to test history.
Definition: JHistory.hh:152
Jpp environment information.
friend std::ostream & operator<<(std::ostream &out, const JHistory &history)
Write history to output stream.
Definition: JHistory.hh:266
Container for historical events.
Definition: JHistory.hh:98
This include file serves the purpose of hiding ROOT dependencies and circumphere namespace problems w...
bool operator()(const JHistory &history) const
Test history.
Definition: JHistory.hh:136
friend std::ostream & operator<<(std::ostream &out, const JEvent &event)
Write event to output stream.
Definition: JHistory.hh:74
Date and time functions.
static JDateAndTime getDateAndTime
Function object to get ASCII formatted date and time.
is_event(int type)
Constructor.
Definition: JHistory.hh:110
virtual ~JEvent()
Virtual destructor.
Definition: JHistory.hh:63
std::string getGITVersion(const std::string &tag)
Get GIT version for given GIT tag.
int type
application type
Definition: JHistory.hh:88
JHistory()
Default constructor.
Definition: JHistory.hh:185
std::string svn
SVN revision.
Definition: JHistory.hh:90
Auxiliary class to test history.
Definition: JHistory.hh:104
JEvent(const int type, const int id)
Constructor.
Definition: JHistory.hh:48
bool operator()(const JHistory &history) const
Test history.
Definition: JHistory.hh:170
std::string date
date
Definition: JHistory.hh:91
JHistory(const int type)
Constructor.
Definition: JHistory.hh:195
JHistory(const JHistory &history, const int type)
Constructor.
Definition: JHistory.hh:208
Auxiliary class for historical event.
Definition: JHistory.hh:33
JEvent()
Default constructor.
Definition: JHistory.hh:37
is_event(const JHistory &history)
Constructor.
Definition: JHistory.hh:121
JFIT::JHistory JHistory
Definition: JHistory.hh:283
const JHistory & getHistory() const
Get history.
Definition: JHistory.hh:228
virtual ~JHistory()
Virtual destructor.
Definition: JHistory.hh:219
JHistory & getHistory()
Get history.
Definition: JHistory.hh:239
int id
application identifier
Definition: JHistory.hh:89
is_not_event(int type)
Constructor.
Definition: JHistory.hh:158