Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
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 */
16namespace JDATABASE {}
17namespace JPP { using namespace JDATABASE; }
18
19namespace JDATABASE {
20
21 /**
22 * Auxiliary data structure for run setup information.
23 */
24 struct JRunsetup_t {
25 std::string name;
26 float value;
27 };
28
29 /**
30 * Auxiliary class for run setup evaluation.
31 *
32 * The run number is mapped to a unique floating point value according the setup name.
33 */
34 struct JRunsetups :
35 public std::map<int, JRunsetup_t>
36 {
37
38 static const char SEPARATOR = '.'; //!< separator between tokens in setup name
39 static const int MAX_NUMBER_OF_SETUPS = 1000; //!< maximal number of setups for a main category
40
41
42 /**
43 * Main run setup category.
44 */
46 CALIB = 100, //!< Calibration
47 NANOCALIB = 200, //!< Nano-beacon calibration
48 TEST = 300, //!< Test
49 WRONG_TEST = 400, //!< Wrong test
50 PHYS = 1000, //!< Physics
51 OTHER = -1 //!< Other
52 };
53
54
55 /**
56 * Get run setup type.
57 *
58 * \param setup run setup name
59 * \return type
60 */
61 static inline int getType(const std::string& setup)
62 {
63 using namespace std;
64 using namespace JPP;
65
66 static std::map<std::string, int> buffer;
67
68 if (buffer.empty()) {
69
70#define MAKE_ENTRY(A) std::make_pair(getClassname(#A), A)
71
72 buffer.insert(MAKE_ENTRY(CALIB));
73 buffer.insert(MAKE_ENTRY(NANOCALIB));
74 buffer.insert(MAKE_ENTRY(TEST));
75 buffer.insert(MAKE_ENTRY(WRONG_TEST));
76 buffer.insert(MAKE_ENTRY(PHYS));
77 buffer.insert(MAKE_ENTRY(OTHER));
78
79#undef MAKE_ENTRY
80 }
81
82 string key = setup;
83
84 string::size_type pos = key.find(SEPARATOR);
85
86 if (pos != string::npos) {
87 key = key.substr(0,pos);
88 }
89
91
92 if (i != buffer.end())
93 return i->second;
94 else
95 return OTHER;
96 }
97
98
99 /**
100 * Put run parameters.
101 *
102 * \param run run number
103 * \param setup run setup name
104 */
105 void put(const int run,
106 const std::string setup)
107 {
108 using namespace std;
109 using namespace JPP;
110
111 const int type = getType(setup);
112 vector<string>& buffer = data[type];
113
114 vector<string>::iterator p = std::find(buffer.begin(), buffer.end(), setup);
115
116 if (p == buffer.end()) {
117
118 buffer.push_back(setup);
119
120 p = buffer.rbegin().base();
121 }
122
123 const int index = distance(buffer.begin(),p) + 1;
124
125 if (index >= MAX_NUMBER_OF_SETUPS) {
126 cerr << "Index of " << setup << ' ' << index << " >= " << MAX_NUMBER_OF_SETUPS << endl;
127 }
128
129 if (type > 0)
130 (*this)[run] = { setup, type + (float) index / (float) MAX_NUMBER_OF_SETUPS };
131 else
132 (*this)[run] = { setup, type - (float) index / (float) MAX_NUMBER_OF_SETUPS };
133 }
134
135
136 /**
137 * Put run parameters.
138 *
139 * \param parameters run parameters
140 */
141 void put(const JRuns& parameters)
142 {
143 put(parameters.RUN, parameters.RUNSETUPNAME);
144 }
145
146
147 /**
148 * Check if run setup is vailable.
149 *
150 * \param run run number
151 * \return true if available; else false
152 */
153 bool has(const int run) const
154 {
155 return this->find(run) != this->end();
156 }
157
158
159 /**
160 * Get run setup value.
161 *
162 * \param run run number
163 * \return value
164 */
165 float get(const int run) const
166 {
167 const_iterator p = this->find(run);
168
169 if (p != this->end())
170 return p->second.value;
171 else
172 return 0.0;
173 }
174
175 protected:
176 mutable std::map<int, std::vector<std::string> > data; // run type -> run setup names
177 };
178}
179
180#endif
181
#define MAKE_ENTRY(A)
Auxiliary methods for handling file names, type names and environment.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Auxiliary classes and methods for database I/O.
Definition JAHRS.hh:14
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::string RUNSETUPNAME
Definition JRuns.hh:27
Auxiliary data structure for run setup information.
Definition JRunsetups.hh:24
Auxiliary class for run setup evaluation.
Definition JRunsetups.hh:36
void put(const int run, const std::string setup)
Put run parameters.
static const int MAX_NUMBER_OF_SETUPS
maximal number of setups for a main category
Definition JRunsetups.hh:39
static int getType(const std::string &setup)
Get run setup type.
Definition JRunsetups.hh:61
static const char SEPARATOR
separator between tokens in setup name
Definition JRunsetups.hh:38
bool has(const int run) const
Check if run setup is vailable.
void put(const JRuns &parameters)
Put run parameters.
std::map< int, std::vector< std::string > > data
float get(const int run) const
Get run setup value.
JRuntype_t
Main run setup category.
Definition JRunsetups.hh:45
@ NANOCALIB
Nano-beacon calibration.
Definition JRunsetups.hh:47
@ WRONG_TEST
Wrong test.
Definition JRunsetups.hh:49
@ CALIB
Calibration.
Definition JRunsetups.hh:46