test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LumiDummy2DB.cc
Go to the documentation of this file.
1 #ifndef RecoLuminosity_LumiProducer_LumiDummy2DB_H
2 #define RecoLuminosity_LumiProducer_LumiDummy2DB_H
3 #include "RelationalAccess/ConnectionService.h"
4 #include "RelationalAccess/ISessionProxy.h"
5 #include "RelationalAccess/ITransaction.h"
6 #include "RelationalAccess/ISchema.h"
7 #include "RelationalAccess/ITable.h"
8 #include "RelationalAccess/ITableDataEditor.h"
9 #include "RelationalAccess/IBulkOperation.h"
10 #include "RelationalAccess/ITypeConverter.h"
11 #include "CoralBase/AttributeList.h"
12 #include "CoralBase/AttributeSpecification.h"
13 #include "CoralBase/AttributeList.h"
14 #include "CoralBase/Attribute.h"
15 #include "CoralBase/Blob.h"
16 #include "CoralBase/Exception.h"
17 
24 //#include <iostream>
25 #include <cstring>
26 namespace lumi{
27  class LumiDummy2DB : public DataPipe{
28  public:
30  virtual unsigned long long retrieveData( unsigned int ) override;
31  virtual const std::string dataType() const override;
32  virtual const std::string sourceType() const override;
33  virtual ~LumiDummy2DB();
34  };//cl LumiDummy2DB
35  //
36  //implementation
37  //
39  //check the format of dest
40  }
41  unsigned long long LumiDummy2DB::retrieveData( unsigned int runnum){
42  //
43  //generate dummy data for lumi summary and detail for the given run and write data to LumiDB
44  //
45  coral::ConnectionService* svc=new coral::ConnectionService;
46  lumi::DBConfig dbconf(*svc);
47  if(!m_authpath.empty()){
49  }
50  coral::ISessionProxy* session=svc->connect(m_dest,coral::Update);
51  coral::ITypeConverter& tpc=session->typeConverter();
52  tpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
53  try{
54  unsigned int totallumils=35;
55  unsigned int totalcmsls=32;
56  session->transaction().start(false);
57  coral::ISchema& schema=session->nominalSchema();
58  lumi::idDealer idg(schema);
59  coral::ITable& summarytable=schema.tableHandle(LumiNames::lumisummaryTableName());
60  coral::ITable& detailtable=schema.tableHandle(LumiNames::lumidetailTableName());
61  coral::AttributeList summaryData;
62  summaryData.extend("LUMISUMMARY_ID",typeid(unsigned long long));
63  summaryData.extend("RUNNUM",typeid(unsigned int));
64  summaryData.extend("CMSLSNUM",typeid(unsigned int));
65  summaryData.extend("LUMILSNUM",typeid(unsigned int));
66  summaryData.extend("LUMIVERSION",typeid(std::string));
67  summaryData.extend("DTNORM",typeid(float));
68  summaryData.extend("LHCNORM",typeid(float));
69  summaryData.extend("INSTLUMI",typeid(float));
70  summaryData.extend("INSTLUMIERROR",typeid(float));
71  summaryData.extend("INSTLUMIQUALITY",typeid(short));
72  summaryData.extend("LUMISECTIONQUALITY",typeid(short));
73  summaryData.extend("CMSALIVE",typeid(short));
74  summaryData.extend("STARTORBIT",typeid(unsigned int));
75  summaryData.extend("NUMORBIT",typeid(unsigned int));
76  summaryData.extend("BEAMENERGY",typeid(float));
77  summaryData.extend("BEAMSTATUS",typeid(std::string));
78 
79  coral::IBulkOperation* summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
80  coral::AttributeList detailData;
81  detailData.extend("LUMIDETAIL_ID",typeid(unsigned long long));
82  detailData.extend("LUMISUMMARY_ID",typeid(unsigned long long));
83  detailData.extend("BXLUMIVALUE",typeid(coral::Blob));
84  detailData.extend("BXLUMIERROR",typeid(coral::Blob));
85  detailData.extend("BXLUMIQUALITY",typeid(coral::Blob));
86  detailData.extend("ALGONAME",typeid(std::string));
87  coral::IBulkOperation* detailInserter=detailtable.dataEditor().bulkInsert(detailData,totallumils*N_LUMIALGO);
88  //loop over lumi LS
89  unsigned long long& lumisummary_id=summaryData["LUMISUMMARY_ID"].data<unsigned long long>();
90  unsigned int& lumirunnum = summaryData["RUNNUM"].data<unsigned int>();
91  unsigned int& cmslsnum=summaryData["CMSLSNUM"].data<unsigned int>();
92  unsigned int& lumilsnum=summaryData["LUMILSNUM"].data<unsigned int>();
93  std::string& lumiversion = summaryData["LUMIVERSION"].data<std::string>();
94  float& dtnorm = summaryData["DTNORM"].data<float>();
95  float& lhcnorm = summaryData["LHCNORM"].data<float>();
96  float& instlumi = summaryData["INSTLUMI"].data<float>();
97  float& instlumierror = summaryData["INSTLUMIERROR"].data<float>();
98  short& instlumiquality = summaryData["INSTLUMIQUALITY"].data<short>();
99  short& lumisectionquality = summaryData["LUMISECTIONQUALITY"].data<short>();
100  short& cmsalive = summaryData["CMSALIVE"].data<short>();
101  unsigned int& startorbit=summaryData["STARTORBIT"].data<unsigned int>();
102  unsigned int& numorbit= summaryData["NUMORBIT"].data<unsigned int>();
103  float& beamenergy= summaryData["BEAMENERGY"].data<float>();
104  std::string& beamstatus= summaryData["BEAMSTATUS"].data<std::string>();
105 
106  unsigned long long& lumidetail_id=detailData["LUMIDETAIL_ID"].data<unsigned long long>();
107  unsigned long long& d2lumisummary_id=detailData["LUMISUMMARY_ID"].data<unsigned long long>();
108  coral::Blob& bxlumivalue=detailData["BXLUMIVALUE"].data<coral::Blob>();
109  coral::Blob& bxlumierror=detailData["BXLUMIERROR"].data<coral::Blob>();
110  coral::Blob& bxlumiquality=detailData["BXLUMIQUALITY"].data<coral::Blob>();
111  std::string& algoname=detailData["ALGONAME"].data<std::string>();
112  for(unsigned int i=1;i<=totallumils;++i){
114  lumilsnum=i;
115  lumirunnum = runnum;
116  lumiversion = "0";
117  dtnorm = 1.05;
118  lhcnorm = 1.2;
119  instlumi = 0.9;
120  instlumierror = 0.01;
121  instlumiquality = 8;
122  lumisectionquality = 16;
123  // unsigned int cmslsnum = 0;
124  short iscmsalive = 0;
125  if(i<=totalcmsls){
126  iscmsalive=1;
127  cmslsnum=i;
128  }
129  cmsalive=iscmsalive;
130  startorbit=2837495;
131  numorbit=34566;
132  beamenergy=362;
133  beamstatus="stable";
134  //fetch a new id value
135  //insert the new row
136  summaryInserter->processNextIteration();
137  summaryInserter->flush();
138  d2lumisummary_id=i;
139  for( unsigned int j=0; j<N_LUMIALGO; ++j ){
141  if(j==0) algoname=std::string("ET");
142  if(j==1) algoname=std::string("OCC1");
143  if(j==2) algoname=std::string("OCC2");
144  float lumivalue[N_BX];
145  std::memset((void*)&lumivalue,0,sizeof(float)*N_BX);
146  float lumierror[N_BX];
147  std::memset((void*)&lumierror,0,sizeof(float)*N_BX );
148  short lumiquality[N_BX];
149  std::memset((void*)&lumiquality,0,sizeof(short)*N_BX );
150  bxlumivalue.resize(sizeof(float)*N_BX);
151  bxlumierror.resize(sizeof(float)*N_BX);
152  bxlumiquality.resize(sizeof(short)*N_BX);
153  void* bxlumivalueStartAddress=bxlumivalue.startingAddress();
154  void* bxlumierrorStartAddress=bxlumierror.startingAddress();
155  void* bxlumiqualityStartAddress=bxlumiquality.startingAddress();
156  for( unsigned int k=0; k<N_BX; ++k ){
157  lumivalue[k]=1.5;
158  lumierror[k]=0.1;
159  lumiquality[k]=1;
160  }
161  std::memmove(bxlumivalueStartAddress,lumivalue,sizeof(float)*N_BX);
162  std::memmove(bxlumierrorStartAddress,lumierror,sizeof(float)*N_BX);
163  std::memmove(bxlumiqualityStartAddress,lumiquality,sizeof(short)*N_BX);
164  detailInserter->processNextIteration();
165  }
166  }
167  detailInserter->flush();
168  delete summaryInserter;
169  delete detailInserter;
170  }catch( const coral::Exception& er){
171  session->transaction().rollback();
172  delete session;
173  delete svc;
174  throw er;
175  }
176  //delete detailInserter;
177  session->transaction().commit();
178  delete session;
179  delete svc;
180  return 0;
181  }
183  return "LUMI";
184  }
186  return "DUMMY";
187  }
189 }//ns lumi
192 #endif
virtual unsigned long long retrieveData(unsigned int) override
Definition: LumiDummy2DB.cc:41
int i
Definition: DBlmapReader.cc:9
tuple schema
Definition: dataDML.py:2334
tuple lumi
Definition: fjr2json.py:35
tuple svc
Definition: dataDML.py:2332
const unsigned int N_LUMIALGO
Definition: ConstantDef.h:4
LumiDummy2DB(const std::string &dest)
Definition: LumiDummy2DB.cc:38
std::string m_dest
Definition: DataPipe.h:27
virtual const std::string dataType() const override
void setAuthentication(const std::string &authPath)
Definition: DBConfig.cc:15
static const std::string lumisummaryTableName()
Definition: LumiNames.cc:11
int j
Definition: DBlmapReader.cc:9
list lumilsnum
Definition: lumiPlot.py:485
virtual ~LumiDummy2DB()
const unsigned int N_BX
Definition: ConstantDef.h:5
static const std::string lumidetailTableName()
Definition: LumiNames.cc:17
virtual const std::string sourceType() const override
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:31
std::string m_authpath
Definition: DataPipe.h:29
#define DEFINE_EDM_PLUGIN(factory, type, name)
tuple runnum
Definition: summaryLumi.py:210
session
Definition: models.py:201