Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:20

0001 #ifndef RecoLuminosity_LumiProducer_CMSRunSummaryDummy2DB_H
0002 #define RecoLuminosity_LumiProducer_CMSRunSummaryDummy2DB_H
0003 #include "RelationalAccess/ConnectionService.h"
0004 #include "RelationalAccess/ISessionProxy.h"
0005 #include "RelationalAccess/ITransaction.h"
0006 #include "RelationalAccess/ITypeConverter.h"
0007 #include "RelationalAccess/ISchema.h"
0008 #include "RelationalAccess/ITable.h"
0009 #include "RelationalAccess/ITableDataEditor.h"
0010 #include "CoralBase/TimeStamp.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/Exception.h"
0018 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
0019 #include <iostream>
0020 namespace lumi {
0021   class CMSRunSummaryDummy2DB : public DataPipe {
0022   public:
0023     CMSRunSummaryDummy2DB(const std::string& dest);
0024     unsigned long long retrieveData(unsigned int) override;
0025     const std::string dataType() const override;
0026     const std::string sourceType() const override;
0027     ~CMSRunSummaryDummy2DB() override;
0028   };  //cl CMSRunSummaryDummy2DB
0029   //
0030   //implementation
0031   //
0032   CMSRunSummaryDummy2DB::CMSRunSummaryDummy2DB(const std::string& dest) : DataPipe(dest) {}
0033   unsigned long long CMSRunSummaryDummy2DB::retrieveData(unsigned int runnum) {
0034     //
0035     //generate dummy data of run summary for the given run and write data to LumiDB
0036     //
0037     std::string fakehltkey("/cdaq/Cosmic/V12");
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     coral::ITypeConverter& tpc = session->typeConverter();
0045     tpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
0046     try {
0047       session->transaction().start(false);
0048       coral::ISchema& schema = session->nominalSchema();
0049       coral::ITable& runtable = schema.tableHandle(LumiNames::cmsrunsummaryTableName());
0050       coral::AttributeList runData;
0051       runtable.dataEditor().rowBuffer(runData);
0052       runData["RUNNUM"].data<unsigned int>() = runnum;
0053       runData["FILLNUM"].data<unsigned int>() = 8973344;
0054       runData["SEQUENCE"].data<std::string>() = "run sequence key";
0055       runData["HLTKEY"].data<std::string>() = fakehltkey;
0056       runData["STARTTIME"].data<coral::TimeStamp>() = coral::TimeStamp::now();
0057       runData["STOPTIME"].data<coral::TimeStamp>() = coral::TimeStamp::now();
0058 
0059       runtable.dataEditor().insertRow(runData);
0060     } catch (const coral::Exception& er) {
0061       std::cout << "database problem " << er.what() << std::endl;
0062       session->transaction().rollback();
0063       delete session;
0064       delete svc;
0065       throw er;
0066     }
0067     session->transaction().commit();
0068     delete session;
0069     delete svc;
0070     return 0;
0071   }
0072   const std::string CMSRunSummaryDummy2DB::dataType() const { return "CMSRUNSUMMARY"; }
0073   const std::string CMSRunSummaryDummy2DB::sourceType() const { return "DUMMY"; }
0074   CMSRunSummaryDummy2DB::~CMSRunSummaryDummy2DB() {}
0075 }  // namespace lumi
0076 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
0077 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory, lumi::CMSRunSummaryDummy2DB, "CMSRunSummaryDummy2DB");
0078 #endif