CMS 3D CMS Logo

TRGDummy2DB.cc
Go to the documentation of this file.
1 #ifndef RecoLuminosity_LumiProducer_TRGDummy2DB_h
2 #define RecoLuminosity_LumiProducer_TRGDummy2DB_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/Attribute.h"
14 #include "CoralBase/Exception.h"
21 
22 #include <iostream>
23 #include <cstdio>
24 namespace lumi {
25  class TRGDummy2DB : public DataPipe {
26  public:
28  unsigned long long retrieveData(unsigned int) override;
29  const std::string dataType() const override;
30  const std::string sourceType() const override;
31  ~TRGDummy2DB() override;
32  }; //cl TRGDummy2DB
33  //
34  //implementation
35  //
37  unsigned long long TRGDummy2DB::retrieveData(unsigned int runnum) {
38  //
39  //generate dummy data of trg for the given run and write data to LumiDB
40  //
41  coral::ConnectionService* svc = new coral::ConnectionService;
42  lumi::DBConfig dbconf(*svc);
43 
44  if (!m_authpath.empty()) {
46  }
47  coral::ISessionProxy* session = svc->connect(m_dest, coral::Update);
48  coral::ITypeConverter& tpc = session->typeConverter();
49  tpc.setCppTypeForSqlType("unsigned int", "NUMBER(7)");
50  tpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
51  tpc.setCppTypeForSqlType("unsigned long long", "NUMBER(20)");
52  try {
53  unsigned int totalcmsls = 32;
54  session->transaction().start(false);
55  coral::ISchema& schema = session->nominalSchema();
56  lumi::idDealer idg(schema);
57  coral::ITable& trgtable = schema.tableHandle(LumiNames::trgTableName());
58  coral::AttributeList trgData;
59  trgData.extend("TRG_ID", typeid(unsigned long long));
60  trgData.extend("RUNNUM", typeid(unsigned int));
61  trgData.extend("CMSLSNUM", typeid(unsigned int));
62  trgData.extend("BITNUM", typeid(unsigned int));
63  trgData.extend("BITNAME", typeid(std::string));
64  trgData.extend("TRGCOUNT", typeid(unsigned int));
65  trgData.extend("DEADTIME", typeid(unsigned long long));
66  trgData.extend("PRESCALE", typeid(unsigned int));
67  coral::IBulkOperation* trgInserter =
68  trgtable.dataEditor().bulkInsert(trgData, totalcmsls * (lumi::N_TRGALGOBIT + lumi::N_TRGTECHBIT));
69  //loop over lumi LS
70  unsigned long long& trg_id = trgData["TRG_ID"].data<unsigned long long>();
71  unsigned int& trgrunnum = trgData["RUNNUM"].data<unsigned int>();
72  unsigned int& cmslsnum = trgData["CMSLSNUM"].data<unsigned int>();
73  unsigned int& bitnum = trgData["BITNUM"].data<unsigned int>();
74  std::string& bitname = trgData["BITNAME"].data<std::string>();
75  unsigned int& count = trgData["TRGCOUNT"].data<unsigned int>();
76  unsigned long long& deadtime = trgData["DEADTIME"].data<unsigned long long>();
77  unsigned int& prescale = trgData["PRESCALE"].data<unsigned int>();
78 
79  for (unsigned int i = 1; i <= totalcmsls; ++i) {
80  for (unsigned int j = 0; j < (lumi::N_TRGALGOBIT + lumi::N_TRGTECHBIT); ++j) { //total n of trg bits
82  trgrunnum = runnum;
83  cmslsnum = i;
84  bitnum = j;
85  char c[10];
86  if (j > (lumi::N_TRGALGOBIT - 1)) {
87  ::sprintf(c, "%d", j - (lumi::N_TRGALGOBIT - 1));
88  bitname = std::string(c);
89  } else {
90  ::sprintf(c, "%d", j);
91  bitname = std::string("FakeTRGBIT_") + std::string(c);
92  }
93  count = 12345;
94  deadtime = 6785;
95  prescale = 1;
96  trgInserter->processNextIteration();
97  }
98  }
99  trgInserter->flush();
100  delete trgInserter;
101  } catch (const coral::Exception& er) {
102  std::cout << "database problem " << er.what() << std::endl;
103  session->transaction().rollback();
104  delete session;
105  delete svc;
106  throw er;
107  }
108  //delete detailInserter;
109  session->transaction().commit();
110  delete session;
111  delete svc;
112  return 0;
113  }
114  const std::string TRGDummy2DB::dataType() const { return "TRG"; }
115  const std::string TRGDummy2DB::sourceType() const { return "DUMMY"; }
117 } // namespace lumi
120 #endif
lumi::TRGDummy2DB::TRGDummy2DB
TRGDummy2DB(const std::string &dest)
Definition: TRGDummy2DB.cc:36
mps_fire.i
i
Definition: mps_fire.py:355
DataPipe.h
lumi::DataPipe::m_dest
std::string m_dest
Definition: DataPipe.h:27
idDealer.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
lumi::DataPipe
Definition: DataPipe.h:8
lumi::TRGDummy2DB::dataType
const std::string dataType() const override
Definition: TRGDummy2DB.cc:114
lumi::TRGDummy2DB::~TRGDummy2DB
~TRGDummy2DB() override
Definition: TRGDummy2DB.cc:116
lumi::DBConfig::setAuthentication
void setAuthentication(const std::string &authPath)
Definition: DBConfig.cc:13
LumiNames.h
lumi::N_TRGTECHBIT
const unsigned int N_TRGTECHBIT
Definition: ConstantDef.h:7
DataPipeFactory.h
lumi::idDealer::generateNextIDForTable
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:33
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
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
edmplugin::PluginFactory
Definition: PluginFactory.h:34
lumi::TRGDummy2DB
Definition: TRGDummy2DB.cc:25
lumi::DBConfig
Definition: DBConfig.h:8
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
prescale
Definition: PrescaleEventFilter.cc:32
lumi::N_TRGALGOBIT
const unsigned int N_TRGALGOBIT
Definition: ConstantDef.h:6
Exception
Definition: hltDiff.cc:246
lumi::TRGDummy2DB::sourceType
const std::string sourceType() const override
Definition: TRGDummy2DB.cc:115
Exception.h
DBConfig.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
lumi::idDealer
Definition: idDealer.h:8
lumi::TRGDummy2DB::retrieveData
unsigned long long retrieveData(unsigned int) override
Definition: TRGDummy2DB.cc:37
lumi
Definition: LumiSectionData.h:20
lumi::LumiNames::trgTableName
static const std::string trgTableName()
Definition: LumiNames.cc:13
mps_fire.dest
dest
Definition: mps_fire.py:179
ConstantDef.h