CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Lumi2DB.cc
Go to the documentation of this file.
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"
24 #include <iostream>
25 #include <cstring>
26 #include <cstdlib>
27 #include <memory>
28 #include <algorithm>
29 #include <map>
30 #include "TFile.h"
31 #include "TTree.h"
32 namespace lumi{
33  class Lumi2DB : public DataPipe{
34  public:
35  const static unsigned int COMMITLSINTERVAL=500; //commit interval in LS,totalrow=nls*(1+nalgo)
36  Lumi2DB(const std::string& dest);
37  virtual unsigned long long retrieveData( unsigned int ) override;
38  virtual const std::string dataType() const override;
39  virtual const std::string sourceType() const override;
40  virtual ~Lumi2DB();
41 
42  struct LumiSource{
43  unsigned int run;
44  unsigned int firstsection;
45  char version[8];
46  char datestr[9];
47  };
48  struct PerBXData{
49  //int idx;
50  float lumivalue;
51  float lumierr;
52  short lumiquality;
53  };
54  struct PerLumiData{
55  float dtnorm;
56  float lhcnorm;
57  float instlumi;
61  short cmsalive;
63  float beamenergy;
64  short nlivebx;//how much is in the beamintensity vector
65  short* bxindex;
68  unsigned int cmslsnr;
69  unsigned int lumilsnr;
70  unsigned int startorbit;
71  unsigned int numorbit;
72  std::vector<PerBXData> bxET;
73  std::vector<PerBXData> bxOCC1;
74  std::vector<PerBXData> bxOCC2;
75  };
76  struct beamData{
77  float energy;
79  short nlivebx;
80  short* bxindex;
83  };
84  typedef std::vector<PerLumiData> LumiResult;
85  bool hasStableBeam( lumi::Lumi2DB::LumiResult::iterator lumiBeg,lumi::Lumi2DB::LumiResult::iterator lumiEnd );
86  private:
89  void writeAllLumiData(coral::ISessionProxy* session,unsigned int irunnumber,const std::string& ilumiversion,LumiResult::iterator lumiBeg,LumiResult::iterator lumiEnd);
90  unsigned int writeAllLumiDataToSchema2(coral::ISessionProxy* session,const std::string& source,unsigned int runnumber,float bgev,unsigned int ncollidingbunches,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);
93  float applyCalibration(float varToCalibrate) const;
94  void cleanTemporaryMemory( lumi::Lumi2DB::LumiResult::iterator lumiBeg,lumi::Lumi2DB::LumiResult::iterator lumiEnd);
95  };//cl Lumi2DB
96 }//ns lumi
97 
98 //
99 //implementation
100 //
101 float
102 lumi::Lumi2DB::applyCalibration(float varToCalibrate)const{ //#only used for writing into schema_v1
103  return float(varToCalibrate)*m_norm;
104 }
105 bool
106 lumi::Lumi2DB::hasStableBeam( lumi::Lumi2DB::LumiResult::iterator lumiBeg,lumi::Lumi2DB::LumiResult::iterator lumiEnd ){
107  //
108  // the run has at least 1 stable beams LS
109  //
110  lumi::Lumi2DB::LumiResult::iterator lumiIt;
111  int nStable=0;
112  for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt){
113  if(lumiIt->beammode=="STABLE BEAMS"){
114  ++nStable;
115  }
116  }
117  if(nStable==0){
118  return false;
119  }
120  return true;
121 }
122 bool
123 lumi::Lumi2DB::isLumiDataValid(lumi::Lumi2DB::LumiResult::iterator lumiBeg,lumi::Lumi2DB::LumiResult::iterator lumiEnd){
124  //
125  // validate lumidata: all ls has lumi less than 0.5e-08 before calibration, then invalid data
126  //
127  lumi::Lumi2DB::LumiResult::iterator lumiIt;
128  int nBad=0;
129  for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt){
130  //std::cout<<"instlumi before calib "<<lumiIt->instlumi<<std::endl;
131  if(lumiIt->instlumi<=0.5e-8){//cut before calib
132  ++nBad;
133  }
134  }
135  if(nBad==std::distance(lumiBeg,lumiEnd)){
136  return false;
137  }
138  return true;
139 }
140 void
142  coral::ISessionProxy* session,
143  unsigned int irunnumber,
144  const std::string& ilumiversion,
145  lumi::Lumi2DB::LumiResult::iterator lumiBeg,
146  lumi::Lumi2DB::LumiResult::iterator lumiEnd
147  ){
148  coral::AttributeList inputData;
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>();
161 
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);
174  }
175  startorbit=lumiIt->startorbit;
176  //std::cout<<"runnumber "<<irunnumber<<" starorbit "<<startorbit<<" lumiversion "<<lumiversion<<" totallumils "<<totallumils<<std::endl;
177  short nlivebx=lumiIt->nlivebx;
178  if(nlivebx!=0){
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);
191  }else{
192  bxindex.resize(0);
193  beamintensity_1.resize(0);
194  beamintensity_2.resize(0);
195  }
196  coral::ITable& summarytable=session->nominalSchema().tableHandle(LumiNames::lumisummaryTableName());
197  summaryUpdater=summarytable.dataEditor().bulkUpdateRows(setClause,condition,inputData,totallumils);
198  summaryUpdater->processNextIteration();
199  summaryUpdater->flush();
200  ++comittedls;
201  if(comittedls==Lumi2DB::COMMITLSINTERVAL){
202  std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
203  delete summaryUpdater;
204  summaryUpdater=0;
205  session->transaction().commit();
206  comittedls=0;
207  std::cout<<"\t committed "<<std::endl;
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();
212  std::cout<<"\t done"<<std::endl;
213  }
214  }
215 }
216 void
218  coral::ISessionProxy* session,
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));
244 
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));
251 
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>();
271 
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>();
278 
279  lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
280  coral::IBulkOperation* summaryInserter=0;
281  coral::IBulkOperation* detailInserter=0;
282  //one loop for ids
283  //nested transaction doesn't work with bulk inserter
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;
288  std::cout<<"\t allocating total lumidetail ids "<<totallumils*lumi::N_LUMIALGO<<std::endl;
289 
290  session->transaction().start(false);
291  lumi::idDealer idg(session->nominalSchema());
292  unsigned long long lumisummaryID = idg.generateNextIDForTable(LumiNames::lumisummaryTableName(),totallumils)-totallumils;
293  unsigned long long lumidetailID=idg.generateNextIDForTable(LumiNames::lumidetailTableName(),totallumils*lumi::N_LUMIALGO)-totallumils*lumi::N_LUMIALGO;
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);
299  for( unsigned int j=0; j<lumi::N_LUMIALGO; ++j, ++lumidetailID){
300  allIDs.push_back(lumidetailID);
301  }
302  idallocationtable.insert(std::make_pair(lumiindx,allIDs));
303  }
304  std::cout<<"\t all ids allocated"<<std::endl;
305  lumiindx=0;
306  unsigned int comittedls=0;
307  for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx){
308  if(!session->transaction().isActive()){
309  session->transaction().start(false);
310  coral::ITable& summarytable=session->nominalSchema().tableHandle(LumiNames::lumisummaryTableName());
311  summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
312  coral::ITable& detailtable=session->nominalSchema().tableHandle(LumiNames::lumidetailTableName());
313  detailInserter=detailtable.dataEditor().bulkInsert(detailData,totallumils*lumi::N_LUMIALGO);
314  }
315  lumisummary_id=idallocationtable[lumiindx][0];
316  lumirunnum = irunnumber;
317  lumiversion = ilumiversion;
318  dtnorm = lumiIt->dtnorm;
319  lhcnorm = lumiIt->lhcnorm;
320  //instlumi = lumiIt->instlumi;
321  //instlumierror = lumiIt->instlumierror;
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;
328 
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;
335  //std::cout<<"nlivebx "<<nlivebx<<std::endl;
336  if(nlivebx!=0){
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);
346  //::free(lumiIt->bxindex);
347  //::free(lumiIt->beamintensity_1);
348  //::free(lumiIt->beamintensity_2);
349  }else{
350  bxindex.resize(0);
351  beamintensity_1.resize(0);
352  beamintensity_2.resize(0);
353  }
354  //insert the new row
355  summaryInserter->processNextIteration();
356  summaryInserter->flush();
357  unsigned int algoindx=1;
358  for( unsigned int j=0; j<lumi:: N_LUMIALGO; ++j,++algoindx ){
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;
364  if(j==0) {
365  algoname=std::string("ET");
366  bxBeg=lumiIt->bxET.begin();
367  bxEnd=lumiIt->bxET.end();
368  }
369  if(j==1) {
370  algoname=std::string("OCC1");
371  bxBeg=lumiIt->bxOCC1.begin();
372  bxEnd=lumiIt->bxOCC1.end();
373  }
374  if(j==2) {
375  algoname=std::string("OCC2");
376  bxBeg=lumiIt->bxOCC2.begin();
377  bxEnd=lumiIt->bxOCC2.end();
378  }
379  float lumivalue[lumi::N_BX]={0.0};
380  float lumierror[lumi::N_BX]={0.0};
381  int lumiquality[lumi::N_BX]={0};
382  bxlumivalue.resize(sizeof(float)*lumi::N_BX);
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();
388  unsigned int k=0;
389  for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++k ){
390  lumivalue[k]=bxIt->lumivalue;
391  lumierror[k]=bxIt->lumierr;
392  lumiquality[k]=bxIt->lumiquality;
393  }
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();
398  }
399  detailInserter->flush();
400  ++comittedls;
401  if(comittedls==Lumi2DB::COMMITLSINTERVAL){
402  std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
403  delete summaryInserter;
404  summaryInserter=0;
405  delete detailInserter;
406  detailInserter=0;
407  session->transaction().commit();
408  comittedls=0;
409  std::cout<<"\t committed "<<std::endl;
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();
415  std::cout<<"\t done"<<std::endl;
416  }
417  }
418 }
419 
420 unsigned int
422  coral::ISessionProxy* session,
423  const std::string& source,
424  unsigned int irunnumber,
425  float bgev,
426  unsigned int ncollidingbunches,
427  lumi::Lumi2DB::LumiResult::iterator lumiBeg,
428  lumi::Lumi2DB::LumiResult::iterator lumiEnd ){
430  //output: lumi data id
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));
457 
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>();
465  std::string& beamstatus = summaryData["BEAMSTATUS"].data<std::string>();
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>();
481 
482  lumi::Lumi2DB::LumiResult::const_iterator lumiIt;
483  coral::IBulkOperation* summaryInserter=0;
484 
485  unsigned int totallumils=std::distance(lumiBeg,lumiEnd);
486  unsigned int lumiindx=0;
487  unsigned int comittedls=0;
488 
489  unsigned long long branch_id=3;
490  std::string branch_name("DATA");
491  lumi::RevisionDML revisionDML;
493  std::stringstream op;
494  op<<irunnumber;
495  std::string runnumberStr=op.str();
496  session->transaction().start(false);
497  lumirundata.entry_name=runnumberStr;
498  lumirundata.source=source;
499  lumirundata.runnumber=irunnumber;
500  lumirundata.bgev=bgev;
501  lumirundata.ncollidingbunches=ncollidingbunches;
502  lumirundata.data_id=0;
503  lumirundata.entry_id=revisionDML.getEntryInBranchByName(session->nominalSchema(),lumi::LumiNames::lumidataTableName(),runnumberStr,branch_name);
504  //std::cout<<"entry_id "<<lumirundata.entry_id<<std::endl;
505  if(lumirundata.entry_id==0){
506  revisionDML.bookNewEntry(session->nominalSchema(),LumiNames::lumidataTableName(),lumirundata);
507  std::cout<<"it's a new run lumirundata revision_id "<<lumirundata.revision_id<<" entry_id "<<lumirundata.entry_id<<" data_id "<<lumirundata.data_id<<std::endl;
508  revisionDML.addEntry(session->nominalSchema(),LumiNames::lumidataTableName(),lumirundata,branch_id,branch_name);
509  std::cout<<"added entry "<<std::endl;
510  }else{
511  revisionDML.bookNewRevision(session->nominalSchema(),LumiNames::lumidataTableName(),lumirundata);
512  std::cout<<"lumirundata revision_id "<<lumirundata.revision_id<<" entry_id "<<lumirundata.entry_id<<" data_id "<<lumirundata.data_id<<std::endl;
513  revisionDML.addRevision(session->nominalSchema(),LumiNames::lumidataTableName(),lumirundata,branch_id,branch_name);
514  }
515  revisionDML.insertLumiRunData(session->nominalSchema(),lumirundata);
516  for(lumiIt=lumiBeg;lumiIt!=lumiEnd;++lumiIt,++lumiindx){
517  if(!session->transaction().isActive()){
518  session->transaction().start(false);
519  coral::ITable& summarytable=session->nominalSchema().tableHandle(LumiNames::lumisummaryv2TableName());
520  summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
521  }else{
522  if(lumiIt==lumiBeg){
523  coral::ITable& summarytable=session->nominalSchema().tableHandle(LumiNames::lumisummaryv2TableName());
524  summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
525  }
526  }
527  data_id = lumirundata.data_id;
528  lumirunnum = irunnumber;
529  lumilsnr = lumiIt->lumilsnr;
530  cmslsnr = lumiIt->cmslsnr;
531  instlumi = lumiIt->instlumi; // not calibrated!
532  instlumierror = lumiIt->instlumierror; // not calibrated!
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;
539  //std::cout<<"nlivebx "<<nlivebx<<std::endl;
540  if(nlivebx!=0){
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);
550  //::free(lumiIt->bxindex);
551  //::free(lumiIt->beamintensity_1);
552  //::free(lumiIt->beamintensity_2);
553  }else{
554  bxindex.resize(0);
555  beamintensity_1.resize(0);
556  beamintensity_2.resize(0);
557  }
558  for( unsigned int j=0; j<lumi:: N_LUMIALGO; ++j ){
559  std::vector<PerBXData>::const_iterator bxIt;
560  std::vector<PerBXData>::const_iterator bxBeg;
561  std::vector<PerBXData>::const_iterator bxEnd;
562  if(j==0) {//the push_back order in the input data is ET,OCC1,OCC2
563  //algoname=std::string("ET");
564  bxBeg=lumiIt->bxET.begin();
565  bxEnd=lumiIt->bxET.end();
566  float lumivalue[lumi::N_BX]={0.0};
567  float lumierror[lumi::N_BX]={0.0};
568  int lumiquality[lumi::N_BX]={0};
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();
575  unsigned int k=0;
576  for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++k ){
577  lumivalue[k]=bxIt->lumivalue;
578  lumierror[k]=bxIt->lumierr;
579  lumiquality[k]=bxIt->lumiquality;
580  }
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);
584  }
585  if(j==1) {
586  //algoname=std::string("OCC1");
587  bxBeg=lumiIt->bxOCC1.begin();
588  bxEnd=lumiIt->bxOCC1.end();
589  float lumivalue[lumi::N_BX]={0.0};
590  float lumierror[lumi::N_BX]={0.0};
591  int lumiquality[lumi::N_BX]={0};
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();
598  unsigned int k=0;
599  for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++k ){
600  lumivalue[k]=bxIt->lumivalue;
601  lumierror[k]=bxIt->lumierr;
602  lumiquality[k]=bxIt->lumiquality;
603  }
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);
607  }
608  if(j==2) {
609  //algoname=std::string("OCC2");
610  bxBeg=lumiIt->bxOCC2.begin();
611  bxEnd=lumiIt->bxOCC2.end();
612  float lumivalue[lumi::N_BX]={0.0};
613  float lumierror[lumi::N_BX]={0.0};
614  int lumiquality[lumi::N_BX]={0};
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();
621  unsigned int k=0;
622  for( bxIt=bxBeg;bxIt!=bxEnd;++bxIt,++k ){
623  lumivalue[k]=bxIt->lumivalue;
624  lumierror[k]=bxIt->lumierr;
625  lumiquality[k]=bxIt->lumiquality;
626  }
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);
630  }
631  }
632  summaryInserter->processNextIteration();
633  summaryInserter->flush();
634  ++comittedls;
635  if(comittedls==Lumi2DB::COMMITLSINTERVAL){
636  std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
637  delete summaryInserter;
638  summaryInserter=0;
639  session->transaction().commit();
640  comittedls=0;
641  std::cout<<"\t committed "<<std::endl;
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();
646  std::cout<<"\t done"<<std::endl;
647  }
648  }
649  return lumirundata.data_id;
650 }
651 
652 void lumi::Lumi2DB::cleanTemporaryMemory( lumi::Lumi2DB::LumiResult::iterator lumiBeg,
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);
659  }
660 
661 }
663 void
665  //parse lumi source file name
666  if(m_source.length()==0) throw lumi::Exception("lumi source is not set","parseSourceString","Lumi2DB");
667  //std::cout<<"source "<<m_source<<std::endl;
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);
671  std::string::size_type lastPos=m_source.find_first_not_of("_",0);
672  std::string::size_type pos = m_source.find_first_of("_",lastPos);
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);
678  }
679  if( pieces[1]!="LUMI" || pieces[2]!="RAW" || FileSuffix!="root"){
680  throw lumi::Exception("not lumi raw data file CMS_LUMI_RAW","parseSourceString","Lumi2DB");
681  }
682  std::strcpy(result.datestr,pieces[3].c_str());
683  std::strcpy(result.version,pieces[5].c_str());
684  //std::cout<<"version : "<<result.version<<std::endl;
685  result.run = atoi(pieces[4].c_str());
686  //std::cout<<"run : "<<result.run<<std::endl;
687  result.firstsection = atoi(pieces[5].c_str());
688  //std::cout<<"first section : "<< result.firstsection<<std::endl;
689 }
690 
691 void
693  if(dataPtr==0){
694  std::cout<<"HCAL_HLX::DIP_COMBINED_DATA* dataPtr=0"<<std::endl;
695  b.bxindex=0;
696  b.beamintensity_1=0;
697  b.beamintensity_2=0;
698  b.nlivebx=0;
699  }else{
700  b.bxindex=(short*)::malloc(sizeof(short)*lumi::N_BX);
701  b.beamintensity_1=(float*)::malloc(sizeof(float)*lumi::N_BX);
702  b.beamintensity_2=(float*)::malloc(sizeof(float)*lumi::N_BX);
703 
704  short a=0;//a is position in lumidetail array
705  for(unsigned int i=0;i<lumi::N_BX;++i){
706  if( i==0 ){
707  if(dataPtr->Beam[0].averageBunchIntensities[0]>0 || dataPtr->Beam[1].averageBunchIntensities[0]>0 ){
708  b.bxindex[a]=0;
709  b.beamintensity_1[a]=dataPtr->Beam[0].averageBunchIntensities[0];
710  b.beamintensity_2[a]=dataPtr->Beam[1].averageBunchIntensities[0];
711  ++a;
712  }
713  continue;
714  }
715  if(dataPtr->Beam[0].averageBunchIntensities[i-1]>0 || dataPtr->Beam[1].averageBunchIntensities[i-1]>0){
716  b.bxindex[a]=i;
717  b.beamintensity_1[a]=dataPtr->Beam[0].averageBunchIntensities[i-1];
718  b.beamintensity_2[a]=dataPtr->Beam[1].averageBunchIntensities[i-1];
719  ++a;
720  //if(i!=0){
721  // std::cout<<"beam intensity "<<dataPtr->sectionNumber<<" "<<dataPtr->timestamp-1262300400<<" "<<(i-1)*10+1<<" "<<b.beamintensity_1[a]<<" "<<b.beamintensity_2[a]<<std::endl;
722  //}
723  }
724  }
725  b.nlivebx=a;
726  }
727 }
731 unsigned long long
733  lumi::Lumi2DB::LumiResult lumiresult;
734  //check filename is in lumiraw format
735  lumi::Lumi2DB::LumiSource filenamecontent;
736  unsigned int lumidataid=0;
737  try{
738  parseSourceString(filenamecontent);
739  }catch(const lumi::Exception& er){
740  std::cout<<er.what()<<std::endl;
741  throw er;
742  }
743  if( filenamecontent.run!=runnumber ){
744  throw lumi::Exception("runnumber in file name does not match requested run number","retrieveData","Lumi2DB");
745  }
746  TFile* source=TFile::Open(m_source.c_str(),"READ");
747  TTree *hlxtree = (TTree*)source->Get("HLXData");
748  if(!hlxtree){
749  throw lumi::Exception(std::string("non-existing HLXData "),"retrieveData","Lumi2DB");
750  }
751  //hlxtree->Print();
752  std::auto_ptr<HCAL_HLX::LUMI_SECTION> localSection(new HCAL_HLX::LUMI_SECTION);
753  HCAL_HLX::LUMI_SECTION_HEADER* lumiheader = &(localSection->hdr);
754  HCAL_HLX::LUMI_SUMMARY* lumisummary = &(localSection->lumiSummary);
755  HCAL_HLX::LUMI_DETAIL* lumidetail = &(localSection->lumiDetail);
756 
757  hlxtree->SetBranchAddress("Header.",&lumiheader);
758  hlxtree->SetBranchAddress("Summary.",&lumisummary);
759  hlxtree->SetBranchAddress("Detail.",&lumidetail);
760 
761  size_t nentries=hlxtree->GetEntries();
762  unsigned int nstablebeam=0;
763  float bgev=0.0;
764  //source->GetListOfKeys()->Print();
765  std::map<unsigned int, Lumi2DB::beamData> dipmap;
766  TTree *diptree= (TTree*)source->Get("DIPCombined");
767  if(diptree){
768  //throw lumi::Exception(std::string("non-existing DIPData "),"retrieveData","Lumi2DB");
769  std::auto_ptr<HCAL_HLX::DIP_COMBINED_DATA> dipdata(new HCAL_HLX::DIP_COMBINED_DATA);
770  diptree->SetBranchAddress("DIPCombined.",&dipdata);
771  size_t ndipentries=diptree->GetEntries();
772  for(size_t i=0;i<ndipentries;++i){
773  diptree->GetEntry(i);
774  //unsigned int fillnumber=dipdata->FillNumber;
775  //std::vector<short> collidingidx;collidingidx.reserve(LUMI::N_BX);
776  //for(unsigned int i=0;i<lumi::N_BX;++i){
777  //int isb1colliding=dipdata->beam[0].beamConfig[i];
778  //int isb2colliding=dipdata->beam[1].beamConfig[i];
779  //if(isb1colliding && isb2colliding&&isb1colliding==1&&isb2colliding==1){
780  // collidingidx.push_back(i);
781  // }
782  //}
783  beamData b;
784  //std::cout<<"Beam Mode : "<<dipdata->beamMode<<"\n";
785  //std::cout<<"Beam Energy : "<<dipdata->Energy<<"\n";
786  //std::cout<<"sectionUmber : "<<dipdata->sectionNumber<<"\n";
787  unsigned int dipls=dipdata->sectionNumber;
788  if (std::string(dipdata->beamMode).empty()){
789  b.mode="N/A";
790  }else{
791  b.mode=dipdata->beamMode;
792  }
793  b.energy=dipdata->Energy;
794  if(b.mode=="STABLE BEAMS"){
795  ++nstablebeam;
796  bgev+=b.energy;
797  }
798  this->retrieveBeamIntensity(dipdata.get(),b);
799  dipmap.insert(std::make_pair(dipls,b));
800  }
801  }else{
802  for(size_t i=0;i<nentries;++i){
803  beamData b;
804  b.mode="N/A";
805  b.energy=0.0;
806  this->retrieveBeamIntensity(0,b);
807  dipmap.insert(std::make_pair(i,b));
808  }
809  }
810  //diptree->Print();
811 
812  size_t ncmslumi=0;
813  std::cout<<"processing total lumi lumisection "<<nentries<<std::endl;
814  //size_t lumisecid=0;
815  //unsigned int lumilumisecid=0;
816  //runnumber=lumiheader->runNumber;
817  //
818  //hardcode the first LS is always alive
819  //
820  unsigned int ncollidingbunches=0;
821  for(size_t i=0;i<nentries;++i){
823  h.cmsalive=1;
824  hlxtree->GetEntry(i);
825  //std::cout<<"live flag "<<lumiheader->bCMSLive <<std::endl;
826  if( !lumiheader->bCMSLive && i!=0){
827  std::cout<<"\t non-CMS LS "<<lumiheader->sectionNumber<<" ";
828  h.cmsalive=0;
829  }
830  ++ncmslumi;
831  if(ncmslumi==1){//just take the first ls
832  ncollidingbunches=lumiheader->numBunches;
833  }
834  h.bxET.reserve(lumi::N_BX);
835  h.bxOCC1.reserve(lumi::N_BX);
836  h.bxOCC2.reserve(lumi::N_BX);
837 
838  //runnumber=lumiheader->runNumber;
839  //if(runnumber!=m_run) throw std::runtime_error(std::string("requested run ")+this->int2str(m_run)+" does not match runnumber in the data header "+this->int2str(runnumber));
840  h.lumilsnr=lumiheader->sectionNumber;
841  std::map<unsigned int , Lumi2DB::beamData >::iterator beamIt=dipmap.find(h.lumilsnr);
842  if ( beamIt!=dipmap.end() ){
843  h.beammode=beamIt->second.mode;
844  h.beamenergy=beamIt->second.energy;
845  h.nlivebx=beamIt->second.nlivebx;
846  if(h.nlivebx!=0){
847  h.bxindex=(short*)malloc(sizeof(short)*h.nlivebx);
848  h.beamintensity_1=(float*)malloc(sizeof(float)*h.nlivebx);
849  h.beamintensity_2=(float*)malloc(sizeof(float)*h.nlivebx);
850  if(h.bxindex==0 || h.beamintensity_1==0 || h.beamintensity_2==0){
851  std::cout<<"malloc failed"<<std::endl;
852  }
853  //std::cout<<"h.bxindex size "<<sizeof(short)*h.nlivebx<<std::endl;
854  //std::cout<<"h.beamintensity_1 size "<<sizeof(float)*h.nlivebx<<std::endl;
855  //std::cout<<"h.beamintensity_2 size "<<sizeof(float)*h.nlivebx<<std::endl;
856 
857  std::memmove(h.bxindex,beamIt->second.bxindex,sizeof(short)*h.nlivebx);
858  std::memmove(h.beamintensity_1,beamIt->second.beamintensity_1,sizeof(float)*h.nlivebx);
859  std::memmove(h.beamintensity_2,beamIt->second.beamintensity_2,sizeof(float)*h.nlivebx);
860 
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;
864  }else{
865  //std::cout<<"h.nlivebx is zero"<<std::endl;
866  h.bxindex=0;
867  h.beamintensity_1=0;
868  h.beamintensity_2=0;
869  }
870  }else{
871  h.beammode="N/A";
872  h.beamenergy=0.0;
873  h.nlivebx=0;
874  h.bxindex=0;
875  h.beamintensity_1=0;
876  h.beamintensity_2=0;
877  }
878  h.startorbit=lumiheader->startOrbit;
879  h.numorbit=lumiheader->numOrbits;
880  if(h.cmsalive==0){
881  h.cmslsnr=0; //the dead ls has cmsls number=0
882  }else{
883  h.cmslsnr=ncmslumi;//we guess cms lumils
884  }
885  h.instlumi=lumisummary->InstantLumi;
886  //std::cout<<"instant lumi "<<lumisummary->InstantLumi<<std::endl;
887  h.instlumierror=lumisummary->InstantLumiErr;
888  h.lumisectionquality=lumisummary->InstantLumiQlty;
889  h.dtnorm=lumisummary->DeadTimeNormalization;
890  h.lhcnorm=lumisummary->LHCNormalization;
891  //unsigned int timestp=lumiheader->timestamp;
892  //std::cout<<"cmslsnum "<<ncmslumi<<"timestp "<<timestp<<std::endl;
893  for(size_t i=0;i<lumi::N_BX;++i){
897  //bET.idx=i+1;
898  bET.lumivalue=lumidetail->ETLumi[i];
899  bET.lumierr=lumidetail->ETLumiErr[i];
900  bET.lumiquality=lumidetail->ETLumiQlty[i];
901  h.bxET.push_back(bET);
902 
903  //bOCC1.idx=i+1;
904 
905  bOCC1.lumivalue=lumidetail->OccLumi[0][i];
906  bOCC1.lumierr=lumidetail->OccLumiErr[0][i];
913  bOCC1.lumiquality=lumidetail->OccLumiQlty[0][i];
914  h.bxOCC1.push_back(bOCC1);
915 
916  //bOCC2.idx=i+1;
917  bOCC2.lumivalue=lumidetail->OccLumi[1][i];
918  bOCC2.lumierr=lumidetail->OccLumiErr[1][i];
919  bOCC2.lumiquality=lumidetail->OccLumiQlty[1][i];
920  h.bxOCC2.push_back(bOCC2);
921  }
922  lumiresult.push_back(h);
923  }
924  std::cout<<std::endl;
925  if(nstablebeam!=0){
926  bgev=bgev/nstablebeam;//nominal beam energy=sum(energy)/nstablebeams
927  }
928  std::cout<<"avg stable beam energy "<<bgev<<std::endl;
929  if( !m_novalidate && !isLumiDataValid(lumiresult.begin(),lumiresult.end()) ){
930  throw lumi::invalidDataException("all lumi values are <0.5e-08","isLumiDataValid","Lumi2DB");
931  }
932  if( !m_nocheckingstablebeam && !hasStableBeam(lumiresult.begin(),lumiresult.end()) ){
933  throw lumi::noStableBeamException("no LS has STABLE BEAMS","hasStableBeam","Lumi2DB");
934  }
935  coral::ConnectionService* svc=new coral::ConnectionService;
936  lumi::DBConfig dbconf(*svc);
937  if(!m_authpath.empty()){
938  dbconf.setAuthentication(m_authpath);
939  }
940  coral::ISessionProxy* session=svc->connect(m_dest,coral::Update);
941  coral::ITypeConverter& tpc=session->typeConverter();
942  tpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
943  //
944  //write to old lumisummary
945  //
946  try{
947  const std::string lversion(filenamecontent.version);
948  if(m_mode==std::string("beamintensity_only")){
949  std::cout<<"writing beam intensity only to old lumisummary table "<<std::endl;
950  writeBeamIntensityOnly(session,runnumber,lversion,lumiresult.begin(),lumiresult.end());
951  std::cout<<"done"<<std::endl;
952  }else{
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());
956  std::cout<<"done"<<std::endl;
957  }
958  }
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());
961  std::cout<<"done"<<std::endl;
962  cleanTemporaryMemory(lumiresult.begin(),lumiresult.end());
963  delete session;
964  delete svc;
965  }catch( const coral::Exception& er){
966  std::cout<<"database error "<<er.what()<<std::endl;
967  session->transaction().rollback();
968  delete session;
969  delete svc;
970  throw er;
971  }
972  return lumidataid;
973 }
975  return "LUMI";
976 }
978  return "DB";
979 }
981 
984 #endif
int i
Definition: DBlmapReader.cc:9
std::vector< PerLumiData > LumiResult
Definition: Lumi2DB.cc:84
void parseSourceString(lumi::Lumi2DB::LumiSource &result) const
Definition: Lumi2DB.cc:664
virtual const std::string dataType() const override
Definition: Lumi2DB.cc:974
void writeBeamIntensityOnly(coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:141
unsigned int lumilsnr
Definition: Lumi2DB.cc:69
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
list lumirundata
Definition: dataDML.py:2362
void addEntry(coral::ISchema &schema, const std::string &datatableName, const Entry &entry, unsigned long long branch_id, const std::string &branchname)
Definition: RevisionDML.cc:64
tuple pieces
Definition: csv2json.py:31
tuple lumi
Definition: fjr2json.py:35
tuple svc
Definition: dataDML.py:2332
bool hasStableBeam(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:106
const unsigned int N_LUMIALGO
Definition: ConstantDef.h:4
uint16_t size_type
tuple result
Definition: mps_fire.py:95
unsigned int numorbit
Definition: Lumi2DB.cc:71
static const unsigned int COMMITLSINTERVAL
Definition: Lumi2DB.cc:35
std::vector< PerBXData > bxOCC2
Definition: Lumi2DB.cc:74
unsigned int firstsection
Definition: Lumi2DB.cc:44
void insertLumiRunData(coral::ISchema &schema, const LumiEntry &lumientry)
Definition: RevisionDML.cc:126
unsigned long long data_id
Definition: RevisionDML.h:30
virtual char const * what() const
Definition: Exception.h:12
void setAuthentication(const std::string &authPath)
Definition: DBConfig.cc:15
unsigned long long getEntryInBranchByName(coral::ISchema &schema, const std::string &datatableName, const std::string &entryname, const std::string &branchname)
Definition: RevisionDML.cc:17
static const std::string lumisummaryTableName()
Definition: LumiNames.cc:11
int j
Definition: DBlmapReader.cc:9
float applyCalibration(float varToCalibrate) const
Definition: Lumi2DB.cc:102
Lumi2DB(const std::string &dest)
Definition: Lumi2DB.cc:662
unsigned int startorbit
Definition: Lumi2DB.cc:70
unsigned long long revision_id
Definition: RevisionDML.h:28
void cleanTemporaryMemory(lumi::Lumi2DB::LumiResult::iterator lumiBeg, lumi::Lumi2DB::LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:652
void retrieveBeamIntensity(HCAL_HLX::DIP_COMBINED_DATA *dataPtr, Lumi2DB::beamData &b) const
Definition: Lumi2DB.cc:692
unsigned int writeAllLumiDataToSchema2(coral::ISessionProxy *session, const std::string &source, unsigned int runnumber, float bgev, unsigned int ncollidingbunches, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:421
static const std::string lumidataTableName()
Definition: LumiNames.cc:5
unsigned long long entry_id
Definition: RevisionDML.h:29
std::string mode
Definition: Lumi2DB.cc:78
void bookNewEntry(coral::ISchema &schema, const std::string &datatableName, Entry &entry)
Definition: RevisionDML.cc:46
unsigned int cmslsnr
Definition: Lumi2DB.cc:68
virtual const std::string sourceType() const override
Definition: Lumi2DB.cc:977
float m_norm
Definition: DataPipe.h:32
const unsigned int N_BX
Definition: ConstantDef.h:5
static const std::string lumidetailTableName()
Definition: LumiNames.cc:17
double b
Definition: hdecay.h:120
unsigned int ncollidingbunches
Definition: RevisionDML.h:39
static const std::string lumisummaryv2TableName()
Definition: LumiNames.cc:14
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:31
std::vector< PerBXData > bxOCC1
Definition: Lumi2DB.cc:73
double a
Definition: hdecay.h:121
bool isLumiDataValid(LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:123
void writeAllLumiData(coral::ISessionProxy *session, unsigned int irunnumber, const std::string &ilumiversion, LumiResult::iterator lumiBeg, LumiResult::iterator lumiEnd)
Definition: Lumi2DB.cc:217
tuple cout
Definition: gather_cfg.py:145
#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)
Definition: RevisionDML.cc:102
session
Definition: models.py:201
virtual unsigned long long retrieveData(unsigned int) override
Definition: Lumi2DB.cc:732
static std::string const source
Definition: EdmProvDump.cc:43
virtual ~Lumi2DB()
Definition: Lumi2DB.cc:980
std::vector< PerBXData > bxET
Definition: Lumi2DB.cc:72
tuple inputData
Definition: idDealer.py:72
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)
Definition: RevisionDML.cc:56