ATLAS Offline Software
IRingerProcedure.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef RINGERSELECTORTOOLS_PROCEDURES_IPROCEDURE_H
6 #define RINGERSELECTORTOOLS_PROCEDURES_IPROCEDURE_H
7 
8 // STL includes:
9 #include <vector>
10 #include <utility>
11 
12 // Root includes:
13 #include <TDirectory.h>
14 //#include <TClass.h>
15 
16 // Local includes:
18 #include "RingerSelectorTools/tools/IRedirectMsgStream.h"
19 #include <type_traits>
20 
21 #ifndef INCLUDE_HEADER_ONLY
22 #define INCLUDE_HEADER_ONLY
23 #endif // INCLUDE_HEADER_ONLY
24 #include "RingerSelectorTools/procedures/Types.h"
25 #undef INCLUDE_HEADER_ONLY
26 
38 #define RINGER_PROCEDURE_BASE_METHODS(self) \
39  \
40  public: \
41  \
42  template <typename T = const char*> \
43  static T procType(); \
44  \
45  virtual std::string name() const = 0; \
46  \
47  virtual void print(MSG::Level lvl) const = 0;
48 
52 #define RINGER_DEFINE_INTERFACE_DEFAULT_METHODS(self) \
53  \
54  template<> \
55  inline \
56  const char* self::procType() \
57  { \
58  return #self; \
59  } \
60  \
61  template<> \
62  inline \
63  Ringer::RingerProcedureType<self>::procEnum_t self::procType() \
64  { \
65  return Ringer::getType< \
66  Ringer::RingerProcedureType<self>::procEnum_t>(#self); \
67  }
68 
69 #define __RINGER_DEFINE_PROCEDURE_STANDARD_METHODS__(self) \
70  \
71  virtual std::string name() const \
72  override; \
73  template <typename T = const char*> \
74  static T procType(); \
75  \
76 
77 
80 #define RINGER_DEFINE_PROCEDURE(self) \
81  \
82  public: \
83  __RINGER_DEFINE_PROCEDURE_STANDARD_METHODS__(self) \
84  \
85  virtual void print(MSG::Level lvl) const \
86  override;
87 
91 #define RINGER_DEFINE_NOMEMBER_PROCEDURE(self) \
92  \
93  public: \
94  __RINGER_DEFINE_PROCEDURE_STANDARD_METHODS__(self) \
95  \
96  virtual void print(MSG::Level lvl) const \
97  override \
98  { \
99  if ( !this->isStreamAvailable() ) { \
100  std::cerr << "Cannot print " << this->name() << ", stream unavailable" \
101  << std::endl; \
102  } \
103  if ( this->level() > lvl ) { \
104  return; \
105  } \
106  ATH_MSG_LVL(lvl, "Procedure hasn't any property."); \
107  }
108 
117 #define RINGER_DEFINE_PROCEDURE_DEFAULT_METHODS(self) \
118  \
119  RINGER_DEFINE_INTERFACE_DEFAULT_METHODS(self) \
120  \
121  inline \
122  std::string self::name() const \
123  { \
124  return this->procType<const char*>(); \
125  }
126 
127 
128 
132 namespace Ringer {
133 
134 class DepVarStruct;
135 
136 // Declare interface base for all Ringer procedure types:
137 //
144 class IRingerProcedure : virtual public IRedirectMsgStream {
145  public:
149  virtual void write(TDirectory *configDir, const char*idxStr = "")
150  const = 0;
151 
153  virtual ~IRingerProcedure(){;}
154 
155  protected:
156 
158  //ClassDef(IRingerProcedure,0)
159 };
160 
161 // Forward declare base procedure types:
162 namespace PreProcessing {
163  class IPreProcessor;
164  class IPreProcessorVarDep;
165 }
166 
167 namespace Discrimination {
168  class IDiscriminator;
169  class IDiscriminatorVarDep;
170  class IThreshold;
171  class IThresholdVarDep;
172 }
173 
189 template<typename procedure_t >
191 
193  "Requested to check Ringer procedure type from class that is not a IRingerProcedure.");
194 
195  // Determine which procedure type it is:
196  static constexpr bool is_pre_processor =
198  static constexpr bool is_discriminator =
200  static constexpr bool is_threshold =
202 
203  static_assert( ( is_pre_processor || is_discriminator || is_threshold ),
204  "Couldn't find a procedure type.");
205 
206  // Determine which enumType it should have been declared
207  typedef typename std::conditional< is_pre_processor,
208  preProcEnum_t, // true, it is_pre_processor
209  typename std::conditional< is_discriminator,
210  discrEnum_t, // true, it is discriminator
211  thresEnum_t >::type >::type procEnum_t;
212 
213  // Boolean to determine whether this procedure inherits from VariableDependency
214  static constexpr bool inherits_from_var_dep = std::is_base_of< VariableDependency,
215  procedure_t>::value;
216 
217  // Determine which interface this Ringer procedure inherits from
218  typedef typename std::conditional< is_pre_processor,
219  // true, it is_pre_processor
220  typename std::conditional< inherits_from_var_dep,
222  // not pre_processor, check if is_discriminator
223  typename std::conditional< is_discriminator,
224  // true, it is_discriminator
225  typename std::conditional< inherits_from_var_dep,
227  // otherwise it has to be threshold
228  typename std::conditional< inherits_from_var_dep,
230  >::type
232 };
233 
238 template<typename procedure_t >
239 struct RingerProcedureType<procedure_t*> : public RingerProcedureType<procedure_t>{ };
240 
244 namespace PreProcessing {
245 
249 class IPreProcessor : virtual public IRingerProcedure
250 {
251 
253 
254  public:
258  virtual void execute(std::vector<float> &inputSpace) const = 0;
259 
261  //ClassDef(IPreProcessor,0)
262 };
263 
268  public virtual IPreProcessor
269 {
270 
272 
273  public:
274  //IPreProcessorVarDep(){;}
275 
276  // This is needed for parsing wrapper
277  static IPreProcessorVarDep* read(TDirectory *){ return nullptr;}
278 
280  //ClassDef(IPreProcessorVarDep,0)
281 };
282 
283 } // namespace PreProcessor
284 
288 namespace Discrimination {
289 
293 class IDiscriminator : virtual public IRingerProcedure
294 {
295 
297 
298  public:
299  virtual void execute(const std::vector<float> &input,
300  std::vector<float> &output) const = 0;
301 
303  //ClassDef(IDiscriminator,0)
304 };
305 
310  public virtual IDiscriminator
311 {
312 
314 
315  public:
316  //IDiscriminatorVarDep(){;}
317 
318  // This prototype is needed for parsing wrapper
319  static IDiscriminatorVarDep* read(TDirectory *){ return nullptr;}
320 
322  //ClassDef(IDiscriminatorVarDep,0)
323 };
324 
328 class IThreshold : virtual public IRingerProcedure
329 {
330 
332 
333  public:
337  virtual void execute(const std::vector<float> &input,
338  std::vector<bool> &output, const DepVarStruct &depVar) const = 0;
339 
341  //ClassDef(IThreshold,0)
342 };
343 
347 class IThresholdVarDep : public virtual VariableDependency,
348  public virtual IThreshold
349 {
350 
352 
353  public:
354  //IThresholdVarDep(){;}
355 
356  // This prototype is needed for parsing wrapper
357  static IThresholdVarDep* read(TDirectory *){ return nullptr;}
358 
360  //ClassDef(IThresholdVarDep,0)
361 };
362 
363 } // namespace Discrimination
364 
365 // Declare procedure type member functions
366 namespace PreProcessing {
368 RINGER_DEFINE_INTERFACE_DEFAULT_METHODS( IPreProcessorVarDep )
369 } // namespace PreProcessing
370 namespace Discrimination {
372 RINGER_DEFINE_INTERFACE_DEFAULT_METHODS( IThresholdVarDep )
374 RINGER_DEFINE_INTERFACE_DEFAULT_METHODS( IDiscriminatorVarDep )
375 } // namespace Discrimination
376 
377 } // namespace Ringer
378 
379 #endif // RINGERSELECTORTOOLS_PROCEDURES_IPROCEDURE_H
Ringer::RingerProcedureType::is_discriminator
static constexpr bool is_discriminator
Definition: IRingerProcedure.h:198
Ringer::IRingerProcedure::write
virtual void write(TDirectory *configDir, const char *idxStr="") const =0
Write Ringer procedure to configuration directory.
VariableDependency.h
Ringer::IRingerProcedure
The base interface for all Ringer procedures.
Definition: IRingerProcedure.h:144
athena.value
value
Definition: athena.py:122
Ringer::RingerProcedureType::procEnum_t
std::conditional< is_pre_processor, preProcEnum_t, typename std::conditional< is_discriminator, discrEnum_t, thresEnum_t >::type >::type procEnum_t
Definition: IRingerProcedure.h:204
Ringer::Discrimination::IDiscriminator::execute
virtual void execute(const std::vector< float > &input, std::vector< float > &output) const =0
Ringer::RingerProcedureType::is_pre_processor
static constexpr bool is_pre_processor
Definition: IRingerProcedure.h:196
Ringer::IRingerProcedure::~IRingerProcedure
virtual ~IRingerProcedure()
Ensures virtual dtor for all inherited classes.
Definition: IRingerProcedure.h:153
Ringer::Discrimination::IThreshold::execute
virtual void execute(const std::vector< float > &input, std::vector< bool > &output, const DepVarStruct &depVar) const =0
Execute threshold for input and retrieve throw output.
Ringer::RingerProcedureType::baseInterface_t
std::conditional< is_pre_processor, typename std::conditional< inherits_from_var_dep, PreProcessing::IPreProcessorVarDep, PreProcessing::IPreProcessor >::type, typename std::conditional< is_discriminator, typename std::conditional< inherits_from_var_dep, Discrimination::IDiscriminatorVarDep, Discrimination::IDiscriminator >::type, typename std::conditional< inherits_from_var_dep, Discrimination::IThresholdVarDep, Discrimination::IThreshold >::type >::type >::type baseInterface_t
Definition: IRingerProcedure.h:231
Ringer::RingerProcedureType
Check Ringer Procedure type.
Definition: IRingerProcedure.h:190
Ringer::PreProcessing::IPreProcessorVarDep
PreProcessor interface to be used by Ringer Wrapper.
Definition: IRingerProcedure.h:269
Ringer::PreProcessing::IPreProcessor
PreProcessing interface to be inherited by PreProcessing procedures.
Definition: IRingerProcedure.h:250
Ringer::RingerProcedureType::is_threshold
static constexpr bool is_threshold
Definition: IRingerProcedure.h:200
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
Ringer::Discrimination::IDiscriminator
Discriminator interface to be inherited by discrimination procedures.
Definition: IRingerProcedure.h:294
Ringer::RingerProcedureType::inherits_from_var_dep
static constexpr bool inherits_from_var_dep
Definition: IRingerProcedure.h:214
Ringer::Discrimination::IThreshold
Threshold interface to be inherited by thresholding procedures.
Definition: IRingerProcedure.h:329
Ringer::Discrimination::IDiscriminatorVarDep::read
static IDiscriminatorVarDep * read(TDirectory *)
Definition: IRingerProcedure.h:319
merge.output
output
Definition: merge.py:17
Ringer::PreProcessing::IPreProcessor::execute
virtual void execute(std::vector< float > &inputSpace) const =0
RINGER_PROCEDURE_BASE_METHODS
#define RINGER_PROCEDURE_BASE_METHODS(self)
Define ringer interface default methods.
Definition: IRingerProcedure.h:38
Ringer::Discrimination::IThresholdVarDep
Threshold interface to be used by Ringer Wrapper.
Definition: IRingerProcedure.h:349
Ringer::VariableDependency
Interface for possible Eta and Et variable dependency.
Definition: VariableDependency.h:89
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Ringer::Discrimination::IThresholdVarDep::read
static IThresholdVarDep * read(TDirectory *)
Definition: IRingerProcedure.h:357
Ringer::Discrimination::IDiscriminatorVarDep
Discriminator interface to be used by Ringer Wrapper.
Definition: IRingerProcedure.h:311
Ringer::PreProcessing::IPreProcessorVarDep::read
static IPreProcessorVarDep * read(TDirectory *)
Definition: IRingerProcedure.h:277
Ringer::DepVarStruct
Definition: VariableDependency.h:32
RINGER_DEFINE_INTERFACE_DEFAULT_METHODS
#define RINGER_DEFINE_INTERFACE_DEFAULT_METHODS(self)
Define Ringer interface procedure type methods.
Definition: IRingerProcedure.h:52
Ringer
Namespace dedicated for Ringer utilities.
Definition: CaloRingsDefs.h:9