File indexing completed on 2024-04-06 12:26:36
0001 #ifndef RecoLuminosity_LumiProducer_TRGDummy2DB_h
0002 #define RecoLuminosity_LumiProducer_TRGDummy2DB_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 "RelationalAccess/ITypeConverter.h"
0011 #include "CoralBase/AttributeList.h"
0012 #include "CoralBase/AttributeSpecification.h"
0013 #include "CoralBase/Attribute.h"
0014 #include "CoralBase/Exception.h"
0015 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
0016 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
0017 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
0018 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
0019 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
0020 #include "RecoLuminosity/LumiProducer/interface/ConstantDef.h"
0021
0022 #include <iostream>
0023 #include <cstdio>
0024 namespace lumi {
0025 class TRGDummy2DB : public DataPipe {
0026 public:
0027 TRGDummy2DB(const std::string& dest);
0028 unsigned long long retrieveData(unsigned int) override;
0029 const std::string dataType() const override;
0030 const std::string sourceType() const override;
0031 ~TRGDummy2DB() override;
0032 };
0033
0034
0035
0036 TRGDummy2DB::TRGDummy2DB(const std::string& dest) : DataPipe(dest) {}
0037 unsigned long long TRGDummy2DB::retrieveData(unsigned int runnum) {
0038
0039
0040
0041 coral::ConnectionService* svc = new coral::ConnectionService;
0042 lumi::DBConfig dbconf(*svc);
0043
0044 if (!m_authpath.empty()) {
0045 dbconf.setAuthentication(m_authpath);
0046 }
0047 coral::ISessionProxy* session = svc->connect(m_dest, coral::Update);
0048 coral::ITypeConverter& tpc = session->typeConverter();
0049 tpc.setCppTypeForSqlType("unsigned int", "NUMBER(7)");
0050 tpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
0051 tpc.setCppTypeForSqlType("unsigned long long", "NUMBER(20)");
0052 try {
0053 unsigned int totalcmsls = 32;
0054 session->transaction().start(false);
0055 coral::ISchema& schema = session->nominalSchema();
0056 lumi::idDealer idg(schema);
0057 coral::ITable& trgtable = schema.tableHandle(LumiNames::trgTableName());
0058 coral::AttributeList trgData;
0059 trgData.extend("TRG_ID", typeid(unsigned long long));
0060 trgData.extend("RUNNUM", typeid(unsigned int));
0061 trgData.extend("CMSLSNUM", typeid(unsigned int));
0062 trgData.extend("BITNUM", typeid(unsigned int));
0063 trgData.extend("BITNAME", typeid(std::string));
0064 trgData.extend("TRGCOUNT", typeid(unsigned int));
0065 trgData.extend("DEADTIME", typeid(unsigned long long));
0066 trgData.extend("PRESCALE", typeid(unsigned int));
0067 coral::IBulkOperation* trgInserter =
0068 trgtable.dataEditor().bulkInsert(trgData, totalcmsls * (lumi::N_TRGALGOBIT + lumi::N_TRGTECHBIT));
0069
0070 unsigned long long& trg_id = trgData["TRG_ID"].data<unsigned long long>();
0071 unsigned int& trgrunnum = trgData["RUNNUM"].data<unsigned int>();
0072 unsigned int& cmslsnum = trgData["CMSLSNUM"].data<unsigned int>();
0073 unsigned int& bitnum = trgData["BITNUM"].data<unsigned int>();
0074 std::string& bitname = trgData["BITNAME"].data<std::string>();
0075 unsigned int& count = trgData["TRGCOUNT"].data<unsigned int>();
0076 unsigned long long& deadtime = trgData["DEADTIME"].data<unsigned long long>();
0077 unsigned int& prescale = trgData["PRESCALE"].data<unsigned int>();
0078
0079 for (unsigned int i = 1; i <= totalcmsls; ++i) {
0080 for (unsigned int j = 0; j < (lumi::N_TRGALGOBIT + lumi::N_TRGTECHBIT); ++j) {
0081 trg_id = idg.generateNextIDForTable(LumiNames::trgTableName());
0082 trgrunnum = runnum;
0083 cmslsnum = i;
0084 bitnum = j;
0085 char c[10];
0086 if (j > (lumi::N_TRGALGOBIT - 1)) {
0087 ::sprintf(c, "%d", j - (lumi::N_TRGALGOBIT - 1));
0088 bitname = std::string(c);
0089 } else {
0090 ::sprintf(c, "%d", j);
0091 bitname = std::string("FakeTRGBIT_") + std::string(c);
0092 }
0093 count = 12345;
0094 deadtime = 6785;
0095 prescale = 1;
0096 trgInserter->processNextIteration();
0097 }
0098 }
0099 trgInserter->flush();
0100 delete trgInserter;
0101 } catch (const coral::Exception& er) {
0102 std::cout << "database problem " << er.what() << std::endl;
0103 session->transaction().rollback();
0104 delete session;
0105 delete svc;
0106 throw er;
0107 }
0108
0109 session->transaction().commit();
0110 delete session;
0111 delete svc;
0112 return 0;
0113 }
0114 const std::string TRGDummy2DB::dataType() const { return "TRG"; }
0115 const std::string TRGDummy2DB::sourceType() const { return "DUMMY"; }
0116 TRGDummy2DB::~TRGDummy2DB() {}
0117 }
0118 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
0119 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory, lumi::TRGDummy2DB, "TRGDummy2DB");
0120 #endif