Jpp  master_rocky-43-ge265d140c
the software that should make you happy
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 consecutive hits according match criterion
41  remove_t //!< remove consecutive hits according match criterion
42  };
43 
44 
47 
48 
49  /**
50  * Default constructor.
51  */
53  std::string(get_options()[0].first)
54  {}
55 
56 
57  /**
58  * Type conversion operator.
59  *
60  * \return option
61  */
62  operator JOption_t () const
63  {
64  return JPreprocessor::getOption(*this);
65  }
66 
67 
68  /**
69  * Get option.
70  *
71  * \param option option
72  * \return option
73  */
74  static JOption_t getOption(const JPreprocessor& option)
75  {
76  using namespace std;
77  using namespace JPP;
78 
79  data_type::const_iterator i = find_if(get_options().begin(),
80  get_options().end(),
81  make_predicate(&pair_type::first, JPreprocessor(option)));
82 
83  if (i != get_options().end()) {
84  return i->second;
85  } else {
86  THROW(JTypeInformationException, "Invalid option <" << option << ">");
87  }
88  };
89 
90 
91  /**
92  * Get option.
93  *
94  * \param option option
95  * \return option
96  */
97  static JPreprocessor getOption(const JOption_t option)
98  {
99  using namespace std;
100  using namespace JPP;
101 
102  data_type::const_iterator i = find_if(get_options().begin(),
103  get_options().end(),
104  make_predicate(&pair_type::second, option));
105 
106  if (i != get_options().end()) {
107  return i->first;
108  } else {
109  THROW(JTypeInformationException, "Invalid option <" << option << ">");
110  }
111  };
112 
113 
114  /**
115  * Get options.
116  *
117  * \return list of options
118  */
120  {
121  return JLANG::make_array(get_options().begin(),
122  get_options().end(),
123  &pair_type::first);
124  }
125 
126 
127  /**
128  * Get options.
129  *
130  * \param option option
131  * \return list of options
132  */
134  {
135  std::vector<JPreprocessor> buffer(1, getOption(option));
136 
137  for (const auto& i : get_options()) {
138  if (i.second != option) {
139  buffer.push_back(i.first);
140  }
141  }
142 
143  return buffer;
144  }
145 
146  protected:
147 
148  static const char ENUM_EXTENSION = '_'; //!< Extension of enumeration names.
149 
150  /**
151  * Constructor.
152  *
153  * \param option option
154  */
155  JPreprocessor(const std::string& option) :
156  std::string(option)
157  {
158  using namespace std;
159 
160  const string::size_type pos = this->rfind(ENUM_EXTENSION);
161 
162  if (pos != string::npos) {
163  this->erase(pos);
164  }
165  }
166 
167 
168  /**
169  * Get paired options.
170  *
171  * \return list of paired options
172  */
173  static const data_type& get_options()
174  {
175  static data_type buffer;
176 
177  if (buffer.empty()) {
178 
179 #define MAKE_ENTRY(A) std::make_pair(JPreprocessor(#A), A)
180 
181  buffer.push_back(MAKE_ENTRY(none_t));
182  buffer.push_back(MAKE_ENTRY(join_t));
183  buffer.push_back(MAKE_ENTRY(filter_t));
184  buffer.push_back(MAKE_ENTRY(remove_t));
185 
186 #undef MAKE_ENTRY
187  }
188 
189  return buffer;
190  }
191  };
192 }
193 
194 #endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
#define MAKE_ENTRY(A)
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
Exception for absence of type information.
Definition: JException.hh:648
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
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
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
Definition: JSTDTypes.hh:14
Auxiliary class for specifying the way of pre-processing of hits.
static const char ENUM_EXTENSION
Extension of enumeration names.
static std::vector< JPreprocessor > getOptions(const JOption_t option)
Get options.
static JPreprocessor getOption(const JOption_t option)
Get option.
static JOption_t getOption(const JPreprocessor &option)
Get option.
JPreprocessor(const std::string &option)
Constructor.
std::vector< pair_type > data_type
std::pair< JPreprocessor, JOption_t > pair_type
JPreprocessor()
Default constructor.
static const data_type & get_options()
Get paired options.
JOption_t
Preprocessing options.
@ none_t
no pre-processing
@ filter_t
filter consecutive hits according match criterion
@ remove_t
remove consecutive hits according match criterion
@ join_t
join consecutive hits according match criterion
static std::vector< JPreprocessor > getOptions()
Get options.