All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TriggerAlgoBase.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file TriggerAlgoBase.h
3 //
4 // \brief Trigger logic base class.
5 //
6 // \author kazuhiro@nevis.columbia.edu
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 #ifndef TRIGGERALGOBASE_H
11 #define TRIGGERALGOBASE_H
12 
13 // ART includes
14 namespace art { class Event; }
15 namespace fhicl { class ParameterSet; }
16 
17 // From this package
18 #include "TriggerTypes.hh"
19 
20 // STL
21 #include <map>
22 #include <set>
23 
24 namespace trigger
25 {
26  /**
27  Simple read-out trigger logic base class.
28  This class applies a logic of data readout trigger.
29 
30  Given an input array of readout trigger timestamps, this module applies
31  trigger deadtime and readout window to decide which data packet to be
32  readout and stored.
33 
34  In the following, I use a notation TS to represent trigdata::TrigTimeSlice_t
35  for short. Note TS is what is used as absolute scale of time in this algorithm.
36  Each experiment may implement different reference point or unit to this time
37  scale. See TriggerTypes.h for definition.
38 
39  std::set<TS> _timestamps should be filled with time-stamps
40  (with an arbitrary unit of your choise) of readout candidate triggers.
41  This should be done in FillData(art::Event& event) function, which
42  is virtual in this header and needs to be implemented in the inherited
43  class.
44 
45  After filling timestamps, one calls SimTrigger() to analyze and decide
46  time windows during which incoming data should be readout and stored.
47  This function stores a valid readout time window in the std::map<TS,TS>
48  type variable, _time_windows. This map contains the ending time stamp
49  of each readout window as a key, and the starting time stamp as a value.
50 
51  Once SimTrigger() is called, then one can ask whether a specific time T
52  is within the valid readout windows or not by a function, IsTriggered(TS time).
53  This function returns true if the given time stamp is included in any of valid
54  readout window. Else, returns false.
55 
56  For further specifications that may have to do with a specific experiment
57  or electronics should implement their specific complications in the inherited
58  class. This includes FillData() virtual function since different experiments
59  certainly have different data format from which readout trigger candidates'
60  timestamp is extracted.
61 
62  Note: IsTriggered(TS time) function performs a search of closest readout
63  window to "time", and hence could be expensive (though stl::upper_bound is pretty fast).
64 
65  */
67 
68  public:
69 
70  TriggerAlgoBase(fhicl::ParameterSet const& pset);
71  virtual ~TriggerAlgoBase() = default;
72 
73  /// Function to run trigger simulation ... children class may be override
74  virtual void RunTriggerSim(const art::Event& event){
75  FillData(event);
76  SimTrigger();
77  };
78 
79  /// Function to clear simulated trigger information
80  virtual void ClearTriggerInfo(){
81  _sim_done=false;
82  _timestamps.clear();
83  _time_windows.clear();
84  };
85 
86  /// Getter for a boolean which "true" value indicates trigger simulation is run already
87  bool HasRunTriggerSim() const { return _sim_done;};
88 
89  /// Function to check if "time" (input arg.) is within any of valid readout windows or not
90  bool IsTriggered(trigdata::TrigTimeSlice_t time) const;
91 
92  /// Getter to a const pointer of _time_windows std::map variable
93  const std::map<trigdata::TrigTimeSlice_t,trigdata::TrigTimeSlice_t>* GetTimeWindows() const {return &_time_windows;};
94 
95  /// Getter to a const pointer of _timestamps std::set variable
96  const std::set<trigdata::TrigTimeSlice_t>* GetTriggerTimeStamps() const {return &_timestamps;};
97 
98 
99  protected:
100 
101  /// Function to fill _timestamps std::set variable ... TO BE IMPLEMENTED in children
102  virtual void FillData(const art::Event& event)=0;
103 
104  /// Function to analyze _timestamps and store valid readout windows in _time_windows
105  virtual void SimTrigger();
106 
107  /// Function to extract fhicl parameters
108  void Config(fhicl::ParameterSet const& pset);
109 
110  /// stores CANDIDATE readout trigger timestamps
111  std::set<trigdata::TrigTimeSlice_t> _timestamps;
112 
113  /// stores VALID readout trigger time windows
114  std::map<trigdata::TrigTimeSlice_t,trigdata::TrigTimeSlice_t> _time_windows;
115 
116  /// preceeding readout-window from trigger time stamp
118 
119  /// proceeding readout-window from trigger time stamp
121 
122  /// trigger deadtime AFTER each valid trigger timestamps
124 
125  /// run utility boolean, set to true after trigger simulation is run
126  bool _sim_done;
127 
128  }; // class TriggerAlgoBase
129 
130 } //namespace trigger
131 
132 #endif
uint64_t TrigTimeSlice_t
A unit of time used in trigger logic.
Definition: TriggerTypes.hh:9
std::set< trigdata::TrigTimeSlice_t > _timestamps
stores CANDIDATE readout trigger timestamps
trigdata::TrigTimeSlice_t _proceeding_slices
proceeding readout-window from trigger time stamp
const std::map< trigdata::TrigTimeSlice_t, trigdata::TrigTimeSlice_t > * GetTimeWindows() const
Getter to a const pointer of _time_windows std::map variable.
trigdata::TrigTimeSlice_t _preceeding_slices
preceeding readout-window from trigger time stamp
TriggerAlgoBase(fhicl::ParameterSet const &pset)
virtual void FillData(const art::Event &event)=0
Function to fill _timestamps std::set variable ... TO BE IMPLEMENTED in children. ...
virtual ~TriggerAlgoBase()=default
virtual void RunTriggerSim(const art::Event &event)
Function to run trigger simulation ... children class may be override.
bool HasRunTriggerSim() const
Getter for a boolean which &quot;true&quot; value indicates trigger simulation is run already.
virtual void SimTrigger()
Function to analyze _timestamps and store valid readout windows in _time_windows. ...
bool _sim_done
run utility boolean, set to true after trigger simulation is run
std::map< trigdata::TrigTimeSlice_t, trigdata::TrigTimeSlice_t > _time_windows
stores VALID readout trigger time windows
void Config(fhicl::ParameterSet const &pset)
Function to extract fhicl parameters.
bool IsTriggered(trigdata::TrigTimeSlice_t time) const
Function to check if &quot;time&quot; (input arg.) is within any of valid readout windows or not...
const std::set< trigdata::TrigTimeSlice_t > * GetTriggerTimeStamps() const
Getter to a const pointer of _timestamps std::set variable.
trigdata::TrigTimeSlice_t _deadtime
trigger deadtime AFTER each valid trigger timestamps
virtual void ClearTriggerInfo()
Function to clear simulated trigger information.