File indexing completed on 2023-03-17 11:19:55
0001 #ifndef RecoLuminosity_LumiProducer_HLTDummy2DB_h
0002 #define RecoLuminosity_LumiProducer_HLTDummy2DB_h
0003 #include "RelationalAccess/ConnectionService.h"
0004 #include "RelationalAccess/ISessionProxy.h"
0005 #include "RelationalAccess/ITransaction.h"
0006 #include "RelationalAccess/ISchema.h"
0007 #include "RelationalAccess/ITable.h"
0008 #include "RelationalAccess/ITableDataEditor.h"
0009 #include "RelationalAccess/IBulkOperation.h"
0010 #include "CoralBase/AttributeList.h"
0011 #include "CoralBase/AttributeSpecification.h"
0012 #include "CoralBase/Attribute.h"
0013 #include "CoralBase/Exception.h"
0014 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
0015 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
0016 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
0017 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
0018 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
0019 #include <iostream>
0020 #include <cstdio>
0021 namespace lumi {
0022 class HLTDummy2DB : public DataPipe {
0023 public:
0024 HLTDummy2DB(const std::string& dest);
0025 unsigned long long retrieveData(unsigned int) override;
0026 const std::string dataType() const override;
0027 const std::string sourceType() const override;
0028 ~HLTDummy2DB() override;
0029 };
0030
0031
0032
0033 HLTDummy2DB::HLTDummy2DB(const std::string& dest) : DataPipe(dest) {}
0034 unsigned long long HLTDummy2DB::retrieveData(unsigned int runnum) {
0035
0036
0037
0038 coral::ConnectionService* svc = new coral::ConnectionService;
0039 lumi::DBConfig dbconf(*svc);
0040 if (!m_authpath.empty()) {
0041 dbconf.setAuthentication(m_authpath);
0042 }
0043 coral::ISessionProxy* session = svc->connect(m_dest, coral::Update);
0044 try {
0045 unsigned int totalcmsls = 32;
0046 session->transaction().start(false);
0047 coral::ISchema& schema = session->nominalSchema();
0048 lumi::idDealer idg(schema);
0049 coral::ITable& hlttable = schema.tableHandle(LumiNames::hltTableName());
0050 coral::AttributeList hltData;
0051 hltData.extend<unsigned long long>("HLT_ID");
0052 hltData.extend<unsigned int>("RUNNUM");
0053 hltData.extend<unsigned int>("CMSLSNUM");
0054 hltData.extend<std::string>("PATHNAME");
0055 hltData.extend<unsigned long long>("INPUTCOUNT");
0056 hltData.extend<unsigned long long>("ACCEPTCOUNT");
0057 hltData.extend<unsigned int>("PRESCALE");
0058 coral::IBulkOperation* hltInserter = hlttable.dataEditor().bulkInsert(hltData, totalcmsls * 260);
0059
0060 unsigned long long& hlt_id = hltData["HLT_ID"].data<unsigned long long>();
0061 unsigned int& hltrunnum = hltData["RUNNUM"].data<unsigned int>();
0062 unsigned int& cmslsnum = hltData["CMSLSNUM"].data<unsigned int>();
0063 std::string& pathname = hltData["PATHNAME"].data<std::string>();
0064 unsigned long long& inputcount = hltData["INPUTCOUNT"].data<unsigned long long>();
0065 unsigned long long& acceptcount = hltData["ACCEPTCOUNT"].data<unsigned long long>();
0066 unsigned int& prescale = hltData["PRESCALE"].data<unsigned int>();
0067
0068 for (unsigned int i = 1; i <= totalcmsls; ++i) {
0069 for (unsigned int j = 1; j < 165; ++j) {
0070 hlt_id = idg.generateNextIDForTable(LumiNames::hltTableName());
0071 hltrunnum = runnum;
0072 cmslsnum = i;
0073 char c[10];
0074 ::sprintf(c, "%d", j);
0075 pathname = std::string("FakeHLTPath_") + std::string(c);
0076 inputcount = 12345;
0077 acceptcount = 10;
0078 prescale = 1;
0079 hltInserter->processNextIteration();
0080 }
0081 }
0082 hltInserter->flush();
0083 delete hltInserter;
0084 } catch (const coral::Exception& er) {
0085 std::cout << "database problem " << er.what() << std::endl;
0086 session->transaction().rollback();
0087 delete session;
0088 delete svc;
0089 throw er;
0090 }
0091
0092 session->transaction().commit();
0093 delete session;
0094 delete svc;
0095 return 0;
0096 }
0097 const std::string HLTDummy2DB::dataType() const { return "HLT"; }
0098 const std::string HLTDummy2DB::sourceType() const { return "DUMMY"; }
0099 HLTDummy2DB::~HLTDummy2DB() {}
0100 }
0101 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
0102 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory, lumi::HLTDummy2DB, "HLTDummy2DB");
0103 #endif