CMS 3D CMS Logo

TRGDummy2DB.cc
Go to the documentation of this file.
1 #ifndef RecoLuminosity_LumiProducer_TRGDummy2DB_h
2 #define RecoLuminosity_LumiProducer_TRGDummy2DB_h
3 #include "RelationalAccess/ConnectionService.h"
4 #include "RelationalAccess/ISessionProxy.h"
5 #include "RelationalAccess/ITransaction.h"
6 #include "RelationalAccess/ISchema.h"
7 #include "RelationalAccess/ITable.h"
8 #include "RelationalAccess/ITableDataEditor.h"
9 #include "RelationalAccess/IBulkOperation.h"
10 #include "RelationalAccess/ITypeConverter.h"
11 #include "CoralBase/AttributeList.h"
12 #include "CoralBase/AttributeSpecification.h"
13 #include "CoralBase/Attribute.h"
14 #include "CoralBase/Exception.h"
21 
22 #include <iostream>
23 #include <cstdio>
24 namespace lumi{
25  class TRGDummy2DB : public DataPipe{
26  public:
28  virtual unsigned long long retrieveData( unsigned int ) override;
29  virtual const std::string dataType() const override;
30  virtual const std::string sourceType() const override;
31  virtual ~TRGDummy2DB();
32  };//cl TRGDummy2DB
33  //
34  //implementation
35  //
37  unsigned long long TRGDummy2DB::retrieveData( unsigned int runnum){
38  //
39  //generate dummy data of trg for the given run and write data to LumiDB
40  //
41  coral::ConnectionService* svc=new coral::ConnectionService;
42  lumi::DBConfig dbconf(*svc);
43 
44  if(!m_authpath.empty()){
46  }
47  coral::ISessionProxy* session=svc->connect(m_dest,coral::Update);
48  coral::ITypeConverter& tpc=session->typeConverter();
49  tpc.setCppTypeForSqlType("unsigned int","NUMBER(7)");
50  tpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
51  tpc.setCppTypeForSqlType("unsigned long long","NUMBER(20)");
52  try{
53  unsigned int totalcmsls=32;
54  session->transaction().start(false);
55  coral::ISchema& schema=session->nominalSchema();
56  lumi::idDealer idg(schema);
57  coral::ITable& trgtable=schema.tableHandle(LumiNames::trgTableName());
58  coral::AttributeList trgData;
59  trgData.extend("TRG_ID",typeid(unsigned long long));
60  trgData.extend("RUNNUM",typeid(unsigned int));
61  trgData.extend("CMSLSNUM",typeid(unsigned int));
62  trgData.extend("BITNUM",typeid(unsigned int));
63  trgData.extend("BITNAME",typeid(std::string));
64  trgData.extend("TRGCOUNT",typeid(unsigned int));
65  trgData.extend("DEADTIME",typeid(unsigned long long));
66  trgData.extend("PRESCALE",typeid(unsigned int));
67  coral::IBulkOperation* trgInserter=trgtable.dataEditor().bulkInsert(trgData,totalcmsls*(lumi::N_TRGALGOBIT+lumi::N_TRGTECHBIT));
68  //loop over lumi LS
69  unsigned long long& trg_id=trgData["TRG_ID"].data<unsigned long long>();
70  unsigned int& trgrunnum=trgData["RUNNUM"].data<unsigned int>();
71  unsigned int& cmslsnum=trgData["CMSLSNUM"].data<unsigned int>();
72  unsigned int& bitnum=trgData["BITNUM"].data<unsigned int>();
73  std::string& bitname=trgData["BITNAME"].data<std::string>();
74  unsigned int& count=trgData["TRGCOUNT"].data<unsigned int>();
75  unsigned long long& deadtime=trgData["DEADTIME"].data<unsigned long long>();
76  unsigned int& prescale=trgData["PRESCALE"].data<unsigned int>();
77 
78  for(unsigned int i=1;i<=totalcmsls;++i){
79  for(unsigned int j=0;j<(lumi::N_TRGALGOBIT+lumi::N_TRGTECHBIT);++j){ //total n of trg bits
81  trgrunnum = runnum;
82  cmslsnum = i;
83  bitnum=j;
84  char c[10];
85  if(j>(lumi::N_TRGALGOBIT-1)){
86  ::sprintf(c,"%d",j-(lumi::N_TRGALGOBIT-1));
87  bitname=std::string(c);
88  }else{
89  ::sprintf(c,"%d",j);
90  bitname=std::string("FakeTRGBIT_")+std::string(c);
91  }
92  count=12345;
93  deadtime=6785;
94  prescale=1;
95  trgInserter->processNextIteration();
96  }
97  }
98  trgInserter->flush();
99  delete trgInserter;
100  }catch( const coral::Exception& er){
101  std::cout<<"database problem "<<er.what()<<std::endl;
102  session->transaction().rollback();
103  delete session;
104  delete svc;
105  throw er;
106  }
107  //delete detailInserter;
108  session->transaction().commit();
109  delete session;
110  delete svc;
111  return 0;
112  }
114  return "TRG";
115  }
117  return "DUMMY";
118  }
120 }//ns lumi
123 #endif
static const std::string trgTableName()
Definition: LumiNames.cc:35
TRGDummy2DB(const std::string &dest)
Definition: TRGDummy2DB.cc:36
virtual unsigned long long retrieveData(unsigned int) override
Definition: TRGDummy2DB.cc:37
std::string m_dest
Definition: DataPipe.h:27
const unsigned int N_TRGTECHBIT
Definition: ConstantDef.h:7
virtual const std::string dataType() const override
Definition: TRGDummy2DB.cc:113
void setAuthentication(const std::string &authPath)
Definition: DBConfig.cc:15
virtual const std::string sourceType() const override
Definition: TRGDummy2DB.cc:116
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:31
std::string m_authpath
Definition: DataPipe.h:29
#define DEFINE_EDM_PLUGIN(factory, type, name)
const unsigned int N_TRGALGOBIT
Definition: ConstantDef.h:6
virtual ~TRGDummy2DB()
Definition: TRGDummy2DB.cc:119