Jpp  16.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPreprocessor.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JPREPROCESSOR__
2 #define __JTRIGGER__JPREPROCESSOR__
3 
4 #include <string>
5 #include <utility>
6 #include <vector>
7 #include <algorithm>
8 
9 #include "JLang/JException.hh"
10 #include "JLang/JPredicate.hh"
11 #include "JLang/JVectorize.hh"
12 
13 
14 /**
15  * \file
16  *
17  * Auxiliaries for pre-processing of hits.
18  * \author mdejong
19  */
20 namespace JTRIGGER {}
21 namespace JPP { using namespace JTRIGGER; }
22 
23 namespace JTRIGGER {
24 
26 
27 
28  /**
29  * Auxiliary class for specifying the way of pre-processing of hits.
30  */
31  struct JPreprocessor :
32  public std::string
33  {
34  /**
35  * Preprocessing options.
36  */
37  enum JOption_t {
38  none_t = 0, //!< no pre-processing
39  join_t, //!< join consecutive hits according match criterion
40  filter_t //!< filter-out consecutive hits according match criterion
41  };
42 
43 
46 
47 
48  /**
49  * Default constructor.
50  */
52  std::string(get_options()[0].first)
53  {}
54 
55 
56  /**
57  * Type conversion operator.
58  *
59  * \return option
60  */
61  operator JOption_t () const
62  {
63  return JPreprocessor::getOption(*this);
64  }
65 
66 
67  /**
68  * Get option.
69  *
70  * \param option option
71  * \return option
72  */
73  static JOption_t getOption(const JPreprocessor& option)
74  {
75  using namespace std;
76  using namespace JPP;
77 
78  map_type::const_iterator i = find_if(get_options().begin(),
79  get_options().end(),
81 
82  if (i != get_options().end()) {
83  return i->second;
84  } else {
85  THROW(JTypeInformationException, "Invalid option <" << option << ">");
86  }
87  };
88 
89 
90  /**
91  * Get options.
92  *
93  * \return list of options
94  */
96  {
97  return JLANG::make_array(get_options().begin(),
98  get_options().end(),
100  }
101 
102  protected:
103 
104  static const char ENUM_EXTENSION = '_'; //!< Extension of enumeration names.
105 
106  /**
107  * Constructor.
108  *
109  * \param option option
110  */
111  JPreprocessor(const std::string& option) :
112  std::string(option)
113  {
114  using namespace std;
115 
116  const string::size_type pos = this->rfind(ENUM_EXTENSION);
117 
118  if (pos != string::npos) {
119  this->erase(pos);
120  }
121  }
122 
123 
124  /**
125  * Get paired options.
126  *
127  * \return list of paired options
128  */
129  static const map_type& get_options()
130  {
131  static map_type buffer;
132 
133  if (buffer.empty()) {
134 
135 #define MAKE_ENTRY(A) std::make_pair(JPreprocessor(#A), A)
136 
137  buffer.push_back(MAKE_ENTRY(none_t));
138  buffer.push_back(MAKE_ENTRY(join_t));
139  buffer.push_back(MAKE_ENTRY(filter_t));
140 
141 #undef MAKE_ENTRY
142  }
143 
144  return buffer;
145  }
146  };
147 }
148 
149 #endif
Exception for absence of type information.
Definition: JException.hh:630
Exceptions.
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
static std::vector< JPreprocessor > getOptions()
Get options.
static JOption_t getOption(const JPreprocessor &option)
Get option.
#define MAKE_ENTRY(A)
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
std::pair< JPreprocessor, JOption_t > pair_type
join consecutive hits according match criterion
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
static const char ENUM_EXTENSION
Extension of enumeration names.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
JOption_t
Preprocessing options.
filter-out consecutive hits according match criterion
JPreprocessor(const std::string &option)
Constructor.
JPreprocessor()
Default constructor.
Auxiliary class for specifying the way of pre-processing of hits.
static const map_type & get_options()
Get paired options.
std::vector< pair_type > map_type