CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/RecoLuminosity/LumiProducer/plugins/TRGDummy2DB.cc

Go to the documentation of this file.
00001 #ifndef RecoLuminosity_LumiProducer_TRGDummy2DB_h 
00002 #define RecoLuminosity_LumiProducer_TRGDummy2DB_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/Attribute.h"
00014 #include "CoralBase/Exception.h"
00015 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
00016 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
00017 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
00018 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
00019 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
00020 #include "RecoLuminosity/LumiProducer/interface/ConstantDef.h"
00021 
00022 #include <iostream>
00023 #include <cstdio>
00024 namespace lumi{
00025   class TRGDummy2DB : public DataPipe{
00026   public:
00027     TRGDummy2DB(const std::string& dest);
00028     virtual void retrieveData( unsigned int );
00029     virtual const std::string dataType() const;
00030     virtual const std::string sourceType() const;
00031     virtual ~TRGDummy2DB();
00032   };//cl TRGDummy2DB
00033   //
00034   //implementation
00035   //
00036   TRGDummy2DB::TRGDummy2DB(const std::string& dest):DataPipe(dest){}
00037   void TRGDummy2DB::retrieveData( unsigned int runnum){
00038     //
00039     //generate dummy data of trg for the given run and write data to LumiDB
00040     //
00041     coral::ConnectionService* svc=new coral::ConnectionService;
00042     lumi::DBConfig dbconf(*svc);
00043     
00044     if(!m_authpath.empty()){
00045       dbconf.setAuthentication(m_authpath);
00046     }
00047     coral::ISessionProxy* session=svc->connect(m_dest,coral::Update);
00048     coral::ITypeConverter& tpc=session->typeConverter();
00049     tpc.setCppTypeForSqlType("unsigned int","NUMBER(7)");
00050     tpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
00051     tpc.setCppTypeForSqlType("unsigned long long","NUMBER(20)");
00052     try{
00053       unsigned int totalcmsls=32;
00054       session->transaction().start(false);
00055       coral::ISchema& schema=session->nominalSchema();
00056       lumi::idDealer idg(schema);
00057       coral::ITable& trgtable=schema.tableHandle(LumiNames::trgTableName());
00058       coral::AttributeList trgData;
00059       trgData.extend("TRG_ID",typeid(unsigned long long));
00060       trgData.extend("RUNNUM",typeid(unsigned int));
00061       trgData.extend("CMSLSNUM",typeid(unsigned int));
00062       trgData.extend("BITNUM",typeid(unsigned int));
00063       trgData.extend("BITNAME",typeid(std::string));
00064       trgData.extend("TRGCOUNT",typeid(unsigned int));
00065       trgData.extend("DEADTIME",typeid(unsigned long long));
00066       trgData.extend("PRESCALE",typeid(unsigned int));
00067       coral::IBulkOperation* trgInserter=trgtable.dataEditor().bulkInsert(trgData,totalcmsls*(lumi::N_TRGALGOBIT+lumi::N_TRGTECHBIT));
00068       //loop over lumi LS
00069       unsigned long long& trg_id=trgData["TRG_ID"].data<unsigned long long>();
00070       unsigned int& trgrunnum=trgData["RUNNUM"].data<unsigned int>();
00071       unsigned int& cmslsnum=trgData["CMSLSNUM"].data<unsigned int>();
00072       unsigned int& bitnum=trgData["BITNUM"].data<unsigned int>();
00073       std::string& bitname=trgData["BITNAME"].data<std::string>();
00074       unsigned int& count=trgData["TRGCOUNT"].data<unsigned int>();
00075       unsigned long long& deadtime=trgData["DEADTIME"].data<unsigned long long>();
00076       unsigned int& prescale=trgData["PRESCALE"].data<unsigned int>();
00077       
00078       for(unsigned int i=1;i<=totalcmsls;++i){
00079         for(unsigned int j=0;j<(lumi::N_TRGALGOBIT+lumi::N_TRGTECHBIT);++j){ //total n of trg bits
00080           trg_id = idg.generateNextIDForTable(LumiNames::trgTableName());
00081           trgrunnum = runnum;
00082           cmslsnum = i;
00083           bitnum=j;
00084           char c[10];
00085           if(j>(lumi::N_TRGALGOBIT-1)){
00086             ::sprintf(c,"%d",j-(lumi::N_TRGALGOBIT-1));
00087             bitname=std::string(c);
00088           }else{
00089             ::sprintf(c,"%d",j);
00090             bitname=std::string("FakeTRGBIT_")+std::string(c);
00091           }
00092           count=12345;
00093           deadtime=6785;
00094           prescale=1;
00095           trgInserter->processNextIteration();
00096         }
00097       }
00098       trgInserter->flush();
00099       delete trgInserter;
00100     }catch( const coral::Exception& er){
00101       std::cout<<"database problem "<<er.what()<<std::endl;
00102       session->transaction().rollback();
00103       delete session;
00104       delete svc;
00105       throw er;
00106     }
00107     //delete detailInserter;
00108     session->transaction().commit();
00109     delete session;
00110     delete svc;
00111   }
00112   const std::string TRGDummy2DB::dataType() const{
00113     return "TRG";
00114   }
00115   const std::string TRGDummy2DB::sourceType() const{
00116     return "DUMMY";
00117   }
00118   TRGDummy2DB::~TRGDummy2DB(){}
00119 }//ns lumi
00120 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
00121 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory,lumi::TRGDummy2DB,"TRGDummy2DB");
00122 #endif