Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRunsetups.hh
Go to the documentation of this file.
1 #ifndef __JDB_JRUNSETUPS__
2 #define __JDB_JRUNSETUPS__
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include <algorithm>
8 
9 #include "JDB/JRuns.hh"
10 #include "Jeep/JeepToolkit.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 namespace JDATABASE {}
17 namespace JPP { using namespace JDATABASE; }
18 
19 namespace JDATABASE {
20 
21  /**
22  * Auxiliary class for run setup evaluation.
23  *
24  * The run number is mapped to a unique floating point value according the setup name.
25  */
26  struct JRunsetups :
27  public std::map<int, float>
28  {
29 
30  static const char SEPARATOR = '.'; //!< separator between tokens in setup name
31  static const int MAX_NUMBER_OF_SETUPS = 1000; //!< maximal number of setups for a main category
32 
33 
34  /**
35  * Main run setup category.
36  */
37  enum JRuntype_t {
38  CALIB = 100, //!< Calibration
39  NANOCALIB = 200, //!< Nano-beacon calibration
40  TEST = 300, //!< Test
41  WRONG_TEST = 400, //!< Wrong test
42  PHYS = 1000, //!< Physics
43  OTHER = -1 //!< Other
44  };
45 
46 
47  /**
48  * Get run setup type.
49  *
50  * \param setup run setup name
51  * \return type
52  */
53  static inline int getType(const std::string& setup)
54  {
55  using namespace std;
56  using namespace JPP;
57 
58  static std::map<std::string, int> buffer;
59 
60  if (buffer.empty()) {
61 
62 #define MAKE_ENTRY(A) std::make_pair(getClassname(#A), A)
63 
64  buffer.insert(MAKE_ENTRY(CALIB));
65  buffer.insert(MAKE_ENTRY(NANOCALIB));
66  buffer.insert(MAKE_ENTRY(TEST));
67  buffer.insert(MAKE_ENTRY(WRONG_TEST));
68  buffer.insert(MAKE_ENTRY(PHYS));
69  buffer.insert(MAKE_ENTRY(OTHER));
70 
71 #undef MAKE_ENTRY
72  }
73 
74  string key = setup;
75 
76  string::size_type pos = key.find(SEPARATOR);
77 
78  if (pos != string::npos) {
79  key = key.substr(0,pos);
80  }
81 
82  std::map<std::string, int>::const_iterator i = buffer.find(key);
83 
84  if (i != buffer.end())
85  return i->second;
86  else
87  return OTHER;
88  }
89 
90 
91  /**
92  * Put run parameters.
93  *
94  * \param run run number
95  * \param setup run setup name
96  */
97  void put(const int run,
98  const std::string setup)
99  {
100  using namespace std;
101  using namespace JPP;
102 
103  const int type = getType(setup);
104  vector<string>& buffer = data[type];
105 
106  vector<string>::iterator p = std::find(buffer.begin(), buffer.end(), setup);
107 
108  if (p == buffer.end()) {
109 
110  buffer.push_back(setup);
111 
112  p = buffer.rbegin().base();
113  }
114 
115  const int index = distance(buffer.begin(),p) + 1;
116 
117  if (index >= MAX_NUMBER_OF_SETUPS) {
118  cerr << "Index of " << setup << ' ' << index << " >= " << MAX_NUMBER_OF_SETUPS << endl;
119  }
120 
121  if (type > 0)
122  (*this)[run] = type + (float) index / (float) MAX_NUMBER_OF_SETUPS;
123  else
124  (*this)[run] = type - (float) index / (float) MAX_NUMBER_OF_SETUPS;
125  }
126 
127 
128  /**
129  * Put run parameters.
130  *
131  * \param parameters run parameters
132  */
133  void put(const JRuns& parameters)
134  {
135  put(parameters.RUN, parameters.RUNSETUPNAME);
136  }
137 
138 
139  /**
140  * Check if run setup is vailable.
141  *
142  * \param run run number
143  * \return true if available; else false
144  */
145  bool has(const int run) const
146  {
147  return this->find(run) != this->end();
148  }
149 
150 
151  /**
152  * Get run setup value.
153  *
154  * \param run run number
155  * \return value
156  */
157  float get(const int run) const
158  {
159  const_iterator p = this->find(run);
160 
161  if (p != this->end())
162  return p->second;
163  else
164  return 0.0;
165  }
166 
167  protected:
168  mutable std::map<int, std::vector<std::string> > data; // run type -> run setup names
169  };
170 }
171 
172 #endif
173 
void put(const JRuns &parameters)
Put run parameters.
Definition: JRunsetups.hh:133
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define MAKE_ENTRY(A)
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
static const char SEPARATOR
separator between tokens in setup name
Definition: JRunsetups.hh:30
std::string RUNSETUPNAME
Definition: JRuns.hh:27
static const int MAX_NUMBER_OF_SETUPS
maximal number of setups for a main category
Definition: JRunsetups.hh:31
static int getType(const std::string &setup)
Get run setup type.
Definition: JRunsetups.hh:53
Auxiliary methods for handling file names, type names and environment.
bool has(const int run) const
Check if run setup is vailable.
Definition: JRunsetups.hh:145
void put(const int run, const std::string setup)
Put run parameters.
Definition: JRunsetups.hh:97
Auxiliary class for run setup evaluation.
Definition: JRunsetups.hh:26
Nano-beacon calibration.
Definition: JRunsetups.hh:39
JRuntype_t
Main run setup category.
Definition: JRunsetups.hh:37
std::map< int, std::vector< std::string > > data
Definition: JRunsetups.hh:168