CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoLuminosity/LumiProducer/plugins/LumiDummy2DB.cc

Go to the documentation of this file.
00001 #ifndef RecoLuminosity_LumiProducer_LumiDummy2DB_H 
00002 #define RecoLuminosity_LumiProducer_LumiDummy2DB_H 
00003 #include "RelationalAccess/ConnectionService.h"
00004 #include "RelationalAccess/ISessionProxy.h"
00005 #include "RelationalAccess/ITransaction.h"
00006 #include "RelationalAccess/ISchema.h"
00007 #include "RelationalAccess/ITable.h"
00008 #include "RelationalAccess/ITableDataEditor.h"
00009 #include "RelationalAccess/IBulkOperation.h"
00010 #include "RelationalAccess/ITypeConverter.h"
00011 #include "CoralBase/AttributeList.h"
00012 #include "CoralBase/AttributeSpecification.h"
00013 #include "CoralBase/AttributeList.h"
00014 #include "CoralBase/Attribute.h"
00015 #include "CoralBase/Blob.h"
00016 #include "CoralBase/Exception.h"
00017 
00018 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
00019 #include "RecoLuminosity/LumiProducer/interface/ConstantDef.h"
00020 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
00021 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
00022 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
00023 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
00024 //#include <iostream>
00025 #include <cstring>
00026 namespace lumi{
00027   class LumiDummy2DB : public DataPipe{
00028   public:
00029     LumiDummy2DB(const std::string& dest);
00030     virtual void retrieveData( unsigned int );
00031     virtual const std::string dataType() const;
00032     virtual const std::string sourceType() const;
00033     virtual ~LumiDummy2DB();
00034   };//cl LumiDummy2DB
00035   //
00036   //implementation
00037   //
00038   LumiDummy2DB::LumiDummy2DB( const std::string& dest):DataPipe(dest){
00039     //check the format of dest
00040   }
00041   void LumiDummy2DB::retrieveData( unsigned int runnum){
00042     //
00043     //generate dummy data for lumi summary and detail for the given run and write data to LumiDB
00044     //
00045     coral::ConnectionService* svc=new coral::ConnectionService;
00046     lumi::DBConfig dbconf(*svc);
00047     if(!m_authpath.empty()){
00048       dbconf.setAuthentication(m_authpath);
00049     }
00050     coral::ISessionProxy* session=svc->connect(m_dest,coral::Update);
00051     coral::ITypeConverter& tpc=session->typeConverter();
00052     tpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
00053     try{
00054       unsigned int totallumils=35;
00055       unsigned int totalcmsls=32;
00056       session->transaction().start(false);
00057       coral::ISchema& schema=session->nominalSchema();
00058       lumi::idDealer idg(schema);
00059       coral::ITable& summarytable=schema.tableHandle(LumiNames::lumisummaryTableName());
00060       coral::ITable& detailtable=schema.tableHandle(LumiNames::lumidetailTableName());
00061       coral::AttributeList summaryData;
00062       summaryData.extend("LUMISUMMARY_ID",typeid(unsigned long long));
00063       summaryData.extend("RUNNUM",typeid(unsigned int));
00064       summaryData.extend("CMSLSNUM",typeid(unsigned int));
00065       summaryData.extend("LUMILSNUM",typeid(unsigned int));
00066       summaryData.extend("LUMIVERSION",typeid(std::string));
00067       summaryData.extend("DTNORM",typeid(float));
00068       summaryData.extend("LHCNORM",typeid(float));
00069       summaryData.extend("INSTLUMI",typeid(float));
00070       summaryData.extend("INSTLUMIERROR",typeid(float));
00071       summaryData.extend("INSTLUMIQUALITY",typeid(short));
00072       summaryData.extend("LUMISECTIONQUALITY",typeid(short));
00073       summaryData.extend("CMSALIVE",typeid(short));
00074       summaryData.extend("STARTORBIT",typeid(unsigned int));
00075       summaryData.extend("NUMORBIT",typeid(unsigned int));
00076       summaryData.extend("BEAMENERGY",typeid(float));
00077       summaryData.extend("BEAMSTATUS",typeid(std::string));
00078 
00079       coral::IBulkOperation* summaryInserter=summarytable.dataEditor().bulkInsert(summaryData,totallumils);
00080       coral::AttributeList detailData;
00081       detailData.extend("LUMIDETAIL_ID",typeid(unsigned long long));
00082       detailData.extend("LUMISUMMARY_ID",typeid(unsigned long long));
00083       detailData.extend("BXLUMIVALUE",typeid(coral::Blob));
00084       detailData.extend("BXLUMIERROR",typeid(coral::Blob));
00085       detailData.extend("BXLUMIQUALITY",typeid(coral::Blob));
00086       detailData.extend("ALGONAME",typeid(std::string));
00087       coral::IBulkOperation* detailInserter=detailtable.dataEditor().bulkInsert(detailData,totallumils*N_LUMIALGO);
00088       //loop over lumi LS
00089       unsigned long long& lumisummary_id=summaryData["LUMISUMMARY_ID"].data<unsigned long long>();
00090       unsigned int& lumirunnum = summaryData["RUNNUM"].data<unsigned int>();
00091       unsigned int& cmslsnum=summaryData["CMSLSNUM"].data<unsigned int>();
00092       unsigned int& lumilsnum=summaryData["LUMILSNUM"].data<unsigned int>();
00093       std::string& lumiversion = summaryData["LUMIVERSION"].data<std::string>();
00094       float& dtnorm = summaryData["DTNORM"].data<float>();
00095       float& lhcnorm = summaryData["LHCNORM"].data<float>();
00096       float& instlumi = summaryData["INSTLUMI"].data<float>();
00097       float& instlumierror = summaryData["INSTLUMIERROR"].data<float>();
00098       short& instlumiquality = summaryData["INSTLUMIQUALITY"].data<short>();
00099       short& lumisectionquality = summaryData["LUMISECTIONQUALITY"].data<short>();
00100       short& cmsalive = summaryData["CMSALIVE"].data<short>();
00101       unsigned int& startorbit=summaryData["STARTORBIT"].data<unsigned int>();
00102       unsigned int& numorbit= summaryData["NUMORBIT"].data<unsigned int>();
00103       float& beamenergy= summaryData["BEAMENERGY"].data<float>();
00104       std::string& beamstatus= summaryData["BEAMSTATUS"].data<std::string>();
00105 
00106       unsigned long long& lumidetail_id=detailData["LUMIDETAIL_ID"].data<unsigned long long>();
00107       unsigned long long& d2lumisummary_id=detailData["LUMISUMMARY_ID"].data<unsigned long long>();
00108       coral::Blob& bxlumivalue=detailData["BXLUMIVALUE"].data<coral::Blob>();
00109       coral::Blob& bxlumierror=detailData["BXLUMIERROR"].data<coral::Blob>();
00110       coral::Blob& bxlumiquality=detailData["BXLUMIQUALITY"].data<coral::Blob>();
00111       std::string& algoname=detailData["ALGONAME"].data<std::string>();
00112       for(unsigned int i=1;i<=totallumils;++i){
00113         lumisummary_id = idg.generateNextIDForTable(LumiNames::lumisummaryTableName());
00114         lumilsnum=i;
00115         lumirunnum = runnum;
00116         lumiversion = "0";
00117         dtnorm = 1.05;
00118         lhcnorm = 1.2;
00119         instlumi = 0.9;
00120         instlumierror = 0.01;
00121         instlumiquality = 8;
00122         lumisectionquality = 16;
00123         //      unsigned int cmslsnum = 0;
00124         short iscmsalive = 0;
00125         if(i<=totalcmsls){
00126           iscmsalive=1;
00127           cmslsnum=i;
00128         }
00129         cmsalive=iscmsalive;
00130         startorbit=2837495;
00131         numorbit=34566;
00132         beamenergy=362;
00133         beamstatus="stable";
00134         //fetch a new id value 
00135         //insert the new row
00136         summaryInserter->processNextIteration();
00137         summaryInserter->flush();
00138         d2lumisummary_id=i;
00139         for( unsigned int j=0; j<N_LUMIALGO; ++j ){
00140           lumidetail_id=idg.generateNextIDForTable(LumiNames::lumidetailTableName());
00141           if(j==0) algoname=std::string("ET");
00142           if(j==1) algoname=std::string("OCC1");
00143           if(j==2) algoname=std::string("OCC2");
00144           float lumivalue[N_BX];
00145           std::memset((void*)&lumivalue,0,sizeof(float)*N_BX);
00146           float lumierror[N_BX];
00147           std::memset((void*)&lumierror,0,sizeof(float)*N_BX );
00148           short lumiquality[N_BX];
00149           std::memset((void*)&lumiquality,0,sizeof(short)*N_BX );
00150           bxlumivalue.resize(sizeof(float)*N_BX);
00151           bxlumierror.resize(sizeof(float)*N_BX);
00152           bxlumiquality.resize(sizeof(short)*N_BX);
00153           void* bxlumivalueStartAddress=bxlumivalue.startingAddress();
00154           void* bxlumierrorStartAddress=bxlumierror.startingAddress();
00155           void* bxlumiqualityStartAddress=bxlumiquality.startingAddress();
00156           for( unsigned int k=0; k<N_BX; ++k ){     
00157             lumivalue[k]=1.5;
00158             lumierror[k]=0.1;
00159             lumiquality[k]=1;
00160           }
00161           std::memmove(bxlumivalueStartAddress,lumivalue,sizeof(float)*N_BX);
00162           std::memmove(bxlumierrorStartAddress,lumierror,sizeof(float)*N_BX);
00163           std::memmove(bxlumiqualityStartAddress,lumiquality,sizeof(short)*N_BX);
00164           detailInserter->processNextIteration();
00165         }
00166       }
00167       detailInserter->flush();
00168       delete summaryInserter;
00169       delete detailInserter;
00170     }catch( const coral::Exception& er){
00171       session->transaction().rollback();
00172       delete session;
00173       delete svc;
00174       throw er;
00175     }
00176     //delete detailInserter;
00177     session->transaction().commit();
00178     delete session;
00179     delete svc;
00180   }
00181   const std::string LumiDummy2DB::dataType() const{
00182     return "LUMI";
00183   }
00184   const std::string LumiDummy2DB::sourceType() const{
00185     return "DUMMY";
00186   }
00187   LumiDummy2DB::~LumiDummy2DB(){}
00188 }//ns lumi
00189 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
00190 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory,lumi::LumiDummy2DB,"LumiDummy2DB");
00191 #endif