Jpp  17.2.1-pre0
the software that should make you happy
 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"
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  /**
190  * This class is used to map trigger class to trigger bit.
191  * It will be specialised using the marco setTriggerBit().
192  *
193  * The specialiation of this class will ensure unique use of a trigger class.
194  * The trigger bit of a valid trigger class (i.e.\ one defined using
195  * macro setTriggerBit()) is accessible using method getTriggerBit().
196  */
197  template<class JTrigger_t> struct JTriggerBit {};
198 
199 
200  /**
201  * Get the trigger bit.
202  *
203  * \return trigger bit
204  */
205  template<class JTrigger_t>
207  {
209  }
210 
211 
212  /**
213  * Get the trigger bit.
214  *
215  * \param event triggered event
216  * \return trigger bit
217  */
218  template<class JTrigger_t>
219  inline JTriggerbit_t getTriggerBit(const JTrigger_t& event)
220  {
222  }
223 
224 
225  /**
226  * Get trigger name.
227  *
228  * param bit trigger bit
229  * \return trigger name
230  */
231  inline const char* getTriggerName(JTriggerbit_t bit)
232  {
234  }
235 
236 
237  /**
238  * This class will generate a compiler error if trigger bit is out of range.
239  */
240  template<JTriggerbit_t N, bool is_valid = (N < NUMBER_OF_TRIGGER_BITS)>
241  struct JAssertBit;
242 
243  /**
244  * Implementation of a valid trigger bit.
245  */
246  template<JTriggerbit_t N>
248 }
249 
250 
251 /**
252  * Macro to set trigger bit of a given trigger class.
253  *
254  * This macro should be called for each trigger class.
255  * As a result, the trigger class is mapped to a unique bit.
256  * This mapping is then avaiable in the following ways:
257  *
258  * -# The member method JTriggerInterface::getTriggerBit()
259  * will return the specified trigger bit of the derived class; and
260  * -# The trigger bit is stored as a static data member value of
261  * the template class JTRIGGER::JTriggerBit.
262  *
263  * By using this macro, it is verified -at compile time- that:
264  * -# The trigger bit is unique;
265  * -# The trigger class derives from JTRIGGER::JTriggerInterface; and
266  * -# The trigger class has not been associated to another trigger bit;
267  *
268  * \param JTrigger_t trigger class
269  * \param N trigger bit
270  */
271 #define setTriggerBit(JTrigger_t, N) \
272  \
273  \
274  template<> \
275  struct JTriggerBit<JTrigger_t> : \
276  JAssertConversion<JTrigger_t, JTriggerInterface>, \
277  JAssertBit<N> \
278  { \
279  static const JTriggerbit_t value = N; \
280  }; \
281  \
282  \
283  template<> \
284  inline bool JTriggerInterface::checkTriggerBit<N>() const \
285  { \
286  return dynamic_cast<const JTrigger_t*>(this) != NULL; \
287  } \
288  \
289  \
290  template<> \
291  const char* JTriggerInterface::getTriggerName<N>() \
292  { \
293  return #JTrigger_t; \
294  }
295 
296 #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.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
virtual ~JTriggerInterface()
Virtual destructor.
Auxialiary class to assert type conversion.
Definition: JConversion.hh:66
Function object interface for hit matching.
Definition: JMatch.hh:25
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 for cluster and hit-preprocessing methods.
bool checkTriggerBit() const
Test whether specific trigger bit correponds to derived trigger class.
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.
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.