Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTriggerInterface.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JTRIGGERINTERFACE__
2 #define __JTRIGGER__JTRIGGERINTERFACE__
3 
4 #include "JLang/JConversion.hh"
5 
8 #include "JTrigger/JMatch.hh"
10 #include "JDAQ/JDAQTriggerMask.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JTRIGGER {}
18 namespace JPP { using namespace JTRIGGER; }
19 
20 namespace JTRIGGER {
21 
24 
25 
26  /**
27  * Type definition of trigger bit.
28  */
29  typedef unsigned int JTriggerbit_t;
30 
31 
32  /**
33  * Trigger interface.
34  * This interface is used to define a unique bit for each trigger.
35  */
37  {
38  protected:
39  /**
40  * Default constructor.
41  */
43  {}
44 
45 
46  /**
47  * Virtual destructor.
48  */
49  virtual ~JTriggerInterface()
50  {}
51 
52 
53  /**
54  * Auxiliary class for type definition of specific trigger bit.
55  */
56  template<JTriggerbit_t N>
57  struct JBit
58  {
59  static const JTriggerbit_t value = N;
60  };
61 
62 
63  /**
64  * Test whether specific trigger bit correponds to derived trigger class.
65  *
66  * This method will be specialised using the marco setTriggerBit() so that
67  * it will return true if this triggered event corresponds to bit N.
68  *
69  * This method will be repeatedly called by method find_trigger_bit()
70  * which in turn is called by the member method JTriggerInterface::getTriggerBit()
71  * so that it returns the correct trigger bit.
72  *
73  * \return false
74  */
75  template<JTriggerbit_t N>
76  inline bool checkTriggerBit() const
77  {
78  return false;
79  }
80 
81 
82  /**
83  * Recursive method to find the trigger bit of the given trigger data.
84  *
85  * \param bit trigger bit
86  * \return trigger bit
87  */
88  template<JTriggerbit_t N>
90  {
91  if (checkTriggerBit<N>())
92  return N;
93  else
94  return find_trigger_bit(JBit<N+1>());
95  }
96 
97 
98  /**
99  * Termination method of recursive method to find the trigger bit of the given trigger data.
100  * This method throws an error.
101  *
102  * \param bit trigger bit
103  * \return trigger bit
104  */
106  {
107  throw JTriggerException("Method find_trigger_bit<>(): no corresponding trigger bit found.");
108  }
109 
110 
111  /**
112  * Get trigger name.
113  *
114  * This method will be specialised using the marco setTriggerBit() so that
115  * it will return name of trigger for bit N.
116  *
117  * This method will be repeatedly called by method get_trigger_name()
118  * which in turn is called by the method JTriggerInterface::getTriggerName()
119  * so that it returns the correct trigger name.
120  *
121  * \return NULL
122  */
123  template<JTriggerbit_t N>
124  static const char* getTriggerName()
125  {
126  return NULL;
127  }
128 
129 
130  /**
131  * Recursive method to get trigger name for given trigger bit.
132  *
133  * \param bit trigger bit
134  * \param value trigger bit
135  * \return trigger name
136  */
137  template<JTriggerbit_t N>
138  static const char* get_trigger_name(JBit<N> bit, JTriggerbit_t value)
139  {
140  if (bit.value == value)
141  return getTriggerName<N>();
142  else
143  return get_trigger_name(JBit<N+1>(), value);
144  }
145 
146 
147  /**
148  * Termination method of recursive method to get trigger name.
149  *
150  * \param bit trigger bit
151  * \param value trigger bit
152  * \return NULL
153  */
155  {
156  return NULL;
157  }
158 
159  public:
160 
161  typedef JTriggerInput::value_type value_type;
163 
164 
165  /**
166  * Get the trigger bit.
167  *
168  * \return trigger bit
169  */
171  {
172  return find_trigger_bit(JBit<0>());
173  }
174 
175 
176  /**
177  * Get trigger name.
178  *
179  * param bit trigger bit
180  * \return trigger name
181  */
182  static const char* getTriggerName(JTriggerbit_t bit)
183  {
184  return get_trigger_name(JBit<0>(), bit);
185  }
186 
187 
188  /**
189  * Function object to count unique modules.
190  */
192  };
193 
194 
195  /**
196  * This class is used to map trigger class to trigger bit.
197  * It will be specialised using the marco setTriggerBit().
198  *
199  * The specialiation of this class will ensure unique use of a trigger class.
200  * The trigger bit of a valid trigger class (i.e. one defined using
201  * macro setTriggerBit()) is accessible using method getTriggerBit().
202  */
203  template<class JTrigger_t> struct JTriggerBit {};
204 
205 
206  /**
207  * Get the trigger bit.
208  *
209  * \return trigger bit
210  */
211  template<class JTrigger_t>
213  {
215  }
216 
217 
218  /**
219  * Get the trigger bit.
220  *
221  * \param event triggered event
222  * \return trigger bit
223  */
224  template<class JTrigger_t>
225  inline JTriggerbit_t getTriggerBit(const JTrigger_t& event)
226  {
228  }
229 
230 
231  /**
232  * Get trigger name.
233  *
234  * param bit trigger bit
235  * \return trigger name
236  */
237  inline const char* getTriggerName(JTriggerbit_t bit)
238  {
240  }
241 
242 
243  /**
244  * This class will generate a compiler error if trigger bit is out of range.
245  */
246  template<JTriggerbit_t N, bool is_valid = (N < NUMBER_OF_TRIGGER_BITS)>
247  struct JAssertBit;
248 
249  /**
250  * Implementation of a valid trigger bit.
251  */
252  template<JTriggerbit_t N>
254 }
255 
256 
257 /**
258  * Macro to set trigger bit of a given trigger class.
259  *
260  * This macro should be called for each trigger class.
261  * As a result, the trigger class is mapped to a unique bit.
262  * This mapping is then avaiable in the following ways:
263  *
264  * -# The member method JTriggerInterface::getTriggerBit()
265  * will return the specified trigger bit of the derived class; and
266  * -# The trigger bit is stored as a static data member value of
267  * the template class JTRIGGER::JTriggerBit.
268  *
269  * By using this macro, it is verified -at compile time- that:
270  * -# The trigger bit is unique;
271  * -# The trigger class derives from JTRIGGER::JTriggerInterface; and
272  * -# The trigger class has not been associated to another trigger bit;
273  *
274  * \param JTrigger_t trigger class
275  * \param N trigger bit
276  */
277 #define setTriggerBit(JTrigger_t, N) \
278  \
279  \
280  template<> \
281  struct JTriggerBit<JTrigger_t> : \
282  JAssertConversion<JTrigger_t, JTriggerInterface>, \
283  JAssertBit<N> \
284  { \
285  static const JTriggerbit_t value = N; \
286  }; \
287  \
288  \
289  template<> \
290  inline bool JTriggerInterface::checkTriggerBit<N>() const \
291  { \
292  return dynamic_cast<const JTrigger_t*>(this) != NULL; \
293  } \
294  \
295  \
296  template<> \
297  const char* JTriggerInterface::getTriggerName<N>() \
298  { \
299  return #JTrigger_t; \
300  }
301 
302 #endif
JTriggerbit_t find_trigger_bit(JBit< N > bit) const
Recursive method to find the trigger bit of the given trigger data.
static const unsigned int NUMBER_OF_TRIGGER_BITS
Number of trigger bits.
static const char * get_trigger_name(JBit< NUMBER_OF_TRIGGER_BITS > bit, JTriggerbit_t value)
Termination method of recursive method to get trigger name.
JMatch< value_type > match_type
This class is used to map trigger class to trigger bit.
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
virtual ~JTriggerInterface()
Virtual destructor.
Auxialiary class to assert type conversion.
Definition: JConversion.hh:66
Function object interface for hit matching.
Definition: JMatch.hh:27
static const char * getTriggerName(JTriggerbit_t bit)
Get trigger name.
Auxiliary class for type definition of specific trigger bit.
static const JTriggerbit_t value
Base class for match operations inside clusterize methods.
bool checkTriggerBit() const
Test whether specific trigger bit correponds to derived trigger class.
JModuleCounter getNumberOfModules
Function object to count unique modules.
JTriggerbit_t find_trigger_bit(JBit< NUMBER_OF_TRIGGER_BITS > bit) const
Termination method of recursive method to find the trigger bit of the given trigger data...
Implementation of a valid trigger bit.
const char * getTriggerName(JTriggerbit_t bit)
Get trigger name.
JTriggerbit_t getTriggerBit() const
Get the trigger bit.
static const char * get_trigger_name(JBit< N > bit, JTriggerbit_t value)
Recursive method to get trigger name for given trigger bit.
Auxiliary class for counting unique modules.
static const char * getTriggerName()
Get trigger name.
JTriggerInput::value_type value_type
JTriggerInterface()
Default constructor.
JTriggerbit_t getTriggerBit()
Get the trigger bit.
unsigned int JTriggerbit_t
Type definition of trigger bit.