DuneEventInfo.h
Go to the documentation of this file.
1 // DuneEventInfo.h
2 
3 // David Adams
4 // June 2019
5 //
6 // Event info for dataprep in DUNE.
7 
8 #ifndef DuneEventInfo_H
9 #define DuneEventInfo_H
10 
11 #include <sstream>
12 #include <memory>
13 
15 
16 public:
17 
18  using Index = unsigned int;
19  using LongIndex = unsigned long;
20 
22  Index event =badIndex();
24  time_t time =0;
25  int timerem =0;
29 
30  static Index badIndex() { return -1u; }
31  static LongIndex badLongIndex() { return -1ul; }
32  static const DuneEventInfo& badEventInfo() {
33  static DuneEventInfo bei;
34  return bei;
35  }
36 
37  // Reset to no event.
38  void clear() {
39  run = badIndex();
40  event = badIndex();
41  subRun = badIndex();
42  time = 0;
43  timerem = 0;
44  trigger = badIndex();
45  triggerClock = badLongIndex();
46  triggerTick0 = badLongIndex();
47  }
48 
49  // Default ctor.
50  DuneEventInfo() = default;
51 
52  // Ctor from components.
53  DuneEventInfo(Index a_run, Index a_event, Index a_subRun =badIndex(),
54  time_t a_time =0, int a_timerem =0,
55  Index a_trigger =badIndex(),
56  LongIndex a_triggerClock =badLongIndex(),
57  LongIndex a_triggerTick0 =badLongIndex())
58  : run(a_run), event(a_event), subRun(a_subRun),
59  time(a_time), timerem(a_timerem),
60  trigger(a_trigger),
61  triggerClock(a_triggerClock),
62  triggerTick0(a_triggerTick0) { }
63 
64  // Is this valid info?
65  bool isValid() const { return run != badIndex(); }
66 
67  // Order two event info objects.
68  bool operator<(const DuneEventInfo& rhs) {
69  if ( run < rhs.run ) return true;
70  if ( rhs.run < run ) return false;
71  if ( subRun < rhs.subRun ) return true;
72  if ( rhs.subRun < subRun ) return false;
73  if ( event < rhs.event ) return true;
74  if ( rhs.event < event ) return false;
75  if ( triggerClock < rhs.triggerClock ) return true;
76  if ( rhs.triggerClock < triggerClock ) return false;
77  if ( triggerTick0 < rhs.triggerTick0 ) return true;
78  if ( rhs.triggerTick0 < triggerTick0 ) return false;
79  return false;
80  }
81 
82  // Compare two event info objects.
83  bool operator==(const DuneEventInfo& rhs) const {
84  if ( run != rhs.run ) return false;
85  if ( subRun != rhs.subRun ) return false;
86  if ( event != rhs.event ) return false;
87  if ( time != rhs.time ) return false;
88  if ( timerem != rhs.timerem ) return false;
89  if ( trigger != rhs.trigger ) return false;
90  if ( triggerClock != rhs.triggerClock ) return false;
91  if ( triggerTick0 != rhs.triggerTick0 ) return false;
92  return true;
93  }
94 
95  bool operator!=(const DuneEventInfo& rhs) const {
96  return ! (*this == rhs);
97  }
98 
99  // Return the event number as a string.
101  std::ostringstream ssout;
102  ssout << event;
103  return ssout.str();
104  }
105 
106  // For run RRR and subrun SSS:
107  // opt = 0: Return RRR.
108  // 1: Return RRR-SSS
109  // 2: if SSS==0, return RRR, otherwise RRR-SSS.
111  std::ostringstream ssout;
112  ssout << run;
113  if ( opt == 1 || (opt ==2 && subRun > 0 && subRun!=badIndex()) ) {
114  ssout << "-" << subRun;
115  }
116  return ssout.str();
117  }
118 
119 };
120 
121 #endif
LongIndex triggerTick0
Definition: DuneEventInfo.h:28
std::string string
Definition: nybbler.cc:12
static Index badIndex()
Definition: DuneEventInfo.h:30
opt
Definition: train.py:196
bool operator==(const DuneEventInfo &rhs) const
Definition: DuneEventInfo.h:83
DuneEventInfo(Index a_run, Index a_event, Index a_subRun=badIndex(), time_t a_time=0, int a_timerem=0, Index a_trigger=badIndex(), LongIndex a_triggerClock=badLongIndex(), LongIndex a_triggerTick0=badLongIndex())
Definition: DuneEventInfo.h:53
bool operator<(const DuneEventInfo &rhs)
Definition: DuneEventInfo.h:68
bool operator!=(const DuneEventInfo &rhs) const
Definition: DuneEventInfo.h:95
static const DuneEventInfo & badEventInfo()
Definition: DuneEventInfo.h:32
std::string runString(Index opt=2) const
bool isValid() const
Definition: DuneEventInfo.h:65
static LongIndex badLongIndex()
Definition: DuneEventInfo.h:31
std::string eventString() const
DuneEventInfo()=default
unsigned long LongIndex
Definition: DuneEventInfo.h:19
unsigned int Index
Definition: DuneEventInfo.h:18
LongIndex triggerClock
Definition: DuneEventInfo.h:27
Event finding and building.