Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:36

0001 #ifndef RecoLuminosity_LumiProducer_LumiDummy2DB_H
0002 #define RecoLuminosity_LumiProducer_LumiDummy2DB_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/AttributeList.h"
0014 #include "CoralBase/Attribute.h"
0015 #include "CoralBase/Blob.h"
0016 #include "CoralBase/Exception.h"
0017 
0018 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
0019 #include "RecoLuminosity/LumiProducer/interface/ConstantDef.h"
0020 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
0021 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
0022 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
0023 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
0024 //#include <iostream>
0025 #include <cstring>
0026 namespace lumi {
0027   class LumiDummy2DB : public DataPipe {
0028   public:
0029     LumiDummy2DB(const std::string& dest);
0030     unsigned long long retrieveData(unsigned int) override;
0031     const std::string dataType() const override;
0032     const std::string sourceType() const override;
0033     ~LumiDummy2DB() override;
0034   };  //cl LumiDummy2DB
0035   //
0036   //implementation
0037   //
0038   LumiDummy2DB::LumiDummy2DB(const std::string& dest) : DataPipe(dest) {
0039     //check the format of dest
0040   }
0041   unsigned long long LumiDummy2DB::retrieveData(unsigned int runnum) {
0042     //
0043     //generate dummy data for lumi summary and detail for the given run and write data to LumiDB
0044     //
0045     coral::ConnectionService* svc = new coral::ConnectionService;
0046     lumi::DBConfig dbconf(*svc);
0047     if (!m_authpath.empty()) {
0048       dbconf.setAuthentication(m_authpath);
0049     }
0050     coral::ISessionProxy* session = svc->connect(m_dest, coral::Update);
0051     coral::ITypeConverter& tpc = session->typeConverter();
0052     tpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
0053     try {
0054       unsigned int totallumils = 35;
0055       unsigned int totalcmsls = 32;
0056       session->transaction().start(false);
0057       coral::ISchema& schema = session->nominalSchema();
0058       lumi::idDealer idg(schema);
0059       coral::ITable& summarytable = schema.tableHandle(LumiNames::lumisummaryTableName());
0060       coral::ITable& detailtable = schema.tableHandle(LumiNames::lumidetailTableName());
0061       coral::AttributeList summaryData;
0062       summaryData.extend("LUMISUMMARY_ID", typeid(unsigned long long));
0063       summaryData.extend("RUNNUM", typeid(unsigned int));
0064       summaryData.extend("CMSLSNUM", typeid(unsigned int));
0065       summaryData.extend("LUMILSNUM", typeid(unsigned int));
0066       summaryData.extend("LUMIVERSION", typeid(std::string));
0067       summaryData.extend("DTNORM", typeid(float));
0068       summaryData.extend("LHCNORM", typeid(float));
0069       summaryData.extend("INSTLUMI", typeid(float));
0070       summaryData.extend("INSTLUMIERROR", typeid(float));
0071       summaryData.extend("INSTLUMIQUALITY", typeid(short));
0072       summaryData.extend("LUMISECTIONQUALITY", typeid(short));
0073       summaryData.extend("CMSALIVE", typeid(short));
0074       summaryData.extend("STARTORBIT", typeid(unsigned int));
0075       summaryData.extend("NUMORBIT", typeid(unsigned int));
0076       summaryData.extend("BEAMENERGY", typeid(float));
0077       summaryData.extend("BEAMSTATUS", typeid(std::string));
0078 
0079       coral::IBulkOperation* summaryInserter = summarytable.dataEditor().bulkInsert(summaryData, totallumils);
0080       coral::AttributeList detailData;
0081       detailData.extend("LUMIDETAIL_ID", typeid(unsigned long long));
0082       detailData.extend("LUMISUMMARY_ID", typeid(unsigned long long));
0083       detailData.extend("BXLUMIVALUE", typeid(coral::Blob));
0084       detailData.extend("BXLUMIERROR", typeid(coral::Blob));
0085       detailData.extend("BXLUMIQUALITY", typeid(coral::Blob));
0086       detailData.extend("ALGONAME", typeid(std::string));
0087       coral::IBulkOperation* detailInserter = detailtable.dataEditor().bulkInsert(detailData, totallumils * N_LUMIALGO);
0088       //loop over lumi LS
0089       unsigned long long& lumisummary_id = summaryData["LUMISUMMARY_ID"].data<unsigned long long>();
0090       unsigned int& lumirunnum = summaryData["RUNNUM"].data<unsigned int>();
0091       unsigned int& cmslsnum = summaryData["CMSLSNUM"].data<unsigned int>();
0092       unsigned int& lumilsnum = summaryData["LUMILSNUM"].data<unsigned int>();
0093       std::string& lumiversion = summaryData["LUMIVERSION"].data<std::string>();
0094       float& dtnorm = summaryData["DTNORM"].data<float>();
0095       float& lhcnorm = summaryData["LHCNORM"].data<float>();
0096       float& instlumi = summaryData["INSTLUMI"].data<float>();
0097       float& instlumierror = summaryData["INSTLUMIERROR"].data<float>();
0098       short& instlumiquality = summaryData["INSTLUMIQUALITY"].data<short>();
0099       short& lumisectionquality = summaryData["LUMISECTIONQUALITY"].data<short>();
0100       short& cmsalive = summaryData["CMSALIVE"].data<short>();
0101       unsigned int& startorbit = summaryData["STARTORBIT"].data<unsigned int>();
0102       unsigned int& numorbit = summaryData["NUMORBIT"].data<unsigned int>();
0103       float& beamenergy = summaryData["BEAMENERGY"].data<float>();
0104       std::string& beamstatus = summaryData["BEAMSTATUS"].data<std::string>();
0105 
0106       unsigned long long& lumidetail_id = detailData["LUMIDETAIL_ID"].data<unsigned long long>();
0107       unsigned long long& d2lumisummary_id = detailData["LUMISUMMARY_ID"].data<unsigned long long>();
0108       coral::Blob& bxlumivalue = detailData["BXLUMIVALUE"].data<coral::Blob>();
0109       coral::Blob& bxlumierror = detailData["BXLUMIERROR"].data<coral::Blob>();
0110       coral::Blob& bxlumiquality = detailData["BXLUMIQUALITY"].data<coral::Blob>();
0111       std::string& algoname = detailData["ALGONAME"].data<std::string>();
0112       for (unsigned int i = 1; i <= totallumils; ++i) {
0113         lumisummary_id = idg.generateNextIDForTable(LumiNames::lumisummaryTableName());
0114         lumilsnum = i;
0115         lumirunnum = runnum;
0116         lumiversion = "0";
0117         dtnorm = 1.05;
0118         lhcnorm = 1.2;
0119         instlumi = 0.9;
0120         instlumierror = 0.01;
0121         instlumiquality = 8;
0122         lumisectionquality = 16;
0123         //  unsigned int cmslsnum = 0;
0124         short iscmsalive = 0;
0125         if (i <= totalcmsls) {
0126           iscmsalive = 1;
0127           cmslsnum = i;
0128         }
0129         cmsalive = iscmsalive;
0130         startorbit = 2837495;
0131         numorbit = 34566;
0132         beamenergy = 362;
0133         beamstatus = "stable";
0134         //fetch a new id value
0135         //insert the new row
0136         summaryInserter->processNextIteration();
0137         summaryInserter->flush();
0138         d2lumisummary_id = i;
0139         for (unsigned int j = 0; j < N_LUMIALGO; ++j) {
0140           lumidetail_id = idg.generateNextIDForTable(LumiNames::lumidetailTableName());
0141           if (j == 0)
0142             algoname = std::string("ET");
0143           if (j == 1)
0144             algoname = std::string("OCC1");
0145           if (j == 2)
0146             algoname = std::string("OCC2");
0147           float lumivalue[N_BX];
0148           std::memset((void*)&lumivalue, 0, sizeof(float) * N_BX);
0149           float lumierror[N_BX];
0150           std::memset((void*)&lumierror, 0, sizeof(float) * N_BX);
0151           short lumiquality[N_BX];
0152           std::memset((void*)&lumiquality, 0, sizeof(short) * N_BX);
0153           bxlumivalue.resize(sizeof(float) * N_BX);
0154           bxlumierror.resize(sizeof(float) * N_BX);
0155           bxlumiquality.resize(sizeof(short) * N_BX);
0156           void* bxlumivalueStartAddress = bxlumivalue.startingAddress();
0157           void* bxlumierrorStartAddress = bxlumierror.startingAddress();
0158           void* bxlumiqualityStartAddress = bxlumiquality.startingAddress();
0159           for (unsigned int k = 0; k < N_BX; ++k) {
0160             lumivalue[k] = 1.5;
0161             lumierror[k] = 0.1;
0162             lumiquality[k] = 1;
0163           }
0164           std::memmove(bxlumivalueStartAddress, lumivalue, sizeof(float) * N_BX);
0165           std::memmove(bxlumierrorStartAddress, lumierror, sizeof(float) * N_BX);
0166           std::memmove(bxlumiqualityStartAddress, lumiquality, sizeof(short) * N_BX);
0167           detailInserter->processNextIteration();
0168         }
0169       }
0170       detailInserter->flush();
0171       delete summaryInserter;
0172       delete detailInserter;
0173     } catch (const coral::Exception& er) {
0174       session->transaction().rollback();
0175       delete session;
0176       delete svc;
0177       throw er;
0178     }
0179     //delete detailInserter;
0180     session->transaction().commit();
0181     delete session;
0182     delete svc;
0183     return 0;
0184   }
0185   const std::string LumiDummy2DB::dataType() const { return "LUMI"; }
0186   const std::string LumiDummy2DB::sourceType() const { return "DUMMY"; }
0187   LumiDummy2DB::~LumiDummy2DB() {}
0188 }  // namespace lumi
0189 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
0190 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory, lumi::LumiDummy2DB, "LumiDummy2DB");
0191 #endif