Bayeux  3.4.1
Core Foundation library for SuperNEMO
event_id.h
Go to the documentation of this file.
1 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2008-02-15
4  * Last modified: 2013-03-22
5  *
6  * Description:
7  * A generic event id with run number and event number
8  *
9  */
10 
11 #ifndef DATATOOLS_EVENT_ID_H
12 #define DATATOOLS_EVENT_ID_H
13 
14 // Standard Library:
15 #include <string>
16 #include <sstream>
17 #include <iostream>
18 #include <stdexcept>
19 
20 // Third Party:
21 // - Boost:
22 #include <boost/cstdint.hpp>
23 
24 // Datatools:
26 #include <datatools/i_tree_dump.h>
27 #include <datatools/i_clear.h>
28 #ifndef Q_MOC_RUN
30 #endif // Q_MOC_RUN
31 
32 namespace datatools {
33 
56  class event_id
59  , public datatools::i_clear
60  {
61  public:
63  static const int INVALID_RUN_NUMBER = -1;
65  static const int ANY_RUN_NUMBER = -2;
66 
68  static const int INVALID_EVENT_NUMBER = -1;
70  static const int ANY_EVENT_NUMBER = -2;
71 
73  static const char IO_FORMAT_SEP = '_';
74  static const char IO_FORMAT_ANY = '*';
75  static const char IO_FORMAT_INVALID = '!';
76 
78 
80  event_id();
81 
83  explicit event_id(int e_);
84 
86 
89  event_id(int r_, int e_);
90 
92  virtual ~event_id();
93 
95  virtual void clear();
96 
98  void reset();
99 
101 
103  int get_run_number() const;
104 
106 
108  int get_event_number() const;
109 
111 
113  void set_run_number(int r_);
114 
116 
118  void set_event_number(int e_);
119 
121 
124  void set(int r_, int e_);
125 
127  bool is_valid() const;
128 
130  bool is_complete() const;
131 
133 
137  bool has(int r_, int e_) const;
138 
140 
144  bool match(int r_, int e_) const;
145 
147  bool operator==(const event_id & id_) const;
148 
150  bool operator<(const event_id & id_) const;
151 
153  bool operator>(const event_id & id_) const;
154 
156  std::string to_string() const;
157 
159  void from_string(const std::string & s_);
160 
162  friend std::ostream & operator<<(std::ostream & s_, const event_id & id_);
163 
165  friend std::istream & operator>>(std::istream & s_, event_id & id_);
166 
168 
173  virtual void tree_dump(std::ostream & out_ = std::cerr,
174  const std::string & title_ = "",
175  const std::string & indent_ = "",
176  bool inherit_ = false) const;
177 
178  void smart_print(std::ostream & out_,
179  const std::string & title_,
180  const std::string & indent_) const;
181 
182  std::string to_smart_string(const std::string & title_,
183  const std::string & indent_) const;
184 
186  void dump() const;
187 
188  private:
189 
190  int32_t _run_number_;
191  int32_t _event_number_;
192 
195 
196 
198 
199  DR_CLASS_RTTI()
200 
201  };
202 
203 
205 
208  : public std::unary_function<event_id, bool>
209  {
210  public:
211 
213 
216  : _id_(id_)
217  {
218  return;
219  }
220 
222 
224  bool operator() (const event_id & id_) const
225  {
226  return _id_ == id_;
227  }
228 
229  private:
230 
231  event_id _id_;
232 
233  };
234 
235 } // end of namespace datatools
236 
238 
239 #ifndef Q_MOC_RUN
240 // Activate reflection layer for the 'datatools::event_id' class:
242 #endif // Q_MOC_RUN
243 
244 // Explicit class version:
245 #include <boost/serialization/version.hpp>
246 BOOST_CLASS_VERSION(datatools::event_id, 1)
247 
248 #endif // DATATOOLS_EVENT_ID_H
249 
250 // Local Variables: --
251 // mode: c++ --
252 // c-file-style: "gnu" --
253 // tab-width: 2 --
254 // End: --
int get_run_number() const
Returns the run number.
#define DR_CLASS_INIT(Introspectable)
Inform Camp that class Introspectable exists and trigger the automatic registration of dedicated refl...
Definition: reflection_interface.h:149
Base abstract class of all serializable (and possibly introspectable) classes.
Definition: i_serializable.h:51
static const int ANY_EVENT_NUMBER
Constant value for any event number.
Definition: event_id.h:70
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
#define DATATOOLS_SERIALIZATION_DECLARATION_ADVANCED(ClassName)
Definition: i_serializable.h:371
bool has(int r_, int e_) const
Check if the instance has specific run and event numbers.
friend std::istream & operator>>(std::istream &s_, event_id &id_)
Input operator.
event_id_equal_predicate(const event_id &id_)
Constructor.
Definition: event_id.h:215
std::string to_smart_string(const std::string &title_, const std::string &indent_) const
event_id()
The default constructor.
bool match(int r_, int e_) const
Check if the instance match specific run and event numbers.
static const int INVALID_RUN_NUMBER
Constant value for an invalid run number.
Definition: event_id.h:63
virtual ~event_id()
The destructor.
void set_run_number(int r_)
Set the run number.
bool operator<(const event_id &id_) const
Comparison operator.
static const char IO_FORMAT_SEP
Separator character used in to_string and from_string methods.
Definition: event_id.h:73
bool is_complete() const
Check whether the ID is complete (run number and event number are set).
Predicate to check if an event_id equals another one.
Definition: event_id.h:207
static const int ANY_RUN_NUMBER
Constant value for any run number.
Definition: event_id.h:65
bool is_valid() const
Check whether the ID is valid.
int get_event_number() const
Returns the event number.
#define DATATOOLS_SERIALIZATION_EXT_BACKWARD_SERIAL_TAG_DECLARATION(ClassName)
Definition: i_serializable.h:180
void smart_print(std::ostream &out_, const std::string &title_, const std::string &indent_) const
void from_string(const std::string &s_)
Input convertor.
void reset()
Invalidate the id.
static const int INVALID_EVENT_NUMBER
Constant value for an invalid event number.
Definition: event_id.h:68
A pure abstract class (interface) for inherited clearable classes.
Definition: i_clear.h:9
void set_event_number(int e_)
Set the event number.
static const char IO_FORMAT_ANY
Definition: event_id.h:74
#define DATATOOLS_SERIALIZATION_BACKWARD_SERIAL_TAG_SUPPORT()
Definition: i_serializable.h:174
static const char IO_FORMAT_INVALID
Definition: event_id.h:75
void set(int r_, int e_)
Set the run and event numbers.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
std::string to_string() const
Output convertor.
bool operator==(const event_id &id_) const
Comparison operator.
virtual void tree_dump(std::ostream &out_=std::cerr, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Method for smart printing (from the datatools::i_tree_dump interface).
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
A simple event identifier based on a run number and an event number Run and event numbers are represe...
Definition: event_id.h:56
friend std::ostream & operator<<(std::ostream &s_, const event_id &id_)
Output operator.
bool operator>(const event_id &id_) const
Comparison operator.
virtual void clear()
Invalidate the id.
void dump() const
Shortcut to the tree_dump method with default arguments.