1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
#include "DQM/L1TMonitor/interface/L1TOMDSHelper.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/Run.h"
using namespace std;
//_____________________________________________________________________
L1TOMDSHelper::L1TOMDSHelper() { m_omdsReader = nullptr; }
//_____________________________________________________________________
L1TOMDSHelper::~L1TOMDSHelper() { delete m_omdsReader; }
//_____________________________________________________________________
bool L1TOMDSHelper::connect(string iOracleDB, string iPathCondDB, int &error) {
// Handeling inputs
m_oracleDB = iOracleDB;
m_pathCondDB = iPathCondDB;
error = NO_ERROR;
// Initializing variables
bool SessionOpen = false;
bool out = false;
m_omdsReader = new l1t::OMDSReader();
m_omdsReader->connect(m_oracleDB, m_pathCondDB);
// Testing session
if (!m_omdsReader->dbSession().connectionString().empty()) {
SessionOpen = true;
}
// Defining output and error message if needed
if (SessionOpen) {
out = true;
} else {
error = WARNING_DB_CONN_FAILED;
}
return out;
}
//_____________________________________________________________________
map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMTriggerXsecFits(string iTable, int &error) {
map<string, WbMTriggerXSecFit> out;
const l1t::OMDSReader::QueryResults qresults;
error = NO_ERROR;
// Parameters
string qSchema = "CMS_WBM";
// Fields to retrive in the query
vector<string> qStrings;
qStrings.push_back("BIT");
qStrings.push_back("NAME");
qStrings.push_back("PM1"); //Inverse
qStrings.push_back("P0"); //Constant
qStrings.push_back("P1"); //Linear
qStrings.push_back("P2"); //Quadratic
l1t::OMDSReader::QueryResults paramResults = m_omdsReader->basicQuery(qStrings, qSchema, iTable, "", qresults);
if (paramResults.queryFailed()) {
error = WARNING_DB_QUERY_FAILED;
} else {
for (int i = 0; i < paramResults.numberRows(); ++i) {
WbMTriggerXSecFit tFit;
tFit.fitFunction = "[0]/x+[1]+[2]*x+[3]*x*x"; // Fitting function hardcoded for now
string tBitName;
paramResults.fillVariableFromRow("BIT", i, tFit.bitNumber);
paramResults.fillVariableFromRow("NAME", i, tBitName);
paramResults.fillVariableFromRow("PM1", i, tFit.pm1);
paramResults.fillVariableFromRow("P0", i, tFit.p0);
paramResults.fillVariableFromRow("P1", i, tFit.p1);
paramResults.fillVariableFromRow("P2", i, tFit.p2);
tFit.bitName = tBitName;
out[tBitName] = tFit;
}
}
return out;
}
//_____________________________________________________________________
map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMAlgoXsecFits(int &error) {
return getWbMTriggerXsecFits("LEVEL1_ALGO_CROSS_SECTION", error);
}
//_____________________________________________________________________
map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMTechXsecFits(int &error) {
return getWbMTriggerXsecFits("LEVEL1_TECH_CROSS_SECTION", error);
}
//_____________________________________________________________________
int L1TOMDSHelper::getNumberCollidingBunches(int lhcFillNumber, int &error) {
int nCollidingBunches = 0;
error = NO_ERROR;
// Parameters
string rtlSchema = "CMS_RUNTIME_LOGGER";
string table = "FILL_INITLUMIPERBUNCH";
string atribute1 = "LHCFILL";
// Fields to retrive in the query
vector<std::string> qStrings;
qStrings.push_back("BUNCH");
qStrings.push_back("BEAM1CONFIG");
qStrings.push_back("BEAM2CONFIG");
l1t::OMDSReader::QueryResults qResults =
m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
// Check query successful
if (qResults.queryFailed()) {
error = WARNING_DB_QUERY_FAILED;
} else {
if (qResults.numberRows() != 3564) {
error = WARNING_DB_INCORRECT_NBUNCHES;
} else {
// Now we count the number of bunches with both beam 1 and 2 configured
for (int i = 0; i < qResults.numberRows(); ++i) {
int bunch;
bool beam1config, beam2config;
qResults.fillVariableFromRow("BUNCH", i, bunch);
qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
if (beam1config && beam2config) {
nCollidingBunches++;
}
}
}
}
return nCollidingBunches;
}
//_____________________________________________________________________
BeamConfiguration L1TOMDSHelper::getBeamConfiguration(int lhcFillNumber, int &error) {
BeamConfiguration bConfig;
error = NO_ERROR;
// Fields to retrive in the query
string rtlSchema = "CMS_RUNTIME_LOGGER";
string table = "FILL_INITLUMIPERBUNCH";
string atribute1 = "LHCFILL";
// Setting the strings we want to recover from OMDS
vector<std::string> qStrings;
qStrings.push_back("BUNCH");
qStrings.push_back("BEAM1CONFIG");
qStrings.push_back("BEAM2CONFIG");
l1t::OMDSReader::QueryResults qResults =
m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
if (qResults.queryFailed()) {
error = WARNING_DB_QUERY_FAILED;
} else {
if (qResults.numberRows() != 3564) {
error = WARNING_DB_INCORRECT_NBUNCHES;
} else {
bConfig.m_valid = true;
int nCollidingBunches = 0;
for (int i = 0; i < qResults.numberRows(); ++i) {
int bunch;
bool beam1config, beam2config;
qResults.fillVariableFromRow("BUNCH", i, bunch);
qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
if (beam1config) {
bConfig.beam1.push_back(true);
} else {
bConfig.beam1.push_back(false);
}
if (beam2config) {
bConfig.beam2.push_back(true);
} else {
bConfig.beam2.push_back(false);
}
if (beam1config && beam2config) {
nCollidingBunches++;
}
}
bConfig.nCollidingBunches = nCollidingBunches;
}
}
return bConfig;
}
//_____________________________________________________________________
vector<bool> L1TOMDSHelper::getBunchStructure(int lhcFillNumber, int &error) {
vector<bool> BunchStructure;
error = NO_ERROR;
// Fields to retrive in the query
string rtlSchema = "CMS_RUNTIME_LOGGER";
string table = "FILL_INITLUMIPERBUNCH";
string atribute1 = "LHCFILL";
// Setting the strings we want to recover from OMDS
vector<std::string> qStrings;
qStrings.push_back("BUNCH");
qStrings.push_back("BEAM1CONFIG");
qStrings.push_back("BEAM2CONFIG");
l1t::OMDSReader::QueryResults qResults =
m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
if (qResults.queryFailed()) {
error = WARNING_DB_QUERY_FAILED;
} else {
if (qResults.numberRows() != 3564) {
error = WARNING_DB_INCORRECT_NBUNCHES;
} else {
for (int i = 0; i < qResults.numberRows(); ++i) {
int bunch;
bool beam1config, beam2config;
qResults.fillVariableFromRow("BUNCH", i, bunch);
qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
if (beam1config && beam2config) {
BunchStructure.push_back(true);
} else {
BunchStructure.push_back(false);
}
}
}
}
return BunchStructure;
}
//_____________________________________________________________________
vector<float> L1TOMDSHelper::getInitBunchLumi(int lhcFillNumber, int &error) {
vector<float> InitBunchLumi;
error = NO_ERROR;
// Fields to retrive in the query
string rtlSchema = "CMS_RUNTIME_LOGGER";
string table = "FILL_INITLUMIPERBUNCH";
string atribute1 = "LHCFILL";
// Setting the strings we want to recover from OMDS
vector<std::string> qStrings;
qStrings.push_back("BUNCH");
qStrings.push_back("INITBUNCHLUMI");
l1t::OMDSReader::QueryResults qResults =
m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
if (qResults.queryFailed()) {
error = WARNING_DB_QUERY_FAILED;
} else {
if (qResults.numberRows() != 3564) {
error = WARNING_DB_INCORRECT_NBUNCHES;
} else {
for (int i = 0; i < qResults.numberRows(); ++i) {
int bunch;
float initbunchlumi;
qResults.fillVariableFromRow("BUNCH", i, bunch);
qResults.fillVariableFromRow("INITBUNCHLUMI", i, initbunchlumi);
InitBunchLumi.push_back(initbunchlumi);
}
}
}
return InitBunchLumi;
}
//_____________________________________________________________________
vector<double> L1TOMDSHelper::getRelativeBunchLumi(int lhcFillNumber, int &error) {
vector<double> RelativeBunchLumi;
error = NO_ERROR;
// Fields to retrive in the query
string rtlSchema = "CMS_RUNTIME_LOGGER";
string table = "FILL_INITLUMIPERBUNCH";
string atribute1 = "LHCFILL";
// Setting the strings we want to recover from OMDS
vector<std::string> qStrings;
qStrings.push_back("BUNCH");
qStrings.push_back("INITBUNCHLUMI");
l1t::OMDSReader::QueryResults qResults =
m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
if (qResults.queryFailed()) {
error = WARNING_DB_QUERY_FAILED;
} else {
if (qResults.numberRows() != 3564) {
error = WARNING_DB_INCORRECT_NBUNCHES;
} else {
//-> Get the inicial bunch luminosity add calculate the total luminosity of the fill
double InitTotalLumi = 0;
vector<float> InitBunchLumi;
for (int i = 0; i < qResults.numberRows(); ++i) {
int bunch;
float initbunchlumi;
qResults.fillVariableFromRow("BUNCH", i, bunch);
qResults.fillVariableFromRow("INITBUNCHLUMI", i, initbunchlumi);
InitTotalLumi += initbunchlumi;
InitBunchLumi.push_back(initbunchlumi);
}
//-> We calculate the relative luminosity for each bunch
for (unsigned int i = 0; i < InitBunchLumi.size(); i++) {
RelativeBunchLumi.push_back(InitBunchLumi[i] / InitTotalLumi);
}
}
}
return RelativeBunchLumi;
}
//_____________________________________________________________________
string L1TOMDSHelper::enumToStringError(int iObject) {
string out;
switch (iObject) {
case NO_ERROR:
out = "NO_ERROR";
break;
case WARNING_DB_CONN_FAILED:
out = "WARNING_DB_CONN_FAILED";
break;
case WARNING_DB_QUERY_FAILED:
out = "WARNING_DB_QUERY_FAILED";
break;
case WARNING_DB_INCORRECT_NBUNCHES:
out = "WARNING_DB_INCORRECT_NBUNCHES";
break;
default:
out = "UNKNOWN";
break;
};
return out;
}
|