CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Static Public Attributes
lumi::HLT2DB Class Reference
Inheritance diagram for lumi::HLT2DB:
lumi::DataPipe

Classes

struct  hltinfo
 

Public Member Functions

virtual const std::string dataType () const
 
 HLT2DB (const std::string &dest)
 
virtual void retrieveData (unsigned int)
 
virtual const std::string sourceType () const
 
virtual ~HLT2DB ()
 
- Public Member Functions inherited from lumi::DataPipe
 DataPipe (const std::string &)
 
std::string getAuthPath () const
 
std::string getMode () const
 
std::string getSource () const
 
void setAuthPath (const std::string &authpath)
 
void setMode (const std::string &mode)
 
void setSource (const std::string &source)
 
virtual ~DataPipe ()
 

Static Public Attributes

static const unsigned int COMMITLSINTERVAL =200
 

Additional Inherited Members

- Protected Attributes inherited from lumi::DataPipe
std::string m_authpath
 
std::string m_dest
 
std::string m_mode
 
std::string m_source
 

Detailed Description

Definition at line 32 of file HLT2DB.cc.

Constructor & Destructor Documentation

lumi::HLT2DB::HLT2DB ( const std::string &  dest)
explicit

Definition at line 54 of file HLT2DB.cc.

54 :DataPipe(dest){}
DataPipe(const std::string &)
Definition: DataPipe.cc:2
lumi::HLT2DB::~HLT2DB ( )
virtual

Definition at line 262 of file HLT2DB.cc.

262 {}

Member Function Documentation

const std::string lumi::HLT2DB::dataType ( ) const
virtual

Implements lumi::DataPipe.

Definition at line 256 of file HLT2DB.cc.

256  {
257  return "HLT";
258  }
void lumi::HLT2DB::retrieveData ( unsigned int  runnumber)
virtual

retrieve hlt info with 2 queries select count(distinct PATHNAME ) as npath from HLT_SUPERVISOR_LUMISECTIONS_V2 where runnr=110823 and lsnumber=1; select l.PATHNAME,l.LSNUMBER,l.L1PASS,l.PACCEPT,m.PSVALUE from hlt_supervisor_lumisections_v2 l, hlt_supervisor_scalar_map m where l.RUNNR=m.RUNNR and l.PSINDEX=m.PSINDEX and l.PATHNAME=m.PATHNAME and l.RUNNR=83037 order by l.LSNUMBER;

Implements lumi::DataPipe.

Definition at line 55 of file HLT2DB.cc.

References lumi::HLT2DB::hltinfo::cmsluminr, COMMITLSINTERVAL, gather_cfg::cout, python.DBCopy::destsession, edm::hlt::Exception, lumi::idDealer::generateNextIDForTable(), lumi::HLT2DB::hltinfo::hltaccept, lumi::HLT2DB::hltinfo::hltconfigid, lumi::HLT2DB::hltinfo::hltinput, lumi::LumiNames::hltTableName(), lumi::DataPipe::m_authpath, lumi::DataPipe::m_dest, lumi::DataPipe::m_source, lumi::HLT2DB::hltinfo::pathname, lumi::HLT2DB::hltinfo::prescale, q2, cond::runnumber, lumi::DBConfig::setAuthentication(), and python.CommonUtils::svc.

55  {
56 
57  std::string hltschema("CMS_RUNINFO");
58  std::string tabname("HLT_SUPERVISOR_LUMISECTIONS_V2");
59  std::string maptabname("HLT_SUPERVISOR_SCALAR_MAP");
60 
61  coral::ConnectionService* svc=new coral::ConnectionService;
62  lumi::DBConfig dbconf(*svc);
63  if(!m_authpath.empty()){
64  dbconf.setAuthentication(m_authpath);
65  }
71  //std::cout<<"m_source "<<m_source<<std::endl;
72  coral::ISessionProxy* srcsession=svc->connect(m_source, coral::ReadOnly);
73  coral::ITypeConverter& tpc=srcsession->typeConverter();
74  tpc.setCppTypeForSqlType("unsigned int","NUMBER(11)");
75  srcsession->transaction().start(true);
76  coral::ISchema& hltSchemaHandle=srcsession->schema(hltschema);
77  if( !hltSchemaHandle.existsTable(tabname) || !hltSchemaHandle.existsTable(maptabname) ){
78  throw lumi::Exception("missing hlt tables" ,"retrieveData","HLT2DB");
79  }
80  std::vector< std::vector<HLT2DB::hltinfo> > hltresult;
81  coral::AttributeList bindVariableList;
82  bindVariableList.extend("runnumber",typeid(unsigned int));
83  bindVariableList.extend("lsnumber",typeid(unsigned int));
84  bindVariableList["runnumber"].data<unsigned int>()=runnumber;
85  bindVariableList["lsnumber"].data<unsigned int>()=1;
86  //coral::IQuery* q1=srcsession->nominalSchema().tableHandle(tabname).newQuery();
87  //coral::AttributeList nls;
88  //nls.extend("npath",typeid(unsigned int));
89  //q1->addToOutputList("count(distinct PATHNAME)","npath");
90  //q1->setCondition("RUNNR =:runnumber AND LSNUMBER =:lsnumber",bindVariableList);
91  //q1->defineOutput(nls);
92  //coral::ICursor& c=q1->execute();
93  //if( !c.next() ){
94  //c.close();
95  // delete q1;
96  //throw lumi::Exception("request run doen't exist","retrieveData","HLT2DB");
97  //}else{
98  //npath=c.currentRow()["npath"].data<unsigned int>();
99  // c.close();
100  //delete q1;
101  //if(npath==0){
102  //std::cout<<"request run is empty, do nothing"<<std::endl;
103  //return;
104  //}
105  //}
106  //std::cout<<"npath "<<npath<<std::endl;
107  unsigned int npath=0;
108  coral::IQuery* q2=srcsession->nominalSchema().newQuery();
109  coral::AttributeList q2bindVariableList;
110  q2bindVariableList.extend("runnumber",typeid(unsigned int));
111  q2bindVariableList["runnumber"].data<unsigned int>()=runnumber;
112  q2->addToTableList(tabname,"l");
113  q2->addToTableList(maptabname,"m");
114  q2->addToOutputList("l.LSNUMBER","lsnumber");
115  q2->addToOutputList("l.PATHNAME","pathname");
116  q2->addToOutputList("l.L1PASS","hltinput");
117  q2->addToOutputList("l.PACCEPT","hltratecounter");
118  q2->addToOutputList("m.PSVALUE","prescale");
119  q2->addToOutputList("m.HLTKEY","hltconfigid");
120  q2->setCondition("l.RUNNR=m.RUNNR and l.PSINDEX=m.PSINDEX and l.PATHNAME=m.PATHNAME and l.RUNNR =:runnumber",q2bindVariableList);
121  q2->addToOrderList("lsnumber");
122  q2->setRowCacheSize(10692);
123  coral::ICursor& cursor2=q2->execute();
124  //unsigned int currentPath=0;
125  unsigned int lastLumiSection=1;
126  unsigned int currentLumiSection=0;
127  // unsigned int counter=0;
128  std::vector<hltinfo> allpaths;
129  allpaths.reserve(200);
130  while( cursor2.next() ){
131  hltinfo pathcontent;
132  const coral::AttributeList& row=cursor2.currentRow();
133  currentLumiSection=row["lsnumber"].data<unsigned int>();
134  pathcontent.cmsluminr=currentLumiSection;
135  pathcontent.hltinput=row["hltinput"].data<unsigned int>();
136  pathcontent.hltaccept=row["hltratecounter"].data<unsigned int>();
137  pathcontent.pathname=row["pathname"].data<std::string>();
138  pathcontent.prescale=row["prescale"].data<unsigned int>();
139  pathcontent.hltconfigid=row["hltconfigid"].data<unsigned int>();
140  if(currentLumiSection != lastLumiSection){
141  hltresult.push_back(allpaths);
142  //npath=allpaths.size();
143  allpaths.clear();
144  }
145  lastLumiSection=currentLumiSection;
146  allpaths.push_back(pathcontent);
147  npath=allpaths.size();
148  }
149  hltresult.push_back(allpaths);
150  cursor2.close();
151  delete q2;
152  srcsession->transaction().commit();
153  delete srcsession;
154 
155  //
156  // Write into DB
157  //
158  unsigned int totalcmsls=hltresult.size();
159  std::cout<<"inserting totalhltls "<<totalcmsls<<std::endl;
160  std::map< unsigned long long, std::vector<unsigned long long> > idallocationtable;
161  coral::ISessionProxy* destsession=svc->connect(m_dest,coral::Update);
162  coral::ITypeConverter& lumitpc=destsession->typeConverter();
163  lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(7)");
164  lumitpc.setCppTypeForSqlType("unsigned int","NUMBER(10)");
165  lumitpc.setCppTypeForSqlType("unsigned long long","NUMBER(20)");
166 
167  std::vector< std::vector<HLT2DB::hltinfo> >::const_iterator hltIt;
168  std::vector< std::vector<HLT2DB::hltinfo> >::const_iterator hltBeg=hltresult.begin();
169  std::vector< std::vector<HLT2DB::hltinfo> >::const_iterator hltEnd=hltresult.end();
170 
171  try{
172  std::cout<<"\t allocating total ids "<<totalcmsls*npath<<std::endl;
173  destsession->transaction().start(false);
174  lumi::idDealer idg(destsession->nominalSchema());
175  unsigned long long hltID = idg.generateNextIDForTable(LumiNames::hltTableName(),totalcmsls*npath)-totalcmsls*npath;
176  destsession->transaction().commit();
177  unsigned int hltlscount=0;
178  for(hltIt=hltBeg;hltIt!=hltEnd;++hltIt,++hltlscount){
179  std::vector<unsigned long long> pathvec;
180  pathvec.reserve(200);
181  std::vector<HLT2DB::hltinfo>::const_iterator pathIt;
182  std::vector<HLT2DB::hltinfo>::const_iterator pathBeg=hltIt->begin();
183  std::vector<HLT2DB::hltinfo>::const_iterator pathEnd=hltIt->end();
184  for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt,++hltID){
185  pathvec.push_back(hltID);
186  }
187  idallocationtable.insert(std::make_pair(hltlscount,pathvec));
188  }
189  std::cout<<"\t all ids allocated"<<std::endl;
190 
191  coral::AttributeList hltData;
192  hltData.extend("HLT_ID",typeid(unsigned long long));
193  hltData.extend("RUNNUM",typeid(unsigned int));
194  hltData.extend("CMSLSNUM",typeid(unsigned int));
195  hltData.extend("PATHNAME",typeid(std::string));
196  hltData.extend("INPUTCOUNT",typeid(unsigned int));
197  hltData.extend("ACCEPTCOUNT",typeid(unsigned int));
198  hltData.extend("PRESCALE",typeid(unsigned int));
199 
200  //loop over lumi LS
201  unsigned long long& hlt_id=hltData["HLT_ID"].data<unsigned long long>();
202  unsigned int& hltrunnum=hltData["RUNNUM"].data<unsigned int>();
203  unsigned int& cmslsnum=hltData["CMSLSNUM"].data<unsigned int>();
204  std::string& pathname=hltData["PATHNAME"].data<std::string>();
205  unsigned int& inputcount=hltData["INPUTCOUNT"].data<unsigned int>();
206  unsigned int& acceptcount=hltData["ACCEPTCOUNT"].data<unsigned int>();
207  unsigned int& prescale=hltData["PRESCALE"].data<unsigned int>();
208  hltlscount=0;
209  coral::IBulkOperation* hltInserter=0;
210  unsigned int comittedls=0;
211  for(hltIt=hltBeg;hltIt!=hltEnd;++hltIt,++hltlscount){
212  std::vector<HLT2DB::hltinfo>::const_iterator pathIt;
213  std::vector<HLT2DB::hltinfo>::const_iterator pathBeg=hltIt->begin();
214  std::vector<HLT2DB::hltinfo>::const_iterator pathEnd=hltIt->end();
215  if(!destsession->transaction().isActive()){
216  destsession->transaction().start(false);
217  coral::ITable& hlttable=destsession->nominalSchema().tableHandle(LumiNames::hltTableName());
218  hltInserter=hlttable.dataEditor().bulkInsert(hltData,200);
219  }
220  unsigned int hltpathcount=0;
221  for(pathIt=pathBeg;pathIt!=pathEnd;++pathIt,++hltpathcount){
222  hlt_id = idallocationtable[hltlscount].at(hltpathcount);
223  hltrunnum = runnumber;
224  cmslsnum = pathIt->cmsluminr;
225  pathname = pathIt->pathname;
226  inputcount = pathIt->hltinput;
227  acceptcount = pathIt->hltaccept;
228  prescale = pathIt->prescale;
229  hltInserter->processNextIteration();
230  }
231  hltInserter->flush();
232  ++comittedls;
233  if(comittedls==HLT2DB::COMMITLSINTERVAL){
234  std::cout<<"\t committing in LS chunck "<<comittedls<<std::endl;
235  delete hltInserter; hltInserter=0;
236  destsession->transaction().commit();
237  comittedls=0;
238  std::cout<<"\t committed "<<std::endl;
239  }else if( hltlscount==(totalcmsls-1) ){
240  std::cout<<"\t committing at the end"<<std::endl;
241  delete hltInserter; hltInserter=0;
242  destsession->transaction().commit();
243  std::cout<<"\t done"<<std::endl;
244  }
245  }
246  }catch( const coral::Exception& er){
247  std::cout<<"database problem "<<er.what()<<std::endl;
248  destsession->transaction().rollback();
249  delete destsession;
250  delete svc;
251  throw er;
252  }
253  delete destsession;
254  delete svc;
255  }
double q2[4]
Definition: TauolaWrapper.h:88
std::string m_dest
Definition: DataPipe.h:23
std::string m_source
Definition: DataPipe.h:24
static const std::string hltTableName()
Definition: LumiNames.cc:17
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:31
std::string m_authpath
Definition: DataPipe.h:25
tuple cout
Definition: gather_cfg.py:41
static const unsigned int COMMITLSINTERVAL
Definition: HLT2DB.cc:35
tuple destsession
Definition: DBCopy.py:270
const std::string lumi::HLT2DB::sourceType ( ) const
virtual

Implements lumi::DataPipe.

Definition at line 259 of file HLT2DB.cc.

259  {
260  return "DB";
261  }

Member Data Documentation

const unsigned int lumi::HLT2DB::COMMITLSINTERVAL =200
static

Definition at line 35 of file HLT2DB.cc.

Referenced by retrieveData().