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"
37 virtual unsigned long long retrieveData(
unsigned int )
override;
72 std::vector<PerBXData>
bxET;
85 bool hasStableBeam( lumi::Lumi2DB::LumiResult::iterator lumiBeg,lumi::Lumi2DB::LumiResult::iterator lumiEnd );
89 void writeAllLumiData(coral::ISessionProxy*
session,
unsigned int irunnumber,
const std::string& ilumiversion,LumiResult::iterator lumiBeg,LumiResult::iterator lumiEnd);
92 bool isLumiDataValid(LumiResult::iterator lumiBeg,LumiResult::iterator lumiEnd);
94 void cleanTemporaryMemory( lumi::Lumi2DB::LumiResult::iterator lumiBeg,lumi::Lumi2DB::LumiResult::iterator lumiEnd);
103 return float(varToCalibrate)*
m_norm;
110 lumi::Lumi2DB::LumiResult::iterator lumiIt;
112 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt){
113 if(lumiIt->beammode==
"STABLE BEAMS"){
127 lumi::Lumi2DB::LumiResult::iterator lumiIt;
129 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt){
131 if(lumiIt->instlumi<=0.5e-8){
135 if(nBad==std::distance(lumiBeg,lumiEnd)){
143 unsigned int irunnumber,
145 lumi::Lumi2DB::LumiResult::iterator lumiBeg,
146 lumi::Lumi2DB::LumiResult::iterator lumiEnd
149 inputData.extend(
"bxindex",
typeid(coral::Blob));
150 inputData.extend(
"beamintensity_1",
typeid(coral::Blob));
151 inputData.extend(
"beamintensity_2",
typeid(coral::Blob));
152 inputData.extend(
"runnum",
typeid(
unsigned int));
153 inputData.extend(
"startorbit",
typeid(
unsigned int));
154 inputData.extend(
"lumiversion",
typeid(
std::string));
155 coral::Blob& bxindex = inputData[
"bxindex"].data<coral::Blob>();
156 coral::Blob& beamintensity_1 = inputData[
"beamintensity_1"].data<coral::Blob>();
157 coral::Blob& beamintensity_2 = inputData[
"beamintensity_2"].data<coral::Blob>();
158 unsigned int&
runnumber = inputData[
"runnum"].data<
unsigned int>();
159 unsigned int& startorbit = inputData[
"startorbit"].data<
unsigned int>();
162 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
163 coral::IBulkOperation* summaryUpdater=0;
164 unsigned int totallumils=std::distance(lumiBeg,lumiEnd);
165 unsigned int lumiindx=0;
166 unsigned int comittedls=0;
167 std::string setClause(
"CMSBXINDEXBLOB=:bxindex,BEAMINTENSITYBLOB_1=:beamintensity_1,BEAMINTENSITYBLOB_2=:beamintensity_2");
168 std::string condition(
"RUNNUM=:runnum AND STARTORBIT=:startorbit AND LUMIVERSION=:lumiversion");
169 runnumber=irunnumber;
170 lumiversion=ilumiversion;
171 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx){
172 if(!session->transaction().isActive()){
173 session->transaction().start(
false);
175 startorbit=lumiIt->startorbit;
177 short nlivebx=lumiIt->nlivebx;
179 bxindex.resize(
sizeof(
short)*nlivebx);
180 beamintensity_1.resize(
sizeof(
float)*nlivebx);
181 beamintensity_2.resize(
sizeof(
float)*nlivebx);
182 void* bxindex_StartAddress = bxindex.startingAddress();
183 void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
184 void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
185 std::memmove(bxindex_StartAddress,lumiIt->bxindex,
sizeof(
short)*nlivebx);
186 std::memmove(beamIntensity1_StartAddress,lumiIt->beamintensity_1,
sizeof(
float)*nlivebx);
187 std::memmove(beamIntensity2_StartAddress,lumiIt->beamintensity_2,
sizeof(
float)*nlivebx);
188 ::free(lumiIt->bxindex);
189 ::free(lumiIt->beamintensity_1);
190 ::free(lumiIt->beamintensity_2);
193 beamintensity_1.resize(0);
194 beamintensity_2.resize(0);
197 summaryUpdater=summarytable.dataEditor().bulkUpdateRows(setClause,condition,inputData,totallumils);
198 summaryUpdater->processNextIteration();
199 summaryUpdater->flush();
202 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
203 delete summaryUpdater;
205 session->transaction().commit();
208 }
else if( lumiindx==(totallumils-1) ){
209 std::cout<<
"\t committing at the end"<<std::endl;
210 delete summaryUpdater; summaryUpdater=0;
211 session->transaction().commit();
219 unsigned int irunnumber,
221 lumi::Lumi2DB::LumiResult::iterator lumiBeg,
222 lumi::Lumi2DB::LumiResult::iterator lumiEnd ){
223 coral::AttributeList summaryData;
224 coral::AttributeList detailData;
225 summaryData.extend(
"LUMISUMMARY_ID",
typeid(
unsigned long long));
226 summaryData.extend(
"RUNNUM",
typeid(
unsigned int));
227 summaryData.extend(
"CMSLSNUM",
typeid(
unsigned int));
228 summaryData.extend(
"LUMILSNUM",
typeid(
unsigned int));
229 summaryData.extend(
"LUMIVERSION",
typeid(
std::string));
230 summaryData.extend(
"DTNORM",
typeid(
float));
231 summaryData.extend(
"LHCNORM",
typeid(
float));
232 summaryData.extend(
"INSTLUMI",
typeid(
float));
233 summaryData.extend(
"INSTLUMIERROR",
typeid(
float));
234 summaryData.extend(
"INSTLUMIQUALITY",
typeid(
short));
235 summaryData.extend(
"LUMISECTIONQUALITY",
typeid(
short));
236 summaryData.extend(
"CMSALIVE",
typeid(
short));
237 summaryData.extend(
"STARTORBIT",
typeid(
unsigned int));
238 summaryData.extend(
"NUMORBIT",
typeid(
unsigned int));
239 summaryData.extend(
"BEAMENERGY",
typeid(
float));
240 summaryData.extend(
"BEAMSTATUS",
typeid(
std::string));
241 summaryData.extend(
"CMSBXINDEXBLOB",
typeid(coral::Blob));
242 summaryData.extend(
"BEAMINTENSITYBLOB_1",
typeid(coral::Blob));
243 summaryData.extend(
"BEAMINTENSITYBLOB_2",
typeid(coral::Blob));
245 detailData.extend(
"LUMIDETAIL_ID",
typeid(
unsigned long long));
246 detailData.extend(
"LUMISUMMARY_ID",
typeid(
unsigned long long));
247 detailData.extend(
"BXLUMIVALUE",
typeid(coral::Blob));
248 detailData.extend(
"BXLUMIERROR",
typeid(coral::Blob));
249 detailData.extend(
"BXLUMIQUALITY",
typeid(coral::Blob));
252 unsigned long long& lumisummary_id=summaryData[
"LUMISUMMARY_ID"].data<
unsigned long long>();
253 unsigned int& lumirunnum = summaryData[
"RUNNUM"].data<
unsigned int>();
255 float& dtnorm = summaryData[
"DTNORM"].data<
float>();
256 float& lhcnorm = summaryData[
"LHCNORM"].data<
float>();
257 float& instlumi = summaryData[
"INSTLUMI"].data<
float>();
258 float& instlumierror = summaryData[
"INSTLUMIERROR"].data<
float>();
259 short& instlumiquality = summaryData[
"INSTLUMIQUALITY"].data<
short>();
260 short& lumisectionquality = summaryData[
"LUMISECTIONQUALITY"].data<
short>();
261 short& alive = summaryData[
"CMSALIVE"].data<
short>();
262 unsigned int& lumilsnr = summaryData[
"LUMILSNUM"].data<
unsigned int>();
263 unsigned int& cmslsnr = summaryData[
"CMSLSNUM"].data<
unsigned int>();
264 unsigned int& startorbit = summaryData[
"STARTORBIT"].data<
unsigned int>();
265 unsigned int& numorbit = summaryData[
"NUMORBIT"].data<
unsigned int>();
266 float& beamenergy = summaryData[
"BEAMENERGY"].data<
float>();
268 coral::Blob& bxindex = summaryData[
"CMSBXINDEXBLOB"].data<coral::Blob>();
269 coral::Blob& beamintensity_1 = summaryData[
"BEAMINTENSITYBLOB_1"].data<coral::Blob>();
270 coral::Blob& beamintensity_2 = summaryData[
"BEAMINTENSITYBLOB_2"].data<coral::Blob>();
272 unsigned long long& lumidetail_id=detailData[
"LUMIDETAIL_ID"].data<
unsigned long long>();
273 unsigned long long& d2lumisummary_id=detailData[
"LUMISUMMARY_ID"].data<
unsigned long long>();
274 coral::Blob& bxlumivalue=detailData[
"BXLUMIVALUE"].data<coral::Blob>();
275 coral::Blob& bxlumierror=detailData[
"BXLUMIERROR"].data<coral::Blob>();
276 coral::Blob& bxlumiquality=detailData[
"BXLUMIQUALITY"].data<coral::Blob>();
279 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
280 coral::IBulkOperation* summaryInserter=0;
281 coral::IBulkOperation* detailInserter=0;
284 unsigned int totallumils=std::distance(lumiBeg,lumiEnd);
285 unsigned int lumiindx=0;
286 std::map< unsigned long long,std::vector<unsigned long long> > idallocationtable;
287 std::cout<<
"\t allocating total lumisummary ids "<<totallumils<<std::endl;
290 session->transaction().start(
false);
294 session->transaction().commit();
295 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx,++lumisummaryID){
296 std::vector< unsigned long long > allIDs;
297 allIDs.reserve(1+lumi::N_LUMIALGO);
298 allIDs.push_back(lumisummaryID);
300 allIDs.push_back(lumidetailID);
302 idallocationtable.insert(std::make_pair(lumiindx,allIDs));
304 std::cout<<
"\t all ids allocated"<<std::endl;
306 unsigned int comittedls=0;
307 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx){
308 if(!session->transaction().isActive()){
309 session->transaction().start(
false);
311 summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
313 detailInserter=detailtable.dataEditor().bulkInsert(detailData,totallumils*lumi::N_LUMIALGO);
315 lumisummary_id=idallocationtable[lumiindx][0];
316 lumirunnum = irunnumber;
317 lumiversion = ilumiversion;
318 dtnorm = lumiIt->dtnorm;
319 lhcnorm = lumiIt->lhcnorm;
322 instlumi = applyCalibration(lumiIt->instlumi);
323 instlumierror = applyCalibration(lumiIt->instlumierror);
324 instlumiquality = lumiIt->instlumiquality;
325 lumisectionquality = lumiIt->lumisectionquality;
326 alive = lumiIt->cmsalive;
327 cmslsnr = lumiIt->cmslsnr;
329 lumilsnr = lumiIt->lumilsnr;
330 startorbit = lumiIt->startorbit;
331 numorbit = lumiIt->numorbit;
332 beamenergy = lumiIt->beamenergy;
333 beamstatus = lumiIt->beammode;
334 short nlivebx=lumiIt->nlivebx;
337 bxindex.resize(
sizeof(
short)*nlivebx);
338 beamintensity_1.resize(
sizeof(
float)*nlivebx);
339 beamintensity_2.resize(
sizeof(
float)*nlivebx);
340 void* bxindex_StartAddress = bxindex.startingAddress();
341 void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
342 void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
343 std::memmove(bxindex_StartAddress,lumiIt->bxindex,
sizeof(
short)*nlivebx);
344 std::memmove(beamIntensity1_StartAddress,lumiIt->beamintensity_1,
sizeof(
float)*nlivebx);
345 std::memmove(beamIntensity2_StartAddress,lumiIt->beamintensity_2,
sizeof(
float)*nlivebx);
351 beamintensity_1.resize(0);
352 beamintensity_2.resize(0);
355 summaryInserter->processNextIteration();
356 summaryInserter->flush();
357 unsigned int algoindx=1;
359 d2lumisummary_id=idallocationtable[lumiindx].at(0);
360 lumidetail_id=idallocationtable[lumiindx].at(algoindx);
361 std::vector<PerBXData>::const_iterator bxIt;
362 std::vector<PerBXData>::const_iterator bxBeg;
363 std::vector<PerBXData>::const_iterator bxEnd;
366 bxBeg=lumiIt->bxET.begin();
367 bxEnd=lumiIt->bxET.end();
371 bxBeg=lumiIt->bxOCC1.begin();
372 bxEnd=lumiIt->bxOCC1.end();
376 bxBeg=lumiIt->bxOCC2.begin();
377 bxEnd=lumiIt->bxOCC2.end();
383 bxlumierror.resize(
sizeof(
float)*lumi::N_BX);
384 bxlumiquality.resize(
sizeof(
short)*lumi::N_BX);
385 void* bxlumivalueStartAddress=bxlumivalue.startingAddress();
386 void* bxlumierrorStartAddress=bxlumierror.startingAddress();
387 void* bxlumiqualityStartAddress=bxlumiquality.startingAddress();
389 for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++
k ){
390 lumivalue[
k]=bxIt->lumivalue;
391 lumierror[
k]=bxIt->lumierr;
392 lumiquality[
k]=bxIt->lumiquality;
394 std::memmove(bxlumivalueStartAddress,lumivalue,
sizeof(
float)*lumi::N_BX);
395 std::memmove(bxlumierrorStartAddress,lumierror,
sizeof(
float)*lumi::N_BX);
396 std::memmove(bxlumiqualityStartAddress,lumiquality,
sizeof(
short)*lumi::N_BX);
397 detailInserter->processNextIteration();
399 detailInserter->flush();
402 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
403 delete summaryInserter;
405 delete detailInserter;
407 session->transaction().commit();
410 }
else if( lumiindx==(totallumils-1) ){
411 std::cout<<
"\t committing at the end"<<std::endl;
412 delete summaryInserter; summaryInserter=0;
413 delete detailInserter; detailInserter=0;
414 session->transaction().commit();
424 unsigned int irunnumber,
426 unsigned int ncollidingbunches,
427 lumi::Lumi2DB::LumiResult::iterator lumiBeg,
428 lumi::Lumi2DB::LumiResult::iterator lumiEnd ){
432 std::cout<<
"writeAllLumiDataToSchema2"<<std::endl;
433 coral::AttributeList summaryData;
434 summaryData.extend(
"DATA_ID",
typeid(
unsigned long long));
435 summaryData.extend(
"RUNNUM",
typeid(
unsigned int));
436 summaryData.extend(
"LUMILSNUM",
typeid(
unsigned int));
437 summaryData.extend(
"CMSLSNUM",
typeid(
unsigned int));
438 summaryData.extend(
"INSTLUMI",
typeid(
float));
439 summaryData.extend(
"INSTLUMIERROR",
typeid(
float));
440 summaryData.extend(
"INSTLUMIQUALITY",
typeid(
short));
441 summaryData.extend(
"BEAMSTATUS",
typeid(
std::string));
442 summaryData.extend(
"BEAMENERGY",
typeid(
float));
443 summaryData.extend(
"NUMORBIT",
typeid(
unsigned int));
444 summaryData.extend(
"STARTORBIT",
typeid(
unsigned int));
445 summaryData.extend(
"CMSBXINDEXBLOB",
typeid(coral::Blob));
446 summaryData.extend(
"BEAMINTENSITYBLOB_1",
typeid(coral::Blob));
447 summaryData.extend(
"BEAMINTENSITYBLOB_2",
typeid(coral::Blob));
448 summaryData.extend(
"BXLUMIVALUE_OCC1",
typeid(coral::Blob));
449 summaryData.extend(
"BXLUMIERROR_OCC1",
typeid(coral::Blob));
450 summaryData.extend(
"BXLUMIQUALITY_OCC1",
typeid(coral::Blob));
451 summaryData.extend(
"BXLUMIVALUE_OCC2",
typeid(coral::Blob));
452 summaryData.extend(
"BXLUMIERROR_OCC2",
typeid(coral::Blob));
453 summaryData.extend(
"BXLUMIQUALITY_OCC2",
typeid(coral::Blob));
454 summaryData.extend(
"BXLUMIVALUE_ET",
typeid(coral::Blob));
455 summaryData.extend(
"BXLUMIERROR_ET",
typeid(coral::Blob));
456 summaryData.extend(
"BXLUMIQUALITY_ET",
typeid(coral::Blob));
458 unsigned long long& data_id=summaryData[
"DATA_ID"].data<
unsigned long long>();
459 unsigned int& lumirunnum = summaryData[
"RUNNUM"].data<
unsigned int>();
460 unsigned int& lumilsnr = summaryData[
"LUMILSNUM"].data<
unsigned int>();
461 unsigned int& cmslsnr = summaryData[
"CMSLSNUM"].data<
unsigned int>();
462 float& instlumi = summaryData[
"INSTLUMI"].data<
float>();
463 float& instlumierror = summaryData[
"INSTLUMIERROR"].data<
float>();
464 short& instlumiquality = summaryData[
"INSTLUMIQUALITY"].data<
short>();
466 float& beamenergy = summaryData[
"BEAMENERGY"].data<
float>();
467 unsigned int& numorbit = summaryData[
"NUMORBIT"].data<
unsigned int>();
468 unsigned int& startorbit = summaryData[
"STARTORBIT"].data<
unsigned int>();
469 coral::Blob& bxindex = summaryData[
"CMSBXINDEXBLOB"].data<coral::Blob>();
470 coral::Blob& beamintensity_1 = summaryData[
"BEAMINTENSITYBLOB_1"].data<coral::Blob>();
471 coral::Blob& beamintensity_2 = summaryData[
"BEAMINTENSITYBLOB_2"].data<coral::Blob>();
472 coral::Blob& bxlumivalue_et=summaryData[
"BXLUMIVALUE_ET"].data<coral::Blob>();
473 coral::Blob& bxlumierror_et=summaryData[
"BXLUMIERROR_ET"].data<coral::Blob>();
474 coral::Blob& bxlumiquality_et=summaryData[
"BXLUMIQUALITY_ET"].data<coral::Blob>();
475 coral::Blob& bxlumivalue_occ1=summaryData[
"BXLUMIVALUE_OCC1"].data<coral::Blob>();
476 coral::Blob& bxlumierror_occ1=summaryData[
"BXLUMIERROR_OCC1"].data<coral::Blob>();
477 coral::Blob& bxlumiquality_occ1=summaryData[
"BXLUMIQUALITY_OCC1"].data<coral::Blob>();
478 coral::Blob& bxlumivalue_occ2=summaryData[
"BXLUMIVALUE_OCC2"].data<coral::Blob>();
479 coral::Blob& bxlumierror_occ2=summaryData[
"BXLUMIERROR_OCC2"].data<coral::Blob>();
480 coral::Blob& bxlumiquality_occ2=summaryData[
"BXLUMIQUALITY_OCC2"].data<coral::Blob>();
482 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
483 coral::IBulkOperation* summaryInserter=0;
485 unsigned int totallumils=std::distance(lumiBeg,lumiEnd);
486 unsigned int lumiindx=0;
487 unsigned int comittedls=0;
489 unsigned long long branch_id=3;
493 std::stringstream op;
496 session->transaction().start(
false);
500 lumirundata.
bgev=bgev;
516 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx){
517 if(!session->transaction().isActive()){
518 session->transaction().start(
false);
520 summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
524 summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
528 lumirunnum = irunnumber;
529 lumilsnr = lumiIt->lumilsnr;
530 cmslsnr = lumiIt->cmslsnr;
531 instlumi = lumiIt->instlumi;
532 instlumierror = lumiIt->instlumierror;
533 instlumiquality = lumiIt->instlumiquality;
534 beamstatus = lumiIt->beammode;
535 beamenergy = lumiIt->beamenergy;
536 numorbit = lumiIt->numorbit;
537 startorbit = lumiIt->startorbit;
538 short nlivebx=lumiIt->nlivebx;
541 bxindex.resize(
sizeof(
short)*nlivebx);
542 beamintensity_1.resize(
sizeof(
float)*nlivebx);
543 beamintensity_2.resize(
sizeof(
float)*nlivebx);
544 void* bxindex_StartAddress = bxindex.startingAddress();
545 void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
546 void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
547 std::memmove(bxindex_StartAddress,lumiIt->bxindex,
sizeof(
short)*nlivebx);
548 std::memmove(beamIntensity1_StartAddress,lumiIt->beamintensity_1,
sizeof(
float)*nlivebx);
549 std::memmove(beamIntensity2_StartAddress,lumiIt->beamintensity_2,
sizeof(
float)*nlivebx);
555 beamintensity_1.resize(0);
556 beamintensity_2.resize(0);
559 std::vector<PerBXData>::const_iterator bxIt;
560 std::vector<PerBXData>::const_iterator bxBeg;
561 std::vector<PerBXData>::const_iterator bxEnd;
564 bxBeg=lumiIt->bxET.begin();
565 bxEnd=lumiIt->bxET.end();
569 bxlumivalue_et.resize(
sizeof(
float)*
lumi::N_BX);
570 bxlumierror_et.resize(
sizeof(
float)*lumi::N_BX);
571 bxlumiquality_et.resize(
sizeof(
short)*lumi::N_BX);
572 void* bxlumivalueStartAddress=bxlumivalue_et.startingAddress();
573 void* bxlumierrorStartAddress=bxlumierror_et.startingAddress();
574 void* bxlumiqualityStartAddress=bxlumiquality_et.startingAddress();
576 for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++
k ){
577 lumivalue[
k]=bxIt->lumivalue;
578 lumierror[
k]=bxIt->lumierr;
579 lumiquality[
k]=bxIt->lumiquality;
581 std::memmove(bxlumivalueStartAddress,lumivalue,
sizeof(
float)*lumi::N_BX);
582 std::memmove(bxlumierrorStartAddress,lumierror,
sizeof(
float)*lumi::N_BX);
583 std::memmove(bxlumiqualityStartAddress,lumiquality,
sizeof(
short)*lumi::N_BX);
587 bxBeg=lumiIt->bxOCC1.begin();
588 bxEnd=lumiIt->bxOCC1.end();
592 bxlumivalue_occ1.resize(
sizeof(
float)*
lumi::N_BX);
593 bxlumierror_occ1.resize(
sizeof(
float)*lumi::N_BX);
594 bxlumiquality_occ1.resize(
sizeof(
short)*lumi::N_BX);
595 void* bxlumivalueStartAddress=bxlumivalue_occ1.startingAddress();
596 void* bxlumierrorStartAddress=bxlumierror_occ1.startingAddress();
597 void* bxlumiqualityStartAddress=bxlumiquality_occ1.startingAddress();
599 for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++
k ){
600 lumivalue[
k]=bxIt->lumivalue;
601 lumierror[
k]=bxIt->lumierr;
602 lumiquality[
k]=bxIt->lumiquality;
604 std::memmove(bxlumivalueStartAddress,lumivalue,
sizeof(
float)*lumi::N_BX);
605 std::memmove(bxlumierrorStartAddress,lumierror,
sizeof(
float)*lumi::N_BX);
606 std::memmove(bxlumiqualityStartAddress,lumiquality,
sizeof(
short)*lumi::N_BX);
610 bxBeg=lumiIt->bxOCC2.begin();
611 bxEnd=lumiIt->bxOCC2.end();
615 bxlumivalue_occ2.resize(
sizeof(
float)*
lumi::N_BX);
616 bxlumierror_occ2.resize(
sizeof(
float)*lumi::N_BX);
617 bxlumiquality_occ2.resize(
sizeof(
short)*lumi::N_BX);
618 void* bxlumivalueStartAddress=bxlumivalue_occ2.startingAddress();
619 void* bxlumierrorStartAddress=bxlumierror_occ2.startingAddress();
620 void* bxlumiqualityStartAddress=bxlumiquality_occ2.startingAddress();
622 for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++
k ){
623 lumivalue[
k]=bxIt->lumivalue;
624 lumierror[
k]=bxIt->lumierr;
625 lumiquality[
k]=bxIt->lumiquality;
627 std::memmove(bxlumivalueStartAddress,lumivalue,
sizeof(
float)*lumi::N_BX);
628 std::memmove(bxlumierrorStartAddress,lumierror,
sizeof(
float)*lumi::N_BX);
629 std::memmove(bxlumiqualityStartAddress,lumiquality,
sizeof(
short)*lumi::N_BX);
632 summaryInserter->processNextIteration();
633 summaryInserter->flush();
636 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
637 delete summaryInserter;
639 session->transaction().commit();
642 }
else if( lumiindx==(totallumils-1) ){
643 std::cout<<
"\t committing at the end"<<std::endl;
644 delete summaryInserter; summaryInserter=0;
645 session->transaction().commit();
653 lumi::Lumi2DB::LumiResult::iterator lumiEnd){
654 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
655 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt){
656 ::free(lumiIt->bxindex);
657 ::free(lumiIt->beamintensity_1);
658 ::free(lumiIt->beamintensity_2);
666 if(m_source.length()==0)
throw lumi::Exception(
"lumi source is not set",
"parseSourceString",
"Lumi2DB");
668 size_t tempIndex = m_source.find_last_of(
".");
669 size_t nameLength = m_source.length();
670 std::string FileSuffix= m_source.substr(tempIndex+1,nameLength - tempIndex);
673 std::vector<std::string>
pieces;
674 while( std::string::npos != pos || std::string::npos != lastPos){
675 pieces.push_back(m_source.substr(lastPos,pos-lastPos));
676 lastPos=m_source.find_first_not_of(
"_",pos);
677 pos=m_source.find_first_of(
"_",lastPos);
679 if( pieces[1]!=
"LUMI" || pieces[2]!=
"RAW" || FileSuffix!=
"root"){
680 throw lumi::Exception(
"not lumi raw data file CMS_LUMI_RAW",
"parseSourceString",
"Lumi2DB");
682 std::strcpy(result.
datestr,pieces[3].c_str());
683 std::strcpy(result.
version,pieces[5].c_str());
685 result.
run = atoi(pieces[4].c_str());
694 std::cout<<
"HCAL_HLX::DIP_COMBINED_DATA* dataPtr=0"<<std::endl;
736 unsigned int lumidataid=0;
738 parseSourceString(filenamecontent);
743 if( filenamecontent.
run!=runnumber ){
744 throw lumi::Exception(
"runnumber in file name does not match requested run number",
"retrieveData",
"Lumi2DB");
746 TFile*
source=TFile::Open(m_source.c_str(),
"READ");
747 TTree *hlxtree = (TTree*)source->Get(
"HLXData");
757 hlxtree->SetBranchAddress(
"Header.",&lumiheader);
758 hlxtree->SetBranchAddress(
"Summary.",&lumisummary);
759 hlxtree->SetBranchAddress(
"Detail.",&lumidetail);
761 size_t nentries=hlxtree->GetEntries();
762 unsigned int nstablebeam=0;
765 std::map<unsigned int, Lumi2DB::beamData> dipmap;
766 TTree *diptree= (TTree*)source->Get(
"DIPCombined");
770 diptree->SetBranchAddress(
"DIPCombined.",&dipdata);
771 size_t ndipentries=diptree->GetEntries();
772 for(
size_t i=0;
i<ndipentries;++
i){
773 diptree->GetEntry(
i);
787 unsigned int dipls=dipdata->sectionNumber;
791 b.
mode=dipdata->beamMode;
794 if(b.
mode==
"STABLE BEAMS"){
798 this->retrieveBeamIntensity(dipdata.get(),
b);
799 dipmap.insert(std::make_pair(dipls,b));
802 for(
size_t i=0;
i<nentries;++
i){
806 this->retrieveBeamIntensity(0,b);
807 dipmap.insert(std::make_pair(
i,b));
813 std::cout<<
"processing total lumi lumisection "<<nentries<<std::endl;
820 unsigned int ncollidingbunches=0;
821 for(
size_t i=0;
i<nentries;++
i){
824 hlxtree->GetEntry(
i);
841 std::map<unsigned int , Lumi2DB::beamData >::iterator beamIt=dipmap.find(h.
lumilsnr);
842 if ( beamIt!=dipmap.end() ){
845 h.
nlivebx=beamIt->second.nlivebx;
857 std::memmove(h.
bxindex,beamIt->second.bxindex,
sizeof(
short)*h.
nlivebx);
861 ::free(beamIt->second.bxindex);beamIt->second.bxindex=0;
862 ::free(beamIt->second.beamintensity_1);beamIt->second.beamintensity_1=0;
863 ::free(beamIt->second.beamintensity_2);beamIt->second.beamintensity_2=0;
901 h.
bxET.push_back(bET);
914 h.
bxOCC1.push_back(bOCC1);
920 h.
bxOCC2.push_back(bOCC2);
922 lumiresult.push_back(h);
926 bgev=bgev/nstablebeam;
928 std::cout<<
"avg stable beam energy "<<bgev<<std::endl;
929 if( !m_novalidate && !isLumiDataValid(lumiresult.begin(),lumiresult.end()) ){
932 if( !m_nocheckingstablebeam && !hasStableBeam(lumiresult.begin(),lumiresult.end()) ){
935 coral::ConnectionService*
svc=
new coral::ConnectionService;
937 if(!m_authpath.empty()){
940 coral::ISessionProxy*
session=svc->connect(m_dest,coral::Update);
941 coral::ITypeConverter& tpc=session->typeConverter();
942 tpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
949 std::cout<<
"writing beam intensity only to old lumisummary table "<<std::endl;
950 writeBeamIntensityOnly(session,runnumber,lversion,lumiresult.begin(),lumiresult.end());
953 if(m_mode==
"loadoldschema"){
954 std::cout<<
"writing all lumi data to old lumisummary table "<<std::endl;
955 writeAllLumiData(session,runnumber,lversion,lumiresult.begin(),lumiresult.end());
959 std::cout<<
"writing all lumi data to lumisummary_V2 table "<<std::endl;
960 lumidataid=writeAllLumiDataToSchema2(session,m_source,runnumber,bgev,ncollidingbunches,lumiresult.begin(),lumiresult.end());
962 cleanTemporaryMemory(lumiresult.begin(),lumiresult.end());
966 std::cout<<
"database error "<<er.what()<<std::endl;
967 session->transaction().rollback();
std::vector< PerLumiData > LumiResult
void parseSourceString(lumi::Lumi2DB::LumiSource &result) const
virtual 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 OccLumi[2][HCAL_HLX_MAX_BUNCHES]
float DeadTimeNormalization
static const unsigned int COMMITLSINTERVAL
int16_t ETLumiQlty[HCAL_HLX_MAX_BUNCHES]
std::vector< PerBXData > bxOCC2
unsigned int firstsection
void insertLumiRunData(coral::ISchema &schema, const LumiEntry &lumientry)
unsigned long long data_id
virtual char const * what() const
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 ETLumi[HCAL_HLX_MAX_BUNCHES]
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)
virtual const std::string sourceType() const override
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
float ETLumiErr[HCAL_HLX_MAX_BUNCHES]
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)
int16_t OccLumiQlty[2][HCAL_HLX_MAX_BUNCHES]
virtual 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)
float OccLumiErr[2][HCAL_HLX_MAX_BUNCHES]