CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoLuminosity/LumiProducer/plugins/HLTDummy2DB.cc

Go to the documentation of this file.
00001 #ifndef RecoLuminosity_LumiProducer_HLTDummy2DB_h 
00002 #define RecoLuminosity_LumiProducer_HLTDummy2DB_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 "CoralBase/AttributeList.h"
00011 #include "CoralBase/AttributeSpecification.h"
00012 #include "CoralBase/Attribute.h"
00013 #include "CoralBase/Exception.h"
00014 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
00015 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
00016 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
00017 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
00018 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
00019 #include <iostream>
00020 #include <cstdio>
00021 namespace lumi{
00022   class HLTDummy2DB : public DataPipe{
00023   public:
00024     HLTDummy2DB( const std::string& dest);
00025     virtual void retrieveData( unsigned int );
00026     virtual const std::string dataType() const;
00027     virtual const std::string sourceType() const;
00028     virtual ~HLTDummy2DB();
00029   };//cl HLTDummy2DB
00030   //
00031   //implementation
00032   //
00033   HLTDummy2DB::HLTDummy2DB(const std::string& dest):DataPipe(dest){}
00034   void HLTDummy2DB::retrieveData( unsigned int runnum){
00035     //
00036     //generate dummy data of hlt for the given run and write data to LumiDB
00037     //
00038     coral::ConnectionService* svc=new coral::ConnectionService;
00039     lumi::DBConfig dbconf(*svc);
00040     if(!m_authpath.empty()){
00041       dbconf.setAuthentication(m_authpath);
00042     }
00043     coral::ISessionProxy* session=svc->connect(m_dest,coral::Update);
00044     try{
00045       unsigned int totalcmsls=32;
00046       session->transaction().start(false);
00047       coral::ISchema& schema=session->nominalSchema();
00048       lumi::idDealer idg(schema);
00049       coral::ITable& hlttable=schema.tableHandle(LumiNames::hltTableName());
00050       coral::AttributeList hltData;
00051       hltData.extend<unsigned long long>("HLT_ID");
00052       hltData.extend<unsigned int>("RUNNUM");
00053       hltData.extend<unsigned int>("CMSLSNUM");
00054       hltData.extend<std::string>("PATHNAME");
00055       hltData.extend<unsigned long long>("INPUTCOUNT");
00056       hltData.extend<unsigned long long>("ACCEPTCOUNT");
00057       hltData.extend<unsigned int>("PRESCALE");
00058       coral::IBulkOperation* hltInserter=hlttable.dataEditor().bulkInsert(hltData,totalcmsls*260);
00059       //loop over lumi LS
00060       unsigned long long& hlt_id=hltData["HLT_ID"].data<unsigned long long>();
00061       unsigned int& hltrunnum=hltData["RUNNUM"].data<unsigned int>();
00062       unsigned int& cmslsnum=hltData["CMSLSNUM"].data<unsigned int>();
00063       std::string& pathname=hltData["PATHNAME"].data<std::string>();
00064       unsigned long long& inputcount=hltData["INPUTCOUNT"].data<unsigned long long>();
00065       unsigned long long& acceptcount=hltData["ACCEPTCOUNT"].data<unsigned long long>();
00066       unsigned int& prescale=hltData["PRESCALE"].data<unsigned int>();
00067       
00068       for(unsigned int i=1;i<=totalcmsls;++i){
00069         for(unsigned int j=1;j<165;++j){
00070           hlt_id = idg.generateNextIDForTable(LumiNames::hltTableName());
00071           hltrunnum = runnum;
00072           cmslsnum = i;
00073           char c[10];
00074           ::sprintf(c,"%d",j);
00075           pathname=std::string("FakeHLTPath_")+std::string(c);
00076           inputcount=12345;
00077           acceptcount=10;
00078           prescale=1;
00079           hltInserter->processNextIteration();
00080         }
00081       }
00082       hltInserter->flush();
00083       delete hltInserter;
00084     }catch( const coral::Exception& er){
00085       std::cout<<"database problem "<<er.what()<<std::endl;
00086       session->transaction().rollback();
00087       delete session;
00088       delete svc;
00089       throw er;
00090     }
00091     //delete detailInserter;
00092     session->transaction().commit();
00093     delete session;
00094     delete svc;
00095   }
00096   const std::string HLTDummy2DB::dataType() const{
00097     return "HLT";
00098   }
00099   const std::string HLTDummy2DB::sourceType() const{
00100     return "DUMMY";
00101   }
00102   HLTDummy2DB::~HLTDummy2DB(){}
00103 }//ns lumi
00104 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
00105 DEFINE_EDM_PLUGIN(lumi::DataPipeFactory,lumi::HLTDummy2DB,"HLTDummy2DB");
00106 #endif