1 #ifndef RecoLuminosity_LumiProducer_Lumi2DB_H
2 #define RecoLuminosity_LumiProducer_Lumi2DB_H
3 #include "RelationalAccess/ConnectionService.h"
4 #include "CoralBase/AttributeList.h"
5 #include "CoralBase/Attribute.h"
6 #include "CoralBase/AttributeSpecification.h"
7 #include "CoralBase/Blob.h"
8 #include "CoralBase/Exception.h"
9 #include "RelationalAccess/ISessionProxy.h"
10 #include "RelationalAccess/ITransaction.h"
11 #include "RelationalAccess/ITypeConverter.h"
12 #include "RelationalAccess/ISchema.h"
13 #include "RelationalAccess/ITable.h"
14 #include "RelationalAccess/ITableDataEditor.h"
15 #include "RelationalAccess/IBulkOperation.h"
72 std::vector<PerBXData>
bxET;
85 bool hasStableBeam(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd);
91 unsigned int irunnumber,
93 LumiResult::iterator lumiBeg,
94 LumiResult::iterator lumiEnd);
99 unsigned int ncollidingbunches,
100 LumiResult::iterator lumiBeg,
101 LumiResult::iterator lumiEnd);
103 unsigned int irunnumber,
105 LumiResult::iterator lumiBeg,
106 LumiResult::iterator lumiEnd);
107 bool isLumiDataValid(LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd);
109 void cleanTemporaryMemory(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd);
117 return float(varToCalibrate) *
m_norm;
120 lumi::Lumi2DB::LumiResult::iterator lumiEnd) {
124 lumi::Lumi2DB::LumiResult::iterator lumiIt;
126 for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt) {
127 if (lumiIt->beammode ==
"STABLE BEAMS") {
137 lumi::Lumi2DB::LumiResult::iterator lumiEnd) {
141 lumi::Lumi2DB::LumiResult::iterator lumiIt;
143 for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt) {
145 if (lumiIt->instlumi <= 0.5e-8) {
155 unsigned int irunnumber,
157 lumi::Lumi2DB::LumiResult::iterator lumiBeg,
158 lumi::Lumi2DB::LumiResult::iterator lumiEnd) {
159 coral::AttributeList inputData;
160 inputData.extend(
"bxindex",
typeid(coral::Blob));
161 inputData.extend(
"beamintensity_1",
typeid(coral::Blob));
162 inputData.extend(
"beamintensity_2",
typeid(coral::Blob));
163 inputData.extend(
"runnum",
typeid(
unsigned int));
164 inputData.extend(
"startorbit",
typeid(
unsigned int));
165 inputData.extend(
"lumiversion",
typeid(
std::string));
166 coral::Blob& bxindex = inputData[
"bxindex"].data<coral::Blob>();
167 coral::Blob& beamintensity_1 = inputData[
"beamintensity_1"].data<coral::Blob>();
168 coral::Blob& beamintensity_2 = inputData[
"beamintensity_2"].data<coral::Blob>();
169 unsigned int&
runnumber = inputData[
"runnum"].data<
unsigned int>();
170 unsigned int& startorbit = inputData[
"startorbit"].data<
unsigned int>();
173 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
174 coral::IBulkOperation* summaryUpdater =
nullptr;
176 unsigned int lumiindx = 0;
177 unsigned int comittedls = 0;
179 "CMSBXINDEXBLOB=:bxindex,BEAMINTENSITYBLOB_1=:beamintensity_1,BEAMINTENSITYBLOB_2=:beamintensity_2");
180 std::string condition(
"RUNNUM=:runnum AND STARTORBIT=:startorbit AND LUMIVERSION=:lumiversion");
181 runnumber = irunnumber;
182 lumiversion = ilumiversion;
183 for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt, ++lumiindx) {
184 if (!session->transaction().isActive()) {
185 session->transaction().start(
false);
187 startorbit = lumiIt->startorbit;
189 short nlivebx = lumiIt->nlivebx;
191 bxindex.resize(
sizeof(
short) * nlivebx);
192 beamintensity_1.resize(
sizeof(
float) * nlivebx);
193 beamintensity_2.resize(
sizeof(
float) * nlivebx);
194 void* bxindex_StartAddress = bxindex.startingAddress();
195 void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
196 void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
197 std::memmove(bxindex_StartAddress, lumiIt->bxindex,
sizeof(
short) * nlivebx);
198 std::memmove(beamIntensity1_StartAddress, lumiIt->beamintensity_1,
sizeof(
float) * nlivebx);
199 std::memmove(beamIntensity2_StartAddress, lumiIt->beamintensity_2,
sizeof(
float) * nlivebx);
200 ::free(lumiIt->bxindex);
201 ::free(lumiIt->beamintensity_1);
202 ::free(lumiIt->beamintensity_2);
205 beamintensity_1.resize(0);
206 beamintensity_2.resize(0);
209 summaryUpdater = summarytable.dataEditor().bulkUpdateRows(setClause, condition, inputData, totallumils);
210 summaryUpdater->processNextIteration();
211 summaryUpdater->flush();
214 std::cout <<
"\t committing in LS chunck " << comittedls << std::endl;
215 delete summaryUpdater;
216 summaryUpdater =
nullptr;
217 session->transaction().commit();
219 std::cout <<
"\t committed " << std::endl;
220 }
else if (lumiindx == (totallumils - 1)) {
221 std::cout <<
"\t committing at the end" << std::endl;
222 delete summaryUpdater;
223 summaryUpdater =
nullptr;
224 session->transaction().commit();
230 unsigned int irunnumber,
232 lumi::Lumi2DB::LumiResult::iterator lumiBeg,
233 lumi::Lumi2DB::LumiResult::iterator lumiEnd) {
234 coral::AttributeList summaryData;
235 coral::AttributeList detailData;
236 summaryData.extend(
"LUMISUMMARY_ID",
typeid(
unsigned long long));
237 summaryData.extend(
"RUNNUM",
typeid(
unsigned int));
238 summaryData.extend(
"CMSLSNUM",
typeid(
unsigned int));
239 summaryData.extend(
"LUMILSNUM",
typeid(
unsigned int));
240 summaryData.extend(
"LUMIVERSION",
typeid(
std::string));
241 summaryData.extend(
"DTNORM",
typeid(
float));
242 summaryData.extend(
"LHCNORM",
typeid(
float));
243 summaryData.extend(
"INSTLUMI",
typeid(
float));
244 summaryData.extend(
"INSTLUMIERROR",
typeid(
float));
245 summaryData.extend(
"INSTLUMIQUALITY",
typeid(
short));
246 summaryData.extend(
"LUMISECTIONQUALITY",
typeid(
short));
247 summaryData.extend(
"CMSALIVE",
typeid(
short));
248 summaryData.extend(
"STARTORBIT",
typeid(
unsigned int));
249 summaryData.extend(
"NUMORBIT",
typeid(
unsigned int));
250 summaryData.extend(
"BEAMENERGY",
typeid(
float));
251 summaryData.extend(
"BEAMSTATUS",
typeid(
std::string));
252 summaryData.extend(
"CMSBXINDEXBLOB",
typeid(coral::Blob));
253 summaryData.extend(
"BEAMINTENSITYBLOB_1",
typeid(coral::Blob));
254 summaryData.extend(
"BEAMINTENSITYBLOB_2",
typeid(coral::Blob));
256 detailData.extend(
"LUMIDETAIL_ID",
typeid(
unsigned long long));
257 detailData.extend(
"LUMISUMMARY_ID",
typeid(
unsigned long long));
258 detailData.extend(
"BXLUMIVALUE",
typeid(coral::Blob));
259 detailData.extend(
"BXLUMIERROR",
typeid(coral::Blob));
260 detailData.extend(
"BXLUMIQUALITY",
typeid(coral::Blob));
261 detailData.extend(
"ALGONAME",
typeid(
std::string));
263 unsigned long long& lumisummary_id = summaryData[
"LUMISUMMARY_ID"].data<
unsigned long long>();
264 unsigned int& lumirunnum = summaryData[
"RUNNUM"].data<
unsigned int>();
266 float& dtnorm = summaryData[
"DTNORM"].data<
float>();
267 float& lhcnorm = summaryData[
"LHCNORM"].data<
float>();
268 float& instlumi = summaryData[
"INSTLUMI"].data<
float>();
269 float& instlumierror = summaryData[
"INSTLUMIERROR"].data<
float>();
270 short& instlumiquality = summaryData[
"INSTLUMIQUALITY"].data<
short>();
271 short& lumisectionquality = summaryData[
"LUMISECTIONQUALITY"].data<
short>();
272 short& alive = summaryData[
"CMSALIVE"].data<
short>();
273 unsigned int& lumilsnr = summaryData[
"LUMILSNUM"].data<
unsigned int>();
274 unsigned int& cmslsnr = summaryData[
"CMSLSNUM"].data<
unsigned int>();
275 unsigned int& startorbit = summaryData[
"STARTORBIT"].data<
unsigned int>();
276 unsigned int& numorbit = summaryData[
"NUMORBIT"].data<
unsigned int>();
277 float& beamenergy = summaryData[
"BEAMENERGY"].data<
float>();
279 coral::Blob& bxindex = summaryData[
"CMSBXINDEXBLOB"].data<coral::Blob>();
280 coral::Blob& beamintensity_1 = summaryData[
"BEAMINTENSITYBLOB_1"].data<coral::Blob>();
281 coral::Blob& beamintensity_2 = summaryData[
"BEAMINTENSITYBLOB_2"].data<coral::Blob>();
283 unsigned long long& lumidetail_id = detailData[
"LUMIDETAIL_ID"].data<
unsigned long long>();
284 unsigned long long& d2lumisummary_id = detailData[
"LUMISUMMARY_ID"].data<
unsigned long long>();
285 coral::Blob& bxlumivalue = detailData[
"BXLUMIVALUE"].data<coral::Blob>();
286 coral::Blob& bxlumierror = detailData[
"BXLUMIERROR"].data<coral::Blob>();
287 coral::Blob& bxlumiquality = detailData[
"BXLUMIQUALITY"].data<coral::Blob>();
290 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
291 coral::IBulkOperation* summaryInserter =
nullptr;
292 coral::IBulkOperation* detailInserter =
nullptr;
296 unsigned int lumiindx = 0;
297 std::map<unsigned long long, std::vector<unsigned long long> > idallocationtable;
298 std::cout <<
"\t allocating total lumisummary ids " << totallumils << std::endl;
301 session->transaction().start(
false);
303 unsigned long long lumisummaryID =
305 unsigned long long lumidetailID =
308 session->transaction().commit();
309 for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt, ++lumiindx, ++lumisummaryID) {
310 std::vector<unsigned long long> allIDs;
311 allIDs.reserve(1 + lumi::N_LUMIALGO);
312 allIDs.push_back(lumisummaryID);
314 allIDs.push_back(lumidetailID);
316 idallocationtable.insert(std::make_pair(lumiindx, allIDs));
318 std::cout <<
"\t all ids allocated" << std::endl;
320 unsigned int comittedls = 0;
321 for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt, ++lumiindx) {
322 if (!session->transaction().isActive()) {
323 session->transaction().start(
false);
325 summaryInserter = summarytable.dataEditor().bulkInsert(summaryData, totallumils);
327 detailInserter = detailtable.dataEditor().bulkInsert(detailData, totallumils * lumi::N_LUMIALGO);
329 lumisummary_id = idallocationtable[lumiindx][0];
330 lumirunnum = irunnumber;
331 lumiversion = ilumiversion;
332 dtnorm = lumiIt->dtnorm;
333 lhcnorm = lumiIt->lhcnorm;
336 instlumi = applyCalibration(lumiIt->instlumi);
337 instlumierror = applyCalibration(lumiIt->instlumierror);
338 instlumiquality = lumiIt->instlumiquality;
339 lumisectionquality = lumiIt->lumisectionquality;
340 alive = lumiIt->cmsalive;
341 cmslsnr = lumiIt->cmslsnr;
343 lumilsnr = lumiIt->lumilsnr;
344 startorbit = lumiIt->startorbit;
345 numorbit = lumiIt->numorbit;
346 beamenergy = lumiIt->beamenergy;
347 beamstatus = lumiIt->beammode;
348 short nlivebx = lumiIt->nlivebx;
351 bxindex.resize(
sizeof(
short) * nlivebx);
352 beamintensity_1.resize(
sizeof(
float) * nlivebx);
353 beamintensity_2.resize(
sizeof(
float) * nlivebx);
354 void* bxindex_StartAddress = bxindex.startingAddress();
355 void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
356 void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
357 std::memmove(bxindex_StartAddress, lumiIt->bxindex,
sizeof(
short) * nlivebx);
358 std::memmove(beamIntensity1_StartAddress, lumiIt->beamintensity_1,
sizeof(
float) * nlivebx);
359 std::memmove(beamIntensity2_StartAddress, lumiIt->beamintensity_2,
sizeof(
float) * nlivebx);
365 beamintensity_1.resize(0);
366 beamintensity_2.resize(0);
369 summaryInserter->processNextIteration();
370 summaryInserter->flush();
371 unsigned int algoindx = 1;
373 d2lumisummary_id = idallocationtable[lumiindx].at(0);
374 lumidetail_id = idallocationtable[lumiindx].at(algoindx);
375 std::vector<PerBXData>::const_iterator bxIt;
376 std::vector<PerBXData>::const_iterator bxBeg;
377 std::vector<PerBXData>::const_iterator bxEnd;
380 bxBeg = lumiIt->bxET.begin();
381 bxEnd = lumiIt->bxET.end();
385 bxBeg = lumiIt->bxOCC1.begin();
386 bxEnd = lumiIt->bxOCC1.end();
390 bxBeg = lumiIt->bxOCC2.begin();
391 bxEnd = lumiIt->bxOCC2.end();
396 bxlumivalue.resize(
sizeof(
float) *
lumi::N_BX);
397 bxlumierror.resize(
sizeof(
float) * lumi::N_BX);
398 bxlumiquality.resize(
sizeof(
short) * lumi::N_BX);
399 void* bxlumivalueStartAddress = bxlumivalue.startingAddress();
400 void* bxlumierrorStartAddress = bxlumierror.startingAddress();
401 void* bxlumiqualityStartAddress = bxlumiquality.startingAddress();
403 for (bxIt = bxBeg; bxIt != bxEnd; ++bxIt, ++
k) {
404 lumivalue[
k] = bxIt->lumivalue;
405 lumierror[
k] = bxIt->lumierr;
406 lumiquality[
k] = bxIt->lumiquality;
408 std::memmove(bxlumivalueStartAddress, lumivalue,
sizeof(
float) * lumi::N_BX);
409 std::memmove(bxlumierrorStartAddress, lumierror,
sizeof(
float) * lumi::N_BX);
410 std::memmove(bxlumiqualityStartAddress, lumiquality,
sizeof(
short) * lumi::N_BX);
411 detailInserter->processNextIteration();
413 detailInserter->flush();
416 std::cout <<
"\t committing in LS chunck " << comittedls << std::endl;
417 delete summaryInserter;
418 summaryInserter =
nullptr;
419 delete detailInserter;
420 detailInserter =
nullptr;
421 session->transaction().commit();
423 std::cout <<
"\t committed " << std::endl;
424 }
else if (lumiindx == (totallumils - 1)) {
425 std::cout <<
"\t committing at the end" << std::endl;
426 delete summaryInserter;
427 summaryInserter =
nullptr;
428 delete detailInserter;
429 detailInserter =
nullptr;
430 session->transaction().commit();
438 unsigned int irunnumber,
440 unsigned int ncollidingbunches,
441 lumi::Lumi2DB::LumiResult::iterator lumiBeg,
442 lumi::Lumi2DB::LumiResult::iterator lumiEnd) {
446 std::cout <<
"writeAllLumiDataToSchema2" << std::endl;
447 coral::AttributeList summaryData;
448 summaryData.extend(
"DATA_ID",
typeid(
unsigned long long));
449 summaryData.extend(
"RUNNUM",
typeid(
unsigned int));
450 summaryData.extend(
"LUMILSNUM",
typeid(
unsigned int));
451 summaryData.extend(
"CMSLSNUM",
typeid(
unsigned int));
452 summaryData.extend(
"INSTLUMI",
typeid(
float));
453 summaryData.extend(
"INSTLUMIERROR",
typeid(
float));
454 summaryData.extend(
"INSTLUMIQUALITY",
typeid(
short));
455 summaryData.extend(
"BEAMSTATUS",
typeid(
std::string));
456 summaryData.extend(
"BEAMENERGY",
typeid(
float));
457 summaryData.extend(
"NUMORBIT",
typeid(
unsigned int));
458 summaryData.extend(
"STARTORBIT",
typeid(
unsigned int));
459 summaryData.extend(
"CMSBXINDEXBLOB",
typeid(coral::Blob));
460 summaryData.extend(
"BEAMINTENSITYBLOB_1",
typeid(coral::Blob));
461 summaryData.extend(
"BEAMINTENSITYBLOB_2",
typeid(coral::Blob));
462 summaryData.extend(
"BXLUMIVALUE_OCC1",
typeid(coral::Blob));
463 summaryData.extend(
"BXLUMIERROR_OCC1",
typeid(coral::Blob));
464 summaryData.extend(
"BXLUMIQUALITY_OCC1",
typeid(coral::Blob));
465 summaryData.extend(
"BXLUMIVALUE_OCC2",
typeid(coral::Blob));
466 summaryData.extend(
"BXLUMIERROR_OCC2",
typeid(coral::Blob));
467 summaryData.extend(
"BXLUMIQUALITY_OCC2",
typeid(coral::Blob));
468 summaryData.extend(
"BXLUMIVALUE_ET",
typeid(coral::Blob));
469 summaryData.extend(
"BXLUMIERROR_ET",
typeid(coral::Blob));
470 summaryData.extend(
"BXLUMIQUALITY_ET",
typeid(coral::Blob));
472 unsigned long long& data_id = summaryData[
"DATA_ID"].data<
unsigned long long>();
473 unsigned int& lumirunnum = summaryData[
"RUNNUM"].data<
unsigned int>();
474 unsigned int& lumilsnr = summaryData[
"LUMILSNUM"].data<
unsigned int>();
475 unsigned int& cmslsnr = summaryData[
"CMSLSNUM"].data<
unsigned int>();
476 float& instlumi = summaryData[
"INSTLUMI"].data<
float>();
477 float& instlumierror = summaryData[
"INSTLUMIERROR"].data<
float>();
478 short& instlumiquality = summaryData[
"INSTLUMIQUALITY"].data<
short>();
480 float& beamenergy = summaryData[
"BEAMENERGY"].data<
float>();
481 unsigned int& numorbit = summaryData[
"NUMORBIT"].data<
unsigned int>();
482 unsigned int& startorbit = summaryData[
"STARTORBIT"].data<
unsigned int>();
483 coral::Blob& bxindex = summaryData[
"CMSBXINDEXBLOB"].data<coral::Blob>();
484 coral::Blob& beamintensity_1 = summaryData[
"BEAMINTENSITYBLOB_1"].data<coral::Blob>();
485 coral::Blob& beamintensity_2 = summaryData[
"BEAMINTENSITYBLOB_2"].data<coral::Blob>();
486 coral::Blob& bxlumivalue_et = summaryData[
"BXLUMIVALUE_ET"].data<coral::Blob>();
487 coral::Blob& bxlumierror_et = summaryData[
"BXLUMIERROR_ET"].data<coral::Blob>();
488 coral::Blob& bxlumiquality_et = summaryData[
"BXLUMIQUALITY_ET"].data<coral::Blob>();
489 coral::Blob& bxlumivalue_occ1 = summaryData[
"BXLUMIVALUE_OCC1"].data<coral::Blob>();
490 coral::Blob& bxlumierror_occ1 = summaryData[
"BXLUMIERROR_OCC1"].data<coral::Blob>();
491 coral::Blob& bxlumiquality_occ1 = summaryData[
"BXLUMIQUALITY_OCC1"].data<coral::Blob>();
492 coral::Blob& bxlumivalue_occ2 = summaryData[
"BXLUMIVALUE_OCC2"].data<coral::Blob>();
493 coral::Blob& bxlumierror_occ2 = summaryData[
"BXLUMIERROR_OCC2"].data<coral::Blob>();
494 coral::Blob& bxlumiquality_occ2 = summaryData[
"BXLUMIQUALITY_OCC2"].data<coral::Blob>();
496 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
497 coral::IBulkOperation* summaryInserter =
nullptr;
500 unsigned int lumiindx = 0;
501 unsigned int comittedls = 0;
503 unsigned long long branch_id = 3;
507 std::stringstream op;
510 session->transaction().start(
false);
514 lumirundata.
bgev = bgev;
522 std::cout <<
"it's a new run lumirundata revision_id " << lumirundata.
revision_id <<
" entry_id "
523 << lumirundata.
entry_id <<
" data_id " << lumirundata.
data_id << std::endl;
525 std::cout <<
"added entry " << std::endl;
529 <<
" data_id " << lumirundata.
data_id << std::endl;
534 for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt, ++lumiindx) {
535 if (!session->transaction().isActive()) {
536 session->transaction().start(
false);
538 summaryInserter = summarytable.dataEditor().bulkInsert(summaryData, totallumils);
540 if (lumiIt == lumiBeg) {
542 summaryInserter = summarytable.dataEditor().bulkInsert(summaryData, totallumils);
546 lumirunnum = irunnumber;
547 lumilsnr = lumiIt->lumilsnr;
548 cmslsnr = lumiIt->cmslsnr;
549 instlumi = lumiIt->instlumi;
550 instlumierror = lumiIt->instlumierror;
551 instlumiquality = lumiIt->instlumiquality;
552 beamstatus = lumiIt->beammode;
553 beamenergy = lumiIt->beamenergy;
554 numorbit = lumiIt->numorbit;
555 startorbit = lumiIt->startorbit;
556 short nlivebx = lumiIt->nlivebx;
559 bxindex.resize(
sizeof(
short) * nlivebx);
560 beamintensity_1.resize(
sizeof(
float) * nlivebx);
561 beamintensity_2.resize(
sizeof(
float) * nlivebx);
562 void* bxindex_StartAddress = bxindex.startingAddress();
563 void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
564 void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
565 std::memmove(bxindex_StartAddress, lumiIt->bxindex,
sizeof(
short) * nlivebx);
566 std::memmove(beamIntensity1_StartAddress, lumiIt->beamintensity_1,
sizeof(
float) * nlivebx);
567 std::memmove(beamIntensity2_StartAddress, lumiIt->beamintensity_2,
sizeof(
float) * nlivebx);
573 beamintensity_1.resize(0);
574 beamintensity_2.resize(0);
577 std::vector<PerBXData>::const_iterator bxIt;
578 std::vector<PerBXData>::const_iterator bxBeg;
579 std::vector<PerBXData>::const_iterator bxEnd;
582 bxBeg = lumiIt->bxET.begin();
583 bxEnd = lumiIt->bxET.end();
587 bxlumivalue_et.resize(
sizeof(
float) *
lumi::N_BX);
588 bxlumierror_et.resize(
sizeof(
float) * lumi::N_BX);
589 bxlumiquality_et.resize(
sizeof(
short) * lumi::N_BX);
590 void* bxlumivalueStartAddress = bxlumivalue_et.startingAddress();
591 void* bxlumierrorStartAddress = bxlumierror_et.startingAddress();
592 void* bxlumiqualityStartAddress = bxlumiquality_et.startingAddress();
594 for (bxIt = bxBeg; bxIt != bxEnd; ++bxIt, ++
k) {
595 lumivalue[
k] = bxIt->lumivalue;
596 lumierror[
k] = bxIt->lumierr;
597 lumiquality[
k] = bxIt->lumiquality;
599 std::memmove(bxlumivalueStartAddress, lumivalue,
sizeof(
float) * lumi::N_BX);
600 std::memmove(bxlumierrorStartAddress, lumierror,
sizeof(
float) * lumi::N_BX);
601 std::memmove(bxlumiqualityStartAddress, lumiquality,
sizeof(
short) * lumi::N_BX);
605 bxBeg = lumiIt->bxOCC1.begin();
606 bxEnd = lumiIt->bxOCC1.end();
610 bxlumivalue_occ1.resize(
sizeof(
float) *
lumi::N_BX);
611 bxlumierror_occ1.resize(
sizeof(
float) * lumi::N_BX);
612 bxlumiquality_occ1.resize(
sizeof(
short) * lumi::N_BX);
613 void* bxlumivalueStartAddress = bxlumivalue_occ1.startingAddress();
614 void* bxlumierrorStartAddress = bxlumierror_occ1.startingAddress();
615 void* bxlumiqualityStartAddress = bxlumiquality_occ1.startingAddress();
617 for (bxIt = bxBeg; bxIt != bxEnd; ++bxIt, ++
k) {
618 lumivalue[
k] = bxIt->lumivalue;
619 lumierror[
k] = bxIt->lumierr;
620 lumiquality[
k] = bxIt->lumiquality;
622 std::memmove(bxlumivalueStartAddress, lumivalue,
sizeof(
float) * lumi::N_BX);
623 std::memmove(bxlumierrorStartAddress, lumierror,
sizeof(
float) * lumi::N_BX);
624 std::memmove(bxlumiqualityStartAddress, lumiquality,
sizeof(
short) * lumi::N_BX);
628 bxBeg = lumiIt->bxOCC2.begin();
629 bxEnd = lumiIt->bxOCC2.end();
633 bxlumivalue_occ2.resize(
sizeof(
float) *
lumi::N_BX);
634 bxlumierror_occ2.resize(
sizeof(
float) * lumi::N_BX);
635 bxlumiquality_occ2.resize(
sizeof(
short) * lumi::N_BX);
636 void* bxlumivalueStartAddress = bxlumivalue_occ2.startingAddress();
637 void* bxlumierrorStartAddress = bxlumierror_occ2.startingAddress();
638 void* bxlumiqualityStartAddress = bxlumiquality_occ2.startingAddress();
640 for (bxIt = bxBeg; bxIt != bxEnd; ++bxIt, ++
k) {
641 lumivalue[
k] = bxIt->lumivalue;
642 lumierror[
k] = bxIt->lumierr;
643 lumiquality[
k] = bxIt->lumiquality;
645 std::memmove(bxlumivalueStartAddress, lumivalue,
sizeof(
float) * lumi::N_BX);
646 std::memmove(bxlumierrorStartAddress, lumierror,
sizeof(
float) * lumi::N_BX);
647 std::memmove(bxlumiqualityStartAddress, lumiquality,
sizeof(
short) * lumi::N_BX);
650 summaryInserter->processNextIteration();
651 summaryInserter->flush();
654 std::cout <<
"\t committing in LS chunck " << comittedls << std::endl;
655 delete summaryInserter;
656 summaryInserter =
nullptr;
657 session->transaction().commit();
659 std::cout <<
"\t committed " << std::endl;
660 }
else if (lumiindx == (totallumils - 1)) {
661 std::cout <<
"\t committing at the end" << std::endl;
662 delete summaryInserter;
663 summaryInserter =
nullptr;
664 session->transaction().commit();
672 lumi::Lumi2DB::LumiResult::iterator lumiEnd) {
673 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
674 for (lumiIt = lumiBeg; lumiIt != lumiEnd; ++lumiIt) {
675 ::free(lumiIt->bxindex);
676 ::free(lumiIt->beamintensity_1);
677 ::free(lumiIt->beamintensity_2);
683 if (m_source.length() == 0)
684 throw lumi::Exception(
"lumi source is not set",
"parseSourceString",
"Lumi2DB");
686 size_t tempIndex = m_source.find_last_of(
'.');
687 size_t nameLength = m_source.length();
688 std::string FileSuffix = m_source.substr(tempIndex + 1, nameLength - tempIndex);
691 std::vector<std::string>
pieces;
692 while (std::string::npos != pos || std::string::npos != lastPos) {
693 pieces.push_back(m_source.substr(lastPos, pos - lastPos));
694 lastPos = m_source.find_first_not_of(
'_', pos);
695 pos = m_source.find_first_of(
'_', lastPos);
697 if (pieces[1] !=
"LUMI" || pieces[2] !=
"RAW" || FileSuffix !=
"root") {
698 throw lumi::Exception(
"not lumi raw data file CMS_LUMI_RAW",
"parseSourceString",
"Lumi2DB");
700 std::strcpy(result.
datestr, pieces[3].c_str());
701 std::strcpy(result.
version, pieces[5].c_str());
703 result.
run = atoi(pieces[4].c_str());
710 if (dataPtr ==
nullptr) {
711 std::cout <<
"HCAL_HLX::DIP_COMBINED_DATA* dataPtr=0" << std::endl;
752 unsigned int lumidataid = 0;
754 parseSourceString(filenamecontent);
759 if (filenamecontent.
run != runnumber) {
760 throw lumi::Exception(
"runnumber in file name does not match requested run number",
"retrieveData",
"Lumi2DB");
762 TFile*
source = TFile::Open(m_source.c_str(),
"READ");
763 TTree* hlxtree = (TTree*)source->Get(
"HLXData");
773 hlxtree->SetBranchAddress(
"Header.", &lumiheader);
774 hlxtree->SetBranchAddress(
"Summary.", &lumisummary);
775 hlxtree->SetBranchAddress(
"Detail.", &lumidetail);
777 size_t nentries = hlxtree->GetEntries();
778 unsigned int nstablebeam = 0;
781 std::map<unsigned int, Lumi2DB::beamData> dipmap;
782 TTree* diptree = (TTree*)source->Get(
"DIPCombined");
786 diptree->SetBranchAddress(
"DIPCombined.", &dipdata);
787 size_t ndipentries = diptree->GetEntries();
788 for (
size_t i = 0;
i < ndipentries; ++
i) {
789 diptree->GetEntry(
i);
803 unsigned int dipls = dipdata->sectionNumber;
807 b.
mode = dipdata->beamMode;
809 b.
energy = dipdata->Energy;
810 if (b.
mode ==
"STABLE BEAMS") {
814 this->retrieveBeamIntensity(dipdata.get(),
b);
815 dipmap.insert(std::make_pair(dipls, b));
818 for (
size_t i = 0;
i < nentries; ++
i) {
822 this->retrieveBeamIntensity(
nullptr, b);
823 dipmap.insert(std::make_pair(
i, b));
829 std::cout <<
"processing total lumi lumisection " << nentries << std::endl;
836 unsigned int ncollidingbunches = 0;
837 for (
size_t i = 0;
i < nentries; ++
i) {
840 hlxtree->GetEntry(
i);
857 std::map<unsigned int, Lumi2DB::beamData>::iterator beamIt = dipmap.find(h.
lumilsnr);
858 if (beamIt != dipmap.end()) {
861 h.
nlivebx = beamIt->second.nlivebx;
867 std::cout <<
"malloc failed" << std::endl;
873 std::memmove(h.
bxindex, beamIt->second.bxindex,
sizeof(
short) * h.
nlivebx);
877 ::free(beamIt->second.bxindex);
878 beamIt->second.bxindex =
nullptr;
879 ::free(beamIt->second.beamintensity_1);
880 beamIt->second.beamintensity_1 =
nullptr;
881 ::free(beamIt->second.beamintensity_2);
882 beamIt->second.beamintensity_2 =
nullptr;
920 h.
bxET.push_back(bET);
933 h.
bxOCC1.push_back(bOCC1);
939 h.
bxOCC2.push_back(bOCC2);
941 lumiresult.push_back(h);
944 if (nstablebeam != 0) {
945 bgev = bgev / nstablebeam;
947 std::cout <<
"avg stable beam energy " << bgev << std::endl;
948 if (!m_novalidate && !isLumiDataValid(lumiresult.begin(), lumiresult.end())) {
951 if (!m_nocheckingstablebeam && !hasStableBeam(lumiresult.begin(), lumiresult.end())) {
954 coral::ConnectionService* svc =
new coral::ConnectionService;
956 if (!m_authpath.empty()) {
959 coral::ISessionProxy*
session = svc->connect(m_dest, coral::Update);
960 coral::ITypeConverter& tpc = session->typeConverter();
961 tpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
968 std::cout <<
"writing beam intensity only to old lumisummary table " << std::endl;
969 writeBeamIntensityOnly(session, runnumber, lversion, lumiresult.begin(), lumiresult.end());
972 if (m_mode ==
"loadoldschema") {
973 std::cout <<
"writing all lumi data to old lumisummary table " << std::endl;
974 writeAllLumiData(session, runnumber, lversion, lumiresult.begin(), lumiresult.end());
978 std::cout <<
"writing all lumi data to lumisummary_V2 table " << std::endl;
979 lumidataid = writeAllLumiDataToSchema2(
980 session, m_source, runnumber, bgev, ncollidingbunches, lumiresult.begin(), lumiresult.end());
982 cleanTemporaryMemory(lumiresult.begin(), lumiresult.end());
986 std::cout <<
"database error " << er.what() << std::endl;
987 session->transaction().rollback();
char const * what() const override
std::vector< PerLumiData > LumiResult
void parseSourceString(lumi::Lumi2DB::LumiSource &result) const
const std::string dataType() const override
void writeBeamIntensityOnly(coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
void addEntry(coral::ISchema &schema, const std::string &datatableName, const Entry &entry, unsigned long long branch_id, const std::string &branchname)
bool hasStableBeam(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
const unsigned int N_LUMIALGO
float DeadTimeNormalization
static const unsigned int COMMITLSINTERVAL
int16_t OccLumiQlty[2][4096]
std::vector< PerBXData > bxOCC2
unsigned int firstsection
void insertLumiRunData(coral::ISchema &schema, const LumiEntry &lumientry)
unsigned long long data_id
void setAuthentication(const std::string &authPath)
unsigned long long getEntryInBranchByName(coral::ISchema &schema, const std::string &datatableName, const std::string &entryname, const std::string &branchname)
static const std::string lumisummaryTableName()
float applyCalibration(float varToCalibrate) const
Lumi2DB(const std::string &dest)
float OccLumiErr[2][4096]
unsigned long long revision_id
void cleanTemporaryMemory(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
void retrieveBeamIntensity(HCAL_HLX::DIP_COMBINED_DATA *dataPtr, Lumi2DB::beamData &b) const
unsigned int writeAllLumiDataToSchema2(coral::ISessionProxy *session, const std::string &source, unsigned int runnumber, float bgev, unsigned int ncollidingbunches, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
static const std::string lumidataTableName()
unsigned long long entry_id
void bookNewEntry(coral::ISchema &schema, const std::string &datatableName, Entry &entry)
const std::string sourceType() const override
static const std::string lumidetailTableName()
unsigned int ncollidingbunches
static const std::string lumisummaryv2TableName()
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
std::vector< PerBXData > bxOCC1
float averageBunchIntensities[3564]
bool isLumiDataValid(LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
void writeAllLumiData(coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
#define DEFINE_EDM_PLUGIN(factory, type, name)
void addRevision(coral::ISchema &schema, const std::string &datatableName, const Entry &revision, unsigned long long branch_id, std::string &branchname)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
unsigned long long retrieveData(unsigned int) override
static std::string const source
std::vector< PerBXData > bxET
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)