CMS 3D CMS Logo

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  unsigned long long retrieveData(unsigned int) override;
31  const std::string dataType() const override;
32  const std::string sourceType() const override;
33  ~LumiDummy2DB() override;
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)
142  algoname = std::string("ET");
143  if (j == 1)
144  algoname = std::string("OCC1");
145  if (j == 2)
146  algoname = std::string("OCC2");
147  float lumivalue[N_BX];
148  std::memset((void*)&lumivalue, 0, sizeof(float) * N_BX);
149  float lumierror[N_BX];
150  std::memset((void*)&lumierror, 0, sizeof(float) * N_BX);
151  short lumiquality[N_BX];
152  std::memset((void*)&lumiquality, 0, sizeof(short) * N_BX);
153  bxlumivalue.resize(sizeof(float) * N_BX);
154  bxlumierror.resize(sizeof(float) * N_BX);
155  bxlumiquality.resize(sizeof(short) * N_BX);
156  void* bxlumivalueStartAddress = bxlumivalue.startingAddress();
157  void* bxlumierrorStartAddress = bxlumierror.startingAddress();
158  void* bxlumiqualityStartAddress = bxlumiquality.startingAddress();
159  for (unsigned int k = 0; k < N_BX; ++k) {
160  lumivalue[k] = 1.5;
161  lumierror[k] = 0.1;
162  lumiquality[k] = 1;
163  }
164  std::memmove(bxlumivalueStartAddress, lumivalue, sizeof(float) * N_BX);
165  std::memmove(bxlumierrorStartAddress, lumierror, sizeof(float) * N_BX);
166  std::memmove(bxlumiqualityStartAddress, lumiquality, sizeof(short) * N_BX);
167  detailInserter->processNextIteration();
168  }
169  }
170  detailInserter->flush();
171  delete summaryInserter;
172  delete detailInserter;
173  } catch (const coral::Exception& er) {
174  session->transaction().rollback();
175  delete session;
176  delete svc;
177  throw er;
178  }
179  //delete detailInserter;
180  session->transaction().commit();
181  delete session;
182  delete svc;
183  return 0;
184  }
185  const std::string LumiDummy2DB::dataType() const { return "LUMI"; }
186  const std::string LumiDummy2DB::sourceType() const { return "DUMMY"; }
188 } // namespace lumi
191 #endif
FastTimerService_cff.lumiversion
lumiversion
Definition: FastTimerService_cff.py:13
mps_fire.i
i
Definition: mps_fire.py:428
lumi::LumiDummy2DB::dataType
const std::string dataType() const override
Definition: LumiDummy2DB.cc:185
DataPipe.h
lumi::DataPipe::m_dest
std::string m_dest
Definition: DataPipe.h:27
idDealer.h
lumi::DataPipe
Definition: DataPipe.h:8
lumi::DBConfig::setAuthentication
void setAuthentication(const std::string &authPath)
Definition: DBConfig.cc:15
LumiNames.h
DataPipeFactory.h
lumi::LumiDummy2DB::LumiDummy2DB
LumiDummy2DB(const std::string &dest)
Definition: LumiDummy2DB.cc:38
lumi::LumiDummy2DB::~LumiDummy2DB
~LumiDummy2DB() override
Definition: LumiDummy2DB.cc:187
lumi::LumiNames::lumisummaryTableName
static const std::string lumisummaryTableName()
Definition: LumiNames.cc:5
lumi::idDealer::generateNextIDForTable
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:33
lumi::LumiNames::lumidetailTableName
static const std::string lumidetailTableName()
Definition: LumiNames.cc:7
dqmdumpme.k
k
Definition: dqmdumpme.py:60
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
lumi::DataPipe::m_authpath
std::string m_authpath
Definition: DataPipe.h:29
lumi::LumiDummy2DB
Definition: LumiDummy2DB.cc:27
edmplugin::PluginFactory
Definition: PluginFactory.h:34
lumi::DBConfig
Definition: DBConfig.h:8
lumi::N_LUMIALGO
const unsigned int N_LUMIALGO
Definition: ConstantDef.h:4
Exception
Definition: hltDiff.cc:245
lumi::LumiDummy2DB::sourceType
const std::string sourceType() const override
Definition: LumiDummy2DB.cc:186
Exception.h
DBConfig.h
lumi::LumiDummy2DB::retrieveData
unsigned long long retrieveData(unsigned int) override
Definition: LumiDummy2DB.cc:41
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
lumi::idDealer
Definition: idDealer.h:8
lumi
Definition: LumiSectionData.h:20
lumi::N_BX
const unsigned int N_BX
Definition: ConstantDef.h:5
mps_fire.dest
dest
Definition: mps_fire.py:179
ConstantDef.h