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"
38 virtual const std::string
dataType()
const;
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);
91 void writeBeamIntensityOnly(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,
144 const std::string& ilumiversion,
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>();
160 std::string& lumiversion = inputData[
"lumiversion"].data<std::string>();
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,
220 const std::string& ilumiversion,
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));
250 detailData.extend(
"ALGONAME",
typeid(std::string));
252 unsigned long long& lumisummary_id=summaryData[
"LUMISUMMARY_ID"].data<
unsigned long long>();
253 unsigned int& lumirunnum = summaryData[
"RUNNUM"].data<
unsigned int>();
254 std::string& lumiversion = summaryData[
"LUMIVERSION"].data<std::string>();
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>();
267 std::string& beamstatus = summaryData[
"BEAMSTATUS"].data<std::string>();
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>();
277 std::string& algoname=detailData[
"ALGONAME"].data<std::string>();
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;
365 algoname=std::string(
"ET");
366 bxBeg=lumiIt->bxET.begin();
367 bxEnd=lumiIt->bxET.end();
370 algoname=std::string(
"OCC1");
371 bxBeg=lumiIt->bxOCC1.begin();
372 bxEnd=lumiIt->bxOCC1.end();
375 algoname=std::string(
"OCC2");
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();
423 const std::string&
source,
424 unsigned int irunnumber,
426 unsigned int ncollidingbunches,
427 lumi::Lumi2DB::LumiResult::iterator lumiBeg,
428 lumi::Lumi2DB::LumiResult::iterator lumiEnd ){
429 std::cout<<
"writeAllLumiDataToSchema2"<<std::endl;
430 coral::AttributeList summaryData;
431 summaryData.extend(
"DATA_ID",
typeid(
unsigned long long));
432 summaryData.extend(
"RUNNUM",
typeid(
unsigned int));
433 summaryData.extend(
"LUMILSNUM",
typeid(
unsigned int));
434 summaryData.extend(
"CMSLSNUM",
typeid(
unsigned int));
435 summaryData.extend(
"INSTLUMI",
typeid(
float));
436 summaryData.extend(
"INSTLUMIERROR",
typeid(
float));
437 summaryData.extend(
"INSTLUMIQUALITY",
typeid(
short));
438 summaryData.extend(
"BEAMSTATUS",
typeid(std::string));
439 summaryData.extend(
"BEAMENERGY",
typeid(
float));
440 summaryData.extend(
"NUMORBIT",
typeid(
unsigned int));
441 summaryData.extend(
"STARTORBIT",
typeid(
unsigned int));
442 summaryData.extend(
"CMSBXINDEXBLOB",
typeid(coral::Blob));
443 summaryData.extend(
"BEAMINTENSITYBLOB_1",
typeid(coral::Blob));
444 summaryData.extend(
"BEAMINTENSITYBLOB_2",
typeid(coral::Blob));
445 summaryData.extend(
"BXLUMIVALUE_OCC1",
typeid(coral::Blob));
446 summaryData.extend(
"BXLUMIERROR_OCC1",
typeid(coral::Blob));
447 summaryData.extend(
"BXLUMIQUALITY_OCC1",
typeid(coral::Blob));
448 summaryData.extend(
"BXLUMIVALUE_OCC2",
typeid(coral::Blob));
449 summaryData.extend(
"BXLUMIERROR_OCC2",
typeid(coral::Blob));
450 summaryData.extend(
"BXLUMIQUALITY_OCC2",
typeid(coral::Blob));
451 summaryData.extend(
"BXLUMIVALUE_ET",
typeid(coral::Blob));
452 summaryData.extend(
"BXLUMIERROR_ET",
typeid(coral::Blob));
453 summaryData.extend(
"BXLUMIQUALITY_ET",
typeid(coral::Blob));
455 unsigned long long& data_id=summaryData[
"DATA_ID"].data<
unsigned long long>();
456 unsigned int& lumirunnum = summaryData[
"RUNNUM"].data<
unsigned int>();
457 unsigned int& lumilsnr = summaryData[
"LUMILSNUM"].data<
unsigned int>();
458 unsigned int& cmslsnr = summaryData[
"CMSLSNUM"].data<
unsigned int>();
459 float& instlumi = summaryData[
"INSTLUMI"].data<
float>();
460 float& instlumierror = summaryData[
"INSTLUMIERROR"].data<
float>();
461 short& instlumiquality = summaryData[
"INSTLUMIQUALITY"].data<
short>();
462 std::string& beamstatus = summaryData[
"BEAMSTATUS"].data<std::string>();
463 float& beamenergy = summaryData[
"BEAMENERGY"].data<
float>();
464 unsigned int& numorbit = summaryData[
"NUMORBIT"].data<
unsigned int>();
465 unsigned int& startorbit = summaryData[
"STARTORBIT"].data<
unsigned int>();
466 coral::Blob& bxindex = summaryData[
"CMSBXINDEXBLOB"].data<coral::Blob>();
467 coral::Blob& beamintensity_1 = summaryData[
"BEAMINTENSITYBLOB_1"].data<coral::Blob>();
468 coral::Blob& beamintensity_2 = summaryData[
"BEAMINTENSITYBLOB_2"].data<coral::Blob>();
469 coral::Blob& bxlumivalue_et=summaryData[
"BXLUMIVALUE_ET"].data<coral::Blob>();
470 coral::Blob& bxlumierror_et=summaryData[
"BXLUMIERROR_ET"].data<coral::Blob>();
471 coral::Blob& bxlumiquality_et=summaryData[
"BXLUMIQUALITY_ET"].data<coral::Blob>();
472 coral::Blob& bxlumivalue_occ1=summaryData[
"BXLUMIVALUE_OCC1"].data<coral::Blob>();
473 coral::Blob& bxlumierror_occ1=summaryData[
"BXLUMIERROR_OCC1"].data<coral::Blob>();
474 coral::Blob& bxlumiquality_occ1=summaryData[
"BXLUMIQUALITY_OCC1"].data<coral::Blob>();
475 coral::Blob& bxlumivalue_occ2=summaryData[
"BXLUMIVALUE_OCC2"].data<coral::Blob>();
476 coral::Blob& bxlumierror_occ2=summaryData[
"BXLUMIERROR_OCC2"].data<coral::Blob>();
477 coral::Blob& bxlumiquality_occ2=summaryData[
"BXLUMIQUALITY_OCC2"].data<coral::Blob>();
479 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
480 coral::IBulkOperation* summaryInserter=0;
482 unsigned int totallumils=std::distance(lumiBeg,lumiEnd);
483 unsigned int lumiindx=0;
484 unsigned int comittedls=0;
486 unsigned long long branch_id=3;
487 std::string branch_name(
"DATA");
490 std::stringstream op;
492 std::string runnumberStr=op.str();
493 session->transaction().start(
false);
497 lumirundata.
bgev=bgev;
512 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx){
513 if(!session->transaction().isActive()){
514 session->transaction().start(
false);
516 summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
520 summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
524 lumirunnum = irunnumber;
525 lumilsnr = lumiIt->lumilsnr;
526 cmslsnr = lumiIt->cmslsnr;
527 instlumi = lumiIt->instlumi;
528 instlumierror = lumiIt->instlumierror;
529 instlumiquality = lumiIt->instlumiquality;
530 beamstatus = lumiIt->beammode;
531 beamenergy = lumiIt->beamenergy;
532 numorbit = lumiIt->numorbit;
533 startorbit = lumiIt->startorbit;
534 short nlivebx=lumiIt->nlivebx;
537 bxindex.resize(
sizeof(
short)*nlivebx);
538 beamintensity_1.resize(
sizeof(
float)*nlivebx);
539 beamintensity_2.resize(
sizeof(
float)*nlivebx);
540 void* bxindex_StartAddress = bxindex.startingAddress();
541 void* beamIntensity1_StartAddress = beamintensity_1.startingAddress();
542 void* beamIntensity2_StartAddress = beamintensity_2.startingAddress();
543 std::memmove(bxindex_StartAddress,lumiIt->bxindex,
sizeof(
short)*nlivebx);
544 std::memmove(beamIntensity1_StartAddress,lumiIt->beamintensity_1,
sizeof(
float)*nlivebx);
545 std::memmove(beamIntensity2_StartAddress,lumiIt->beamintensity_2,
sizeof(
float)*nlivebx);
551 beamintensity_1.resize(0);
552 beamintensity_2.resize(0);
555 std::vector<PerBXData>::const_iterator bxIt;
556 std::vector<PerBXData>::const_iterator bxBeg;
557 std::vector<PerBXData>::const_iterator bxEnd;
560 bxBeg=lumiIt->bxET.begin();
561 bxEnd=lumiIt->bxET.end();
565 bxlumivalue_et.resize(
sizeof(
float)*
lumi::N_BX);
566 bxlumierror_et.resize(
sizeof(
float)*lumi::N_BX);
567 bxlumiquality_et.resize(
sizeof(
short)*lumi::N_BX);
568 void* bxlumivalueStartAddress=bxlumivalue_et.startingAddress();
569 void* bxlumierrorStartAddress=bxlumierror_et.startingAddress();
570 void* bxlumiqualityStartAddress=bxlumiquality_et.startingAddress();
572 for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++
k ){
573 lumivalue[
k]=bxIt->lumivalue;
574 lumierror[
k]=bxIt->lumierr;
575 lumiquality[
k]=bxIt->lumiquality;
577 std::memmove(bxlumivalueStartAddress,lumivalue,
sizeof(
float)*lumi::N_BX);
578 std::memmove(bxlumierrorStartAddress,lumierror,
sizeof(
float)*lumi::N_BX);
579 std::memmove(bxlumiqualityStartAddress,lumiquality,
sizeof(
short)*lumi::N_BX);
583 bxBeg=lumiIt->bxOCC1.begin();
584 bxEnd=lumiIt->bxOCC1.end();
588 bxlumivalue_occ1.resize(
sizeof(
float)*
lumi::N_BX);
589 bxlumierror_occ1.resize(
sizeof(
float)*lumi::N_BX);
590 bxlumiquality_occ1.resize(
sizeof(
short)*lumi::N_BX);
591 void* bxlumivalueStartAddress=bxlumivalue_occ1.startingAddress();
592 void* bxlumierrorStartAddress=bxlumierror_occ1.startingAddress();
593 void* bxlumiqualityStartAddress=bxlumiquality_occ1.startingAddress();
595 for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++
k ){
596 lumivalue[
k]=bxIt->lumivalue;
597 lumierror[
k]=bxIt->lumierr;
598 lumiquality[
k]=bxIt->lumiquality;
600 std::memmove(bxlumivalueStartAddress,lumivalue,
sizeof(
float)*lumi::N_BX);
601 std::memmove(bxlumierrorStartAddress,lumierror,
sizeof(
float)*lumi::N_BX);
602 std::memmove(bxlumiqualityStartAddress,lumiquality,
sizeof(
short)*lumi::N_BX);
606 bxBeg=lumiIt->bxOCC2.begin();
607 bxEnd=lumiIt->bxOCC2.end();
611 bxlumivalue_occ2.resize(
sizeof(
float)*
lumi::N_BX);
612 bxlumierror_occ2.resize(
sizeof(
float)*lumi::N_BX);
613 bxlumiquality_occ2.resize(
sizeof(
short)*lumi::N_BX);
614 void* bxlumivalueStartAddress=bxlumivalue_occ2.startingAddress();
615 void* bxlumierrorStartAddress=bxlumierror_occ2.startingAddress();
616 void* bxlumiqualityStartAddress=bxlumiquality_occ2.startingAddress();
618 for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++
k ){
619 lumivalue[
k]=bxIt->lumivalue;
620 lumierror[
k]=bxIt->lumierr;
621 lumiquality[
k]=bxIt->lumiquality;
623 std::memmove(bxlumivalueStartAddress,lumivalue,
sizeof(
float)*lumi::N_BX);
624 std::memmove(bxlumierrorStartAddress,lumierror,
sizeof(
float)*lumi::N_BX);
625 std::memmove(bxlumiqualityStartAddress,lumiquality,
sizeof(
short)*lumi::N_BX);
628 summaryInserter->processNextIteration();
629 summaryInserter->flush();
632 std::cout<<
"\t committing in LS chunck "<<comittedls<<std::endl;
633 delete summaryInserter;
635 session->transaction().commit();
638 }
else if( lumiindx==(totallumils-1) ){
639 std::cout<<
"\t committing at the end"<<std::endl;
640 delete summaryInserter; summaryInserter=0;
641 session->transaction().commit();
648 lumi::Lumi2DB::LumiResult::iterator lumiEnd){
649 lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
650 for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt){
651 ::free(lumiIt->bxindex);
652 ::free(lumiIt->beamintensity_1);
653 ::free(lumiIt->beamintensity_2);
661 if(m_source.length()==0)
throw lumi::Exception(
"lumi source is not set",
"parseSourceString",
"Lumi2DB");
663 size_t tempIndex = m_source.find_last_of(
".");
664 size_t nameLength = m_source.length();
665 std::string FileSuffix= m_source.substr(tempIndex+1,nameLength - tempIndex);
668 std::vector<std::string>
pieces;
669 while( std::string::npos != pos || std::string::npos != lastPos){
670 pieces.push_back(m_source.substr(lastPos,pos-lastPos));
671 lastPos=m_source.find_first_not_of(
"_",pos);
672 pos=m_source.find_first_of(
"_",lastPos);
674 if( pieces[1]!=
"LUMI" || pieces[2]!=
"RAW" || FileSuffix!=
"root"){
675 throw lumi::Exception(
"not lumi raw data file CMS_LUMI_RAW",
"parseSourceString",
"Lumi2DB");
677 std::strcpy(result.
datestr,pieces[3].c_str());
678 std::strcpy(result.
version,pieces[5].c_str());
680 result.
run = atoi(pieces[4].c_str());
689 std::cout<<
"HCAL_HLX::DIP_COMBINED_DATA* dataPtr=0"<<std::endl;
732 parseSourceString(filenamecontent);
737 if( filenamecontent.
run!=runnumber ){
738 throw lumi::Exception(
"runnumber in file name does not match requested run number",
"retrieveData",
"Lumi2DB");
740 TFile*
source=TFile::Open(m_source.c_str(),
"READ");
741 TTree *hlxtree = (TTree*)source->Get(
"HLXData");
743 throw lumi::Exception(std::string(
"non-existing HLXData "),
"retrieveData",
"Lumi2DB");
751 hlxtree->SetBranchAddress(
"Header.",&lumiheader);
752 hlxtree->SetBranchAddress(
"Summary.",&lumisummary);
753 hlxtree->SetBranchAddress(
"Detail.",&lumidetail);
755 size_t nentries=hlxtree->GetEntries();
756 unsigned int nstablebeam=0;
759 std::map<unsigned int, Lumi2DB::beamData> dipmap;
760 TTree *diptree= (TTree*)source->Get(
"DIPCombined");
764 diptree->SetBranchAddress(
"DIPCombined.",&dipdata);
765 size_t ndipentries=diptree->GetEntries();
766 for(
size_t i=0;
i<ndipentries;++
i){
767 diptree->GetEntry(
i);
781 unsigned int dipls=dipdata->sectionNumber;
782 if (std::string(dipdata->beamMode).empty()){
785 b.
mode=dipdata->beamMode;
788 if(b.
mode==
"STABLE BEAMS"){
792 this->retrieveBeamIntensity(dipdata.get(),
b);
793 dipmap.insert(std::make_pair(dipls,b));
796 for(
size_t i=0;
i<nentries;++
i){
800 this->retrieveBeamIntensity(0,b);
801 dipmap.insert(std::make_pair(
i,b));
807 std::cout<<
"processing total lumi lumisection "<<nentries<<std::endl;
814 unsigned int ncollidingbunches=0;
815 for(
size_t i=0;
i<nentries;++
i){
818 hlxtree->GetEntry(
i);
835 std::map<unsigned int , Lumi2DB::beamData >::iterator beamIt=dipmap.find(h.
lumilsnr);
836 if ( beamIt!=dipmap.end() ){
839 h.
nlivebx=beamIt->second.nlivebx;
851 std::memmove(h.
bxindex,beamIt->second.bxindex,
sizeof(
short)*h.
nlivebx);
855 ::free(beamIt->second.bxindex);beamIt->second.bxindex=0;
856 ::free(beamIt->second.beamintensity_1);beamIt->second.beamintensity_1=0;
857 ::free(beamIt->second.beamintensity_2);beamIt->second.beamintensity_2=0;
895 h.
bxET.push_back(bET);
908 h.
bxOCC1.push_back(bOCC1);
914 h.
bxOCC2.push_back(bOCC2);
916 lumiresult.push_back(h);
920 bgev=bgev/nstablebeam;
922 std::cout<<
"avg stable beam energy "<<bgev<<std::endl;
923 if( !m_novalidate && !isLumiDataValid(lumiresult.begin(),lumiresult.end()) ){
926 if( !m_nocheckingstablebeam && !hasStableBeam(lumiresult.begin(),lumiresult.end()) ){
929 coral::ConnectionService*
svc=
new coral::ConnectionService;
931 if(!m_authpath.empty()){
934 coral::ISessionProxy*
session=svc->connect(m_dest,coral::Update);
935 coral::ITypeConverter& tpc=session->typeConverter();
936 tpc.setCppTypeForSqlType(
"unsigned int",
"NUMBER(10)");
941 const std::string lversion(filenamecontent.
version);
942 if(m_mode==std::string(
"beamintensity_only")){
943 std::cout<<
"writing beam intensity only to old lumisummary table "<<std::endl;
944 writeBeamIntensityOnly(session,runnumber,lversion,lumiresult.begin(),lumiresult.end());
947 if(m_mode==
"loadoldschema"){
948 std::cout<<
"writing all lumi data to old lumisummary table "<<std::endl;
949 writeAllLumiData(session,runnumber,lversion,lumiresult.begin(),lumiresult.end());
953 std::cout<<
"writing all lumi data to lumisummary_V2 table "<<std::endl;
954 writeAllLumiDataToSchema2(session,m_source,runnumber,bgev,ncollidingbunches,lumiresult.begin(),lumiresult.end());
956 cleanTemporaryMemory(lumiresult.begin(),lumiresult.end());
960 std::cout<<
"database error "<<er.what()<<std::endl;
961 session->transaction().rollback();
std::vector< PerLumiData > LumiResult
void parseSourceString(lumi::Lumi2DB::LumiSource &result) const
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
virtual const std::string sourceType() const
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
virtual void retrieveData(unsigned int)
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 OccLumiErr[2][4096]
void cleanTemporaryMemory(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
void retrieveBeamIntensity(HCAL_HLX::DIP_COMBINED_DATA *dataPtr, Lumi2DB::beamData &b) const
void 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)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
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
virtual const std::string dataType() const
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)
std::vector< PerBXData > bxET
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)