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