CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LumiProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: LumiProducer
4 // Class: LumiProducer
5 //
16 //
17 // Original Author: Valerie Halyo
18 // David Dagenhart
19 //
20 // Created: Tue Jun 12 00:47:28 CEST 2007
21 // $Id: LumiProducer.cc,v 1.18 2011/01/17 11:01:50 xiezhen Exp $
22 
34 
35 #include "CoralBase/Exception.h"
36 #include "CoralBase/AttributeList.h"
37 #include "CoralBase/Attribute.h"
38 #include "CoralBase/AttributeSpecification.h"
39 #include "CoralBase/Exception.h"
40 #include "CoralBase/Blob.h"
41 #include "RelationalAccess/ISessionProxy.h"
42 #include "RelationalAccess/ITransaction.h"
43 #include "RelationalAccess/AccessMode.h"
44 #include "RelationalAccess/ITypeConverter.h"
45 #include "RelationalAccess/IQuery.h"
46 #include "RelationalAccess/ICursor.h"
47 #include "RelationalAccess/ISchema.h"
48 #include "RelationalAccess/ITable.h"
49 
54 #include <sstream>
55 #include <string>
56 #include <memory>
57 #include <algorithm>
58 #include <vector>
59 #include <cstring>
60 
61 #include <xercesc/dom/DOM.hpp>
62 #include <xercesc/parsers/XercesDOMParser.hpp>
63 #include <xercesc/util/PlatformUtils.hpp>
64 #include <xercesc/util/XMLString.hpp>
65 
66 #include "boost/filesystem/path.hpp"
67 #include "boost/filesystem/operations.hpp"
68 namespace edm {
69  class EventSetup;
70 }
71 
72 //
73 // class declaration
74 //
75 class LumiProducer : public edm::EDProducer {
76 
77 public:
78 
79  struct HLTData{
80  unsigned int pathnum;
81  unsigned int prescale;
82  unsigned int l1passcount;
83  unsigned int acceptcount;
84  };
85  struct L1Data{
86  unsigned int bitnum;
87  unsigned int prescale;
88  unsigned int ratecount;
89  };
90  struct PerRunData{
91  std::map< unsigned int,std::string > TRGBitNames;
92  std::map< unsigned int,std::string > HLTPathNames;
93  };
94  struct PerLSData{
95  float lumivalue;
96  float lumierror;
97  short lumiquality;
98  unsigned long long deadcount;
99  unsigned int numorbit;
100  unsigned int startorbit;
101  std::vector< HLTData > hltdata;
102  std::vector< L1Data > l1data;
103  std::vector< std::pair<std::string, std::vector<float> > > bunchlumivalue;
104  std::vector< std::pair<std::string, std::vector<float> > > bunchlumierror;
105  std::vector< std::pair<std::string, std::vector<short> > > bunchlumiquality;
106  std::vector<float> beam1intensity;
107  std::vector<float> beam2intensity;
108  };
109 
110  explicit LumiProducer(const edm::ParameterSet&);
111 
112  ~LumiProducer();
113 
114 private:
115 
116  virtual void produce(edm::Event&, const edm::EventSetup&);
117 
118  virtual void beginRun(edm::Run&, edm::EventSetup const &);
119 
120  virtual void beginLuminosityBlock(edm::LuminosityBlock & iLBlock,
121  edm::EventSetup const& iSetup);
122  virtual void endLuminosityBlock(edm::LuminosityBlock& lumiBlock,
123  edm::EventSetup const& c);
124  //void fillDefaultLumi(edm::LuminosityBlock & iLBlock);
125  bool fillLumi(edm::LuminosityBlock & iLBlock);
126  void fillRunCache(unsigned int runnumber);
127  void fillLSCache(unsigned int luminum);
128  void writeProductsForEntry(edm::LuminosityBlock & iLBlock,unsigned int runnumber,unsigned int luminum);
129  const std::string servletTranslation(const std::string& servlet) const;
130  std::string x2s(const XMLCh* input)const;
131  XMLCh* s2x(const std::string& input)const;
132  std::string toParentString(const xercesc::DOMNode &nodeToConvert)const;
133 
134  std::string m_connectStr;
135  std::string m_lumiversion;
136  std::string m_siteconfpath;
137  unsigned int m_cachedrun;
139  std::map< unsigned int,PerLSData > m_lscache;
141  unsigned int m_cachesize;
142 };
143 
144 //
145 // constructors and destructor
146 //
147 
148 std::string
149 LumiProducer::x2s(const XMLCh *toTranscode)const{
150  std::string tmp(xercesc::XMLString::transcode(toTranscode));
151  return tmp;
152 }
153 
154 XMLCh*
155 LumiProducer::s2x( const std::string& temp )const{
156  XMLCh* buff = xercesc::XMLString::transcode(temp.c_str());
157  return buff;
158 }
159 
160 std::string
161 LumiProducer::toParentString(const xercesc::DOMNode &nodeToConvert)const{
162  std::ostringstream oss;
163  xercesc::DOMNodeList *childList = nodeToConvert.getChildNodes();
164 
165  unsigned int numNodes = childList->getLength ();
166  for (unsigned int i = 0; i < numNodes; ++i){
167  xercesc::DOMNode *childNode = childList->item(i);
168  if (childNode->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)
169  continue;
170  xercesc::DOMElement *child = static_cast < xercesc::DOMElement *> (childNode);
171  xercesc::DOMNamedNodeMap *attributes = child->getAttributes();
172  unsigned int numAttributes = attributes->getLength ();
173  for (unsigned int j = 0; j < numAttributes; ++j){
174  xercesc::DOMNode *attributeNode = attributes->item(j);
175  if (attributeNode->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
176  continue;
177  xercesc::DOMAttr *attribute = static_cast <xercesc::DOMAttr *> (attributeNode);
178 
179  oss << "(" << x2s(child->getTagName()) <<
180  x2s(attribute->getName()) << "=" <<
181  x2s(attribute->getValue()) << ")";
182  }
183  }
184  return oss.str();
185 }
186 
187 const std::string
188 LumiProducer::servletTranslation(const std::string& servlet) const{
189  std::string frontierConnect;
190  std::string realconnect;
191  xercesc::XMLPlatformUtils::Initialize();
192  std::auto_ptr< xercesc::XercesDOMParser > parser(new xercesc::XercesDOMParser);
193  try{
194  parser->setValidationScheme(xercesc::XercesDOMParser::Val_Auto);
195  parser->setDoNamespaces(false);
196  parser->parse(m_siteconfpath.c_str());
197  xercesc::DOMDocument* doc=parser->getDocument();
198  if(!doc){
199  return "";
200  }
201 
202  xercesc::DOMNodeList *frontierConnectList=doc->getElementsByTagName(s2x("frontier-connect"));
203  if (frontierConnectList->getLength()>0){
204  xercesc::DOMElement *frontierConnectElement=static_cast < xercesc::DOMElement *> (frontierConnectList->item (0));
205  frontierConnect = toParentString(*frontierConnectElement);
206  }
207  // Replace the last component of every "serverurl=" piece (up to the
208  // next close-paren) with the servlet
209  std::string::size_type nextparen = 0;
210  std::string::size_type serverurl, lastslash;
211  std::string complexstr = "";
212  while ((serverurl=frontierConnect.find("(serverurl=", nextparen)) != std::string::npos){
213  realconnect.append(frontierConnect, nextparen, serverurl - nextparen);
214  nextparen=frontierConnect.find(')', serverurl);
215  lastslash=frontierConnect.rfind('/', nextparen);
216  realconnect.append(frontierConnect,serverurl,lastslash-serverurl+1);
217  realconnect.append(servlet);
218  }
219  realconnect.append(frontierConnect, nextparen,frontierConnect.length()-nextparen);
220  }catch(xercesc::DOMException &e){
221  }
222  return realconnect;
223 }
224 
225 LumiProducer::
226 LumiProducer::LumiProducer(const edm::ParameterSet& iConfig):m_cachedrun(0),m_isNullRun(false),m_cachesize(0)
227 {
228  // register your products
229  produces<LumiSummary, edm::InLumi>();
230  produces<LumiDetails, edm::InLumi>();
231  // set up cache
232  std::string connectStr=iConfig.getParameter<std::string>("connect");
233  m_cachesize=iConfig.getUntrackedParameter<unsigned int>("ncacheEntries",5);
234  m_lumiversion=iConfig.getUntrackedParameter<std::string>("lumiversion");
235  const std::string fproto("frontier://");
236  //test if need frontier servlet site-local translation
237  if(connectStr.substr(0,fproto.length())==fproto){
238  std::string::size_type startservlet=fproto.length();
239  std::string::size_type endservlet=connectStr.find("(",startservlet);
240  if(endservlet==std::string::npos){
241  endservlet=connectStr.rfind('/',connectStr.length());
242  }
243  std::string servlet=connectStr.substr(startservlet,endservlet-startservlet);
244  if( (servlet !="")&& (servlet.find_first_of(":/)[]")==std::string::npos)){
245  if(servlet=="cms_conditions_data") servlet="";
246 
247  std::string siteconfpath=iConfig.getUntrackedParameter<std::string>("siteconfpath","");
248  if(siteconfpath.length()==0){
249  std::string url=(boost::filesystem::path("SITECONF")/boost::filesystem::path("local")/boost::filesystem::path("JobConfig")/boost::filesystem::path("site-local-config.xml")).string();
250  char * tmp = getenv ("CMS_PATH");
251  if(tmp){
253  }
254  }else{
255  if(!boost::filesystem::exists(boost::filesystem::path(siteconfpath))){
256  throw cms::Exception("Non existing path ")<<siteconfpath;
257  }
258  m_siteconfpath = (boost::filesystem::path(siteconfpath)/boost::filesystem::path("site-local-config.xml")).string();
259  }
260  //std::cout<<"servlet : "<<servlet<<std::endl;
261  m_connectStr=fproto+servletTranslation(servlet)+connectStr.substr(endservlet);
262  }else{
263  m_connectStr=connectStr;
264  }
265  }else{
266  m_connectStr=connectStr;
267  }
268  //std::cout<<"connect string "<< m_connectStr<<std::endl;
269 }
270 
272 }
273 //
274 // member functions
275 //
277 }
279  unsigned int runnumber=run.run();
281  fillRunCache(runnumber);
282 }
284 }
286  unsigned int runnumber=iLBlock.run();
287  unsigned int luminum=iLBlock.luminosityBlock();
288  //if is null run, fill empty values and return
289  if(m_isNullRun){
290  std::auto_ptr<LumiSummary> pOut1;
291  std::auto_ptr<LumiDetails> pOut2;
292  LumiSummary* pIn1=new LumiSummary;
293  LumiDetails* pIn2=new LumiDetails;
294  pOut1.reset(pIn1);
295  iLBlock.put(pOut1);
296  pOut2.reset(pIn2);
297  iLBlock.put(pOut2);
298  return;
299  }
300  if(m_lscache.find(luminum)==m_lscache.end()){
301  //if runnumber is cached but LS is not, this is the first LS, fill LS cache to full capacity
302  fillLSCache(luminum);
303  }
304  //here the presence of ls is guaranteed
305  writeProductsForEntry(iLBlock,runnumber,luminum);
306 }
307 void
309  //queries once per run
311  if( !mydbservice.isAvailable() ){
312  throw cms::Exception("Non existing service lumi::service::DBService");
313  }
314  //std::cout<<"in fillRunCache "<<runnumber<<std::endl;
315  coral::ISessionProxy* session=mydbservice->connectReadOnly(m_connectStr);
316  try{
317  session->transaction().start(true);
318  coral::ISchema& schema=session->nominalSchema();
319  //
320  //select bitnum,bitname from trg where runnum=:runnum and cmslsnum=:1 order by bitnum;
321  //
322  //std::cout<<"got schema handle "<<std::endl;
324  coral::AttributeList trgBindVariables;
325  trgBindVariables.extend("runnum",typeid(unsigned int));
326  trgBindVariables.extend("cmslsnum",typeid(unsigned int));
327  trgBindVariables["runnum"].data<unsigned int>()=runnumber;
328  trgBindVariables["cmslsnum"].data<unsigned int>()=1;
329  coral::AttributeList trgOutput;
330  trgOutput.extend("bitnum",typeid(unsigned int));
331  trgOutput.extend("bitname",typeid(std::string));
332  coral::IQuery* trgQuery=schema.newQuery();
333  trgQuery->addToTableList(lumi::LumiNames::trgTableName());
334  trgQuery->addToOutputList("BITNUM");
335  trgQuery->addToOutputList("BITNAME");
336  trgQuery->setCondition("RUNNUM=:runnum AND CMSLSNUM=:cmslsnum",trgBindVariables);
337  trgQuery->defineOutput(trgOutput);
338  coral::ICursor& trgcursor=trgQuery->execute();
339  unsigned int rowcounter=0;
340  while( trgcursor.next() ){
341  const coral::AttributeList& row=trgcursor.currentRow();
342  m_runcache.TRGBitNames.insert(std::make_pair(row["bitnum"].data<unsigned int>(),row["bitname"].data<std::string>()));
343  ++rowcounter;
344  }
345  delete trgQuery;
346  if (rowcounter==0){
347  m_isNullRun=true;
348  session->transaction().commit();
349  mydbservice->disconnect(session);
350  return;
351  }
352  //
353  //select pathname from from hlt where runnum=:runnum and cmslsnum=:1 order by pathname;
354  //
355  coral::AttributeList hltBindVariables;
356  hltBindVariables.extend("runnum",typeid(unsigned int));
357  hltBindVariables.extend("cmslsnum",typeid(unsigned int));
358  hltBindVariables["runnum"].data<unsigned int>()=runnumber;
359  hltBindVariables["cmslsnum"].data<unsigned int>()=1;
360  coral::AttributeList hltOutput;
361  hltOutput.extend("pathname",typeid(std::string));
362  coral::IQuery* hltQuery=schema.newQuery();
363  hltQuery->addToTableList(lumi::LumiNames::hltTableName());
364  hltQuery->addToOutputList("PATHNAME");
365  hltQuery->setCondition("RUNNUM=:runnum AND CMSLSNUM=:cmslsnum",hltBindVariables);
366  hltQuery->addToOrderList("PATHNAME");
367  hltQuery->defineOutput(hltOutput);
368  coral::ICursor& hltcursor=hltQuery->execute();
369  rowcounter=0;
370  unsigned int pathcount=0;
371  while( hltcursor.next() ){
372  const coral::AttributeList& row=hltcursor.currentRow();
373  m_runcache.HLTPathNames.insert(std::make_pair(pathcount,row["pathname"].data<std::string>()));
374  ++pathcount;
375  ++rowcounter;
376  }
377  delete hltQuery;
378  if (rowcounter==0){
379  m_isNullRun=true;
380  session->transaction().commit();
381  mydbservice->disconnect(session);
382  return;
383  }
384  session->transaction().commit();
385  }catch(const coral::Exception& er){
386  session->transaction().rollback();
387  mydbservice->disconnect(session);
388  throw cms::Exception("DatabaseError ")<<er.what();
389  }
390  mydbservice->disconnect(session);
391 }
392 void
393 LumiProducer::fillLSCache(unsigned int luminum){
394  //std::cout<<"in fillLSCache "<<luminum<<std::endl;
395  //initialize cache
396  if(m_isNullRun) return;
397  m_lscache.clear();
398  for(unsigned int n=luminum;n<luminum+m_cachesize;++n){
399  PerLSData l;
400  l.hltdata.reserve(250);
401  l.l1data.reserve(192);
402  l.bunchlumivalue.reserve(5);
403  l.bunchlumierror.reserve(5);
404  l.bunchlumiquality.reserve(5);
405  l.beam1intensity.resize(3564,0.0);
406  l.beam2intensity.resize(3564,0.0);
407  m_lscache.insert(std::make_pair(n,l));
408  }
409  //queries once per cache refill
410  //
411  //select cmslsnum,instlumi,instlumierror,lumiquality,startorbit,numorbit,bxindex,beam1intensity,beam2intensity from lumisummary where cmslsnum>=:lsmin and cmslsnum<:lsmax and runnum=:runnumber ;
412  //
414  if( !mydbservice.isAvailable() ){
415  throw cms::Exception("Non existing service lumi::service::DBService");
416  }
417  coral::ISessionProxy* session=mydbservice->connectReadOnly(m_connectStr);
418  try{
419  session->transaction().start(true);
420  coral::ISchema& schema=session->nominalSchema();
421  coral::AttributeList lumisummaryBindVariables;
422  lumisummaryBindVariables.extend("runnum",typeid(unsigned int));
423  lumisummaryBindVariables.extend("lsmin",typeid(unsigned int));
424  lumisummaryBindVariables.extend("lsmax",typeid(unsigned int));
425 
426  lumisummaryBindVariables["runnum"].data<unsigned int>()=m_cachedrun;
427  lumisummaryBindVariables["lsmin"].data<unsigned int>()=luminum;
428  lumisummaryBindVariables["lsmax"].data<unsigned int>()=luminum+m_cachesize;
429  coral::AttributeList lumisummaryOutput;
430  lumisummaryOutput.extend("cmslsnum",typeid(unsigned int));
431  lumisummaryOutput.extend("instlumi",typeid(float));
432  lumisummaryOutput.extend("instlumierror",typeid(float));
433  lumisummaryOutput.extend("instlumiquality",typeid(short));
434  lumisummaryOutput.extend("startorbit",typeid(unsigned int));
435  lumisummaryOutput.extend("numorbit",typeid(unsigned int));
436  lumisummaryOutput.extend("bxindexBlob",typeid(coral::Blob));
437  lumisummaryOutput.extend("beam1intensityBlob",typeid(coral::Blob));
438  lumisummaryOutput.extend("beam2intensityBlob",typeid(coral::Blob));
439 
440  coral::IQuery* lumisummaryQuery=schema.newQuery();
441  lumisummaryQuery->addToTableList(lumi::LumiNames::lumisummaryTableName());
442  lumisummaryQuery->addToOutputList("CMSLSNUM","cmslsnum");
443  lumisummaryQuery->addToOutputList("INSTLUMI","instlumi");
444  lumisummaryQuery->addToOutputList("INSTLUMIERROR","instlumierror");
445  lumisummaryQuery->addToOutputList("INSTLUMIQUALITY","instlumiquality");
446  lumisummaryQuery->addToOutputList("STARTORBIT","startorbit");
447  lumisummaryQuery->addToOutputList("NUMORBIT","numorbit");
448  lumisummaryQuery->addToOutputList("CMSBXINDEXBLOB","bxindexBlob");
449  lumisummaryQuery->addToOutputList("BEAMINTENSITYBLOB_1","beam1intensityBlob");
450  lumisummaryQuery->addToOutputList("BEAMINTENSITYBLOB_2","beam2intensityBlob");
451  lumisummaryQuery->setCondition("RUNNUM=:runnum AND CMSLSNUM>=:lsmin AND CMSLSNUM<:lsmax",lumisummaryBindVariables);
452  lumisummaryQuery->defineOutput(lumisummaryOutput);
453  coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
454  unsigned int rowcounter=0;
455  while( lumisummarycursor.next() ){
456  const coral::AttributeList& row=lumisummarycursor.currentRow();
457  unsigned int cmslsnum=row["cmslsnum"].data<unsigned int>();
458  //std::cout<<"cmslsnum "<<cmslsnum<<std::endl;
459  PerLSData& lsdata=m_lscache[cmslsnum];
460  lsdata.lumivalue=row["instlumi"].data<float>();
461  lsdata.lumierror=row["instlumierror"].data<float>();
462  lsdata.lumiquality=row["instlumiquality"].data<short>();
463  lsdata.startorbit=row["startorbit"].data<unsigned int>();
464  lsdata.numorbit=row["numorbit"].data<unsigned int>();
465 
466  if(!row["bxindexBlob"].isNull()){
467  const coral::Blob& bxindexBlob=row["bxindexBlob"].data<coral::Blob>();
468  const void* bxindex_StartAddress=bxindexBlob.startingAddress();
469  short* bxindex=(short*)::malloc(bxindexBlob.size());
470  const coral::Blob& beam1intensityBlob=row["beam1intensityBlob"].data<coral::Blob>();
471  const void* beam1intensityBlob_StartAddress=beam1intensityBlob.startingAddress();
472  float* beam1intensity=(float*)::malloc(beam1intensityBlob.size());
473  const coral::Blob& beam2intensityBlob=row["beam2intensityBlob"].data<coral::Blob>();
474  const void* beam2intensityBlob_StartAddress=beam2intensityBlob.startingAddress();
475  float* beam2intensity=(float*)::malloc(beam2intensityBlob.size());
476  std::memmove(bxindex,bxindex_StartAddress,bxindexBlob.size());
477  std::memmove(beam1intensity,beam1intensityBlob_StartAddress,beam1intensityBlob.size());
478  std::memmove(beam2intensity,beam2intensityBlob_StartAddress,beam2intensityBlob.size());
479  //std::cout<<"lsnum,pos,bxidx,beam1intensity,beam2intensity "<<std::endl;
480  for(unsigned int i=0;i<bxindexBlob.size()/sizeof(short);++i){
481  unsigned int idx=bxindex[i];
482  lsdata.beam1intensity.at(idx)=beam1intensity[i];
483  lsdata.beam2intensity.at(idx)=beam2intensity[i];
484  //std::cout<<cmslsnum<<","<<i<<","<<idx<<","<<beam1intensity[i]<<","<<beam2intensity[i]<<std::endl;
485  }
486  ::free(bxindex);
487  ::free(beam1intensity);
488  ::free(beam2intensity);
489  }
490  ++rowcounter;
491  }
492  if (rowcounter==0){
493  m_isNullRun=true;
494  return;
495  }
496  delete lumisummaryQuery;
497 
498  //
499  //select lumisummary.cmslsnum,lumidetail.bxlumivalue,lumidetail.bxlumierror,lumidetail.bxlumiquality,lumidetail.algoname from lumisummary,lumidetail where lumisummary.lumisummary_id=lumidetail.lumisummary_id and lumisummary.runnum=:runnum and lumisummary.cmslsnum>=:luminum and lumisummary.cmslsnum<:luminum+cachesize order by lumidetail.algoname,lumisummary.cmslsnum
500  //
501  coral::AttributeList lumidetailBindVariables;
502  lumidetailBindVariables.extend("runnum",typeid(unsigned int));
503  lumidetailBindVariables.extend("lsmin",typeid(unsigned int));
504  lumidetailBindVariables.extend("lsmax",typeid(unsigned int));
505 
506  lumidetailBindVariables["runnum"].data<unsigned int>()=m_cachedrun;
507  lumidetailBindVariables["lsmin"].data<unsigned int>()=luminum;
508  lumidetailBindVariables["lsmax"].data<unsigned int>()=luminum+m_cachesize;
509  coral::AttributeList lumidetailOutput;
510 
511  lumidetailOutput.extend("cmslsnum",typeid(unsigned int));
512  lumidetailOutput.extend("bxlumivalue",typeid(coral::Blob));
513  lumidetailOutput.extend("bxlumierror",typeid(coral::Blob));
514  lumidetailOutput.extend("bxlumiquality",typeid(coral::Blob));
515  lumidetailOutput.extend("algoname",typeid(std::string));
516 
517  coral::IQuery* lumidetailQuery=schema.newQuery();
518  lumidetailQuery->addToTableList(lumi::LumiNames::lumisummaryTableName());
519  lumidetailQuery->addToTableList(lumi::LumiNames::lumidetailTableName());
520  lumidetailQuery->addToOutputList(lumi::LumiNames::lumisummaryTableName()+".CMSLSNUM","cmslsnum");
521  lumidetailQuery->addToOutputList(lumi::LumiNames::lumidetailTableName()+".BXLUMIVALUE","bxlumivalue");
522  lumidetailQuery->addToOutputList(lumi::LumiNames::lumidetailTableName()+".BXLUMIERROR","bxlumierror");
523  lumidetailQuery->addToOutputList(lumi::LumiNames::lumidetailTableName()+".BXLUMIQUALITY","instlumiquality");
524  lumidetailQuery->addToOutputList(lumi::LumiNames::lumidetailTableName()+".ALGONAME","algoname");
525  lumidetailQuery->setCondition(lumi::LumiNames::lumisummaryTableName()+".LUMISUMMARY_ID="+lumi::LumiNames::lumidetailTableName()+".LUMISUMMARY_ID AND "+lumi::LumiNames::lumisummaryTableName()+".RUNNUM=:runnum AND "+lumi::LumiNames::lumisummaryTableName()+".CMSLSNUM>=:lsmin AND "+lumi::LumiNames::lumisummaryTableName()+".CMSLSNUM<:lsmax",lumidetailBindVariables);
526  lumidetailQuery->addToOrderList(lumi::LumiNames::lumidetailTableName()+".ALGONAME");
527  lumidetailQuery->addToOrderList(lumi::LumiNames::lumisummaryTableName()+".CMSLSNUM");
528  lumidetailQuery->defineOutput(lumidetailOutput);
529  coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
530  while( lumidetailcursor.next() ){
531  const coral::AttributeList& row=lumidetailcursor.currentRow();
532  unsigned int cmslsnum=row["cmslsnum"].data<unsigned int>();
533  std::string algoname=row["algoname"].data<std::string>();
534  //std::cout<<"cmslsnum "<<cmslsnum<<" "<<algoname<<std::endl;
535  PerLSData& lsdata=m_lscache[cmslsnum];
536  if( !row["bxlumivalue"].isNull() && !row["bxlumierror"].isNull() && !row["bxlumiquality"].isNull() ){
537  const coral::Blob& bxlumivalueBlob=row["bxlumivalue"].data<coral::Blob>();
538  const coral::Blob& bxlumierrorBlob=row["bxlumierror"].data<coral::Blob>();
539  const coral::Blob& bxlumiqualityBlob=row["bxlumiquality"].data<coral::Blob>();
540  const void* bxlumivalueBlob_StartAddress=bxlumivalueBlob.startingAddress();
541  const void* bxlumierrorBlob_StartAddress=bxlumierrorBlob.startingAddress();
542  const void* bxlumiqualityBlob_StartAddress=bxlumiqualityBlob.startingAddress();
543  float* bxlumivalue=(float*)::malloc(bxlumivalueBlob.size());
544  float* bxlumierror=(float*)::malloc(bxlumierrorBlob.size());
545  short* bxlumiquality=(short*)::malloc(bxlumiqualityBlob.size());
546  std::memmove(bxlumivalue,bxlumivalueBlob_StartAddress,bxlumivalueBlob.size());
547  std::memmove(bxlumierror,bxlumierrorBlob_StartAddress,bxlumierrorBlob.size());
548  std::memmove(bxlumiquality,bxlumiqualityBlob_StartAddress,bxlumiqualityBlob.size());
549  std::vector<float> bxlumivalueVec(bxlumivalue,bxlumivalue+bxlumivalueBlob.size()/sizeof(float));
550  ::free(bxlumivalue);
551  lsdata.bunchlumivalue.push_back(std::make_pair(algoname,bxlumivalueVec));
552  std::vector<float> bxlumierrorVec(bxlumierror,bxlumierror+bxlumierrorBlob.size()/sizeof(float));
553  ::free(bxlumierror);
554  lsdata.bunchlumierror.push_back(std::make_pair(algoname,bxlumierrorVec));
555  std::vector<short> bxlumiqualityVec(bxlumiquality,bxlumiquality+bxlumiqualityBlob.size()/sizeof(short));
556  lsdata.bunchlumiquality.push_back(std::make_pair(algoname,bxlumiqualityVec));
557  ::free(bxlumiquality);
558  }
559  }
560  delete lumidetailQuery;
561  //
562  //select cmslsnum,bitnum,deadtime,prescale,trgcount from trg where cmslsnum >=:luminum and cmslsnum<:luminum+cachesize AND runnum=:runnum order by cmslsnum,bitnum
563  //
564  coral::AttributeList trgBindVariables;
565  trgBindVariables.extend("runnum",typeid(unsigned int));
566  trgBindVariables.extend("lsmin",typeid(unsigned int));
567  trgBindVariables.extend("lsmax",typeid(unsigned int));
568  trgBindVariables["runnum"].data<unsigned int>()=m_cachedrun;
569  trgBindVariables["lsmin"].data<unsigned int>()=luminum;
570  trgBindVariables["lsmax"].data<unsigned int>()=luminum+m_cachesize;
571  coral::AttributeList trgOutput;
572  trgOutput.extend("cmslsnum",typeid(unsigned int));
573  trgOutput.extend("bitnum",typeid(unsigned int));
574  trgOutput.extend("deadtime",typeid(unsigned long long));
575  trgOutput.extend("prescale",typeid(unsigned int));
576  trgOutput.extend("trgcount",typeid(unsigned int));
577 
578  coral::IQuery* trgQuery=schema.newQuery();
579  trgQuery->addToTableList(lumi::LumiNames::trgTableName());
580  trgQuery->addToOutputList("CMSLSNUM","cmslsnum");
581  trgQuery->addToOutputList("BITNUM","bitnum");
582  trgQuery->addToOutputList("DEADTIME","deadtime");
583  trgQuery->addToOutputList("PRESCALE","prescale");
584  trgQuery->addToOutputList("TRGCOUNT","trgcount");
585  trgQuery->setCondition("CMSLSNUM>=:lsmin AND CMSLSNUM<:lsmax AND RUNNUM=:runnum ",trgBindVariables);
586  trgQuery->addToOrderList("CMSLSNUM");
587  trgQuery->addToOrderList("BITNUM");
588  trgQuery->defineOutput(trgOutput);
589  coral::ICursor& trgcursor=trgQuery->execute();
590  while( trgcursor.next() ){
591  const coral::AttributeList& row=trgcursor.currentRow();
592  unsigned int cmslsnum=row["cmslsnum"].data<unsigned int>();
593  PerLSData& lsdata=m_lscache[cmslsnum];
594  lsdata.deadcount=row["deadtime"].data<unsigned long long>();
595  L1Data l1tmp;
596  l1tmp.bitnum=row["bitnum"].data<unsigned int>();
597  l1tmp.prescale=row["prescale"].data<unsigned int>();
598  l1tmp.ratecount=row["trgcount"].data<unsigned int>();
599  lsdata.l1data.push_back(l1tmp);
600  }
601  delete trgQuery;
602  //
603  //select cmslsnum,inputcount,acceptcount,prescale from hlt where cmslsnum >=:luminum and cmslsnum<=:luminum+cachesize and runnum=:runnumber order by cmslsum,pathname
604  //
605  coral::AttributeList hltBindVariables;
606  hltBindVariables.extend("runnum",typeid(unsigned int));
607  hltBindVariables.extend("lsmin",typeid(unsigned int));
608  hltBindVariables.extend("lsmax",typeid(unsigned int));
609  hltBindVariables["runnum"].data<unsigned int>()=m_cachedrun;
610  hltBindVariables["lsmin"].data<unsigned int>()=luminum;
611  hltBindVariables["lsmax"].data<unsigned int>()=luminum+m_cachesize;
612  coral::AttributeList hltOutput;
613  hltOutput.extend("cmslsnum",typeid(unsigned int));
614  hltOutput.extend("inputcount",typeid(unsigned int));
615  hltOutput.extend("acceptcount",typeid(unsigned int));
616  hltOutput.extend("prescale",typeid(unsigned int));
617  coral::IQuery* hltQuery=schema.newQuery();
618  hltQuery->addToTableList(lumi::LumiNames::hltTableName());
619  hltQuery->addToOutputList("CMSLSNUM","cmslsnum");
620  hltQuery->addToOutputList("INPUTCOUNT","inputcount");
621  hltQuery->addToOutputList("ACCEPTCOUNT","acceptcount");
622  hltQuery->addToOutputList("PRESCALE","prescale");
623  hltQuery->setCondition("CMSLSNUM>=:lsmin AND CMSLSNUM<:lsmax AND RUNNUM=:runnum",hltBindVariables);
624  hltQuery->addToOrderList("CMSLSNUM");
625  hltQuery->addToOrderList("PATHNAME");
626  hltQuery->defineOutput(hltOutput);
627  coral::ICursor& hltcursor=hltQuery->execute();
628  unsigned int npaths=m_runcache.HLTPathNames.size();
629  unsigned int pathcount=0;
630  while( hltcursor.next() ){
631  const coral::AttributeList& row=hltcursor.currentRow();
632  unsigned int cmslsnum=row["cmslsnum"].data<unsigned int>();
633  PerLSData& lsdata=m_lscache[cmslsnum];
634  HLTData hlttmp;
635  hlttmp.pathnum=pathcount;
636  hlttmp.prescale=row["prescale"].data<unsigned int>();
637  hlttmp.l1passcount=row["inputcount"].data<unsigned int>();
638  hlttmp.acceptcount=row["acceptcount"].data<unsigned int>();
639  lsdata.hltdata.push_back(hlttmp);
640  if(pathcount!=npaths){
641  ++pathcount;
642  }else{
643  pathcount=0;
644  }
645  }
646  delete hltQuery;
647  session->transaction().commit();
648  }catch(const coral::Exception& er){
649  session->transaction().rollback();
650  mydbservice->disconnect(session);
651  throw cms::Exception("DatabaseError ")<<er.what();
652  }
653  mydbservice->disconnect(session);
654 }
655 void
656 LumiProducer::writeProductsForEntry(edm::LuminosityBlock & iLBlock,unsigned int runnumber,unsigned int luminum){
657  std::auto_ptr<LumiSummary> pOut1;
658  std::auto_ptr<LumiDetails> pOut2;
659  LumiSummary* pIn1=new LumiSummary;
660  LumiDetails* pIn2=new LumiDetails;
661  if(m_isNullRun){
662  pIn1->setLumiVersion("-1");
663  pIn2->setLumiVersion("-1");
664  pOut1.reset(pIn1);
665  iLBlock.put(pOut1);
666  pOut2.reset(pIn2);
667  iLBlock.put(pOut2);
668  return;
669  }
670  PerLSData& lsdata=m_lscache[luminum];
671  pIn1->setLumiData(lsdata.lumivalue,lsdata.lumierror,lsdata.lumiquality);
672  pIn1->setDeadtime(lsdata.deadcount);
673  pIn1->setlsnumber(luminum);
674  pIn1->setOrbitData(lsdata.startorbit,lsdata.numorbit);
675  std::vector<LumiSummary::L1> l1temp;
676  for(std::vector< L1Data >::iterator it=lsdata.l1data.begin();it!=lsdata.l1data.end();++it){
677  LumiSummary::L1 trgtmp;
678  trgtmp.prescale=it->prescale;
679  trgtmp.ratecount=it->ratecount;
680  trgtmp.triggername=m_runcache.TRGBitNames[it->bitnum];
681  l1temp.push_back(trgtmp);
682  }
683  std::vector<LumiSummary::HLT> hlttemp;
684  for(std::vector< HLTData >::iterator it=lsdata.hltdata.begin();it!=lsdata.hltdata.end();++it){
685  LumiSummary::HLT hlttmp;
686  hlttmp.prescale=it->prescale;
687  hlttmp.ratecount=it->acceptcount;
688  hlttmp.inputcount=it->l1passcount;
689  hlttmp.pathname=m_runcache.HLTPathNames[it->pathnum];
690  hlttemp.push_back(hlttmp);
691  }
692  pIn1->swapL1Data(l1temp);
693  pIn1->swapHLTData(hlttemp);
694  pIn1->setLumiVersion(m_lumiversion);
696  for(unsigned int i=0;i<lsdata.bunchlumivalue.size();++i){
697  std::string algoname=lsdata.bunchlumivalue[i].first;
698  if(algoname=="OCC1"){
699  pIn2->fill(LumiDetails::kOCC1,lsdata.bunchlumivalue[i].second,lsdata.bunchlumierror[i].second,lsdata.bunchlumiquality[i].second);
700  }else if(algoname=="OCC2"){
701  pIn2->fill(LumiDetails::kOCC2,lsdata.bunchlumivalue[i].second,lsdata.bunchlumierror[i].second,lsdata.bunchlumiquality[i].second);
702  }else if(algoname=="ET"){
703  pIn2->fill(LumiDetails::kET,lsdata.bunchlumivalue[i].second,lsdata.bunchlumierror[i].second,lsdata.bunchlumiquality[i].second);
704  }else if(algoname=="PLT"){
705  pIn2->fill(LumiDetails::kPLT,lsdata.bunchlumivalue[i].second,lsdata.bunchlumierror[i].second,lsdata.bunchlumiquality[i].second);
706  }
707  }
708  pIn2->setLumiVersion(m_lumiversion);
709  pOut1.reset(pIn1);
710  iLBlock.put(pOut1);
711  pOut2.reset(pIn2);
712  iLBlock.put(pOut2);
713 }
void writeProductsForEntry(edm::LuminosityBlock &iLBlock, unsigned int runnumber, unsigned int luminum)
unsigned int pathnum
Definition: LumiProducer.cc:80
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< std::pair< std::string, std::vector< float > > > bunchlumivalue
static const std::string trgTableName()
Definition: LumiNames.cc:14
RunNumber_t run() const
Definition: RunBase.h:44
std::string triggername
Definition: LumiSummary.h:26
unsigned int prescale
Definition: LumiProducer.cc:81
std::vector< float > beam1intensity
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
LumiProducer(const edm::ParameterSet &)
void swapHLTData(std::vector< HLT > &hltdata)
Definition: LumiSummary.cc:162
std::string x2s(const XMLCh *input) const
XMLCh * s2x(const std::string &input) const
unsigned int ratecount
Definition: LumiProducer.cc:88
std::map< unsigned int, std::string > HLTPathNames
Definition: LumiProducer.cc:92
uint16_t size_type
int path() const
Definition: HLTadd.h:3
LuminosityBlockNumber_t luminosityBlock() const
void setLumiVersion(std::string const &lumiVersion)
Definition: LumiDetails.cc:36
unsigned int ratecount
Definition: LumiSummary.h:34
void setlsnumber(unsigned int lsnumber)
Definition: LumiSummary.cc:149
std::string m_connectStr
std::map< unsigned int, std::string > TRGBitNames
Definition: LumiProducer.cc:91
unsigned int inputcount
Definition: LumiSummary.h:35
unsigned int prescale
Definition: LumiSummary.h:28
void setOrbitData(unsigned int startorbit, unsigned int numorbit)
Definition: LumiSummary.cc:153
std::string toParentString(const xercesc::DOMNode &nodeToConvert) const
std::vector< std::pair< std::string, std::vector< float > > > bunchlumierror
void fill(AlgoType algo, std::vector< float > const &values, std::vector< float > const &errors, std::vector< short > const &qualities)
Definition: LumiDetails.cc:51
unsigned int prescale
Definition: LumiProducer.cc:87
void fillLSCache(unsigned int luminum)
unsigned int l1passcount
Definition: LumiProducer.cc:82
std::vector< HLTData > hltdata
list attributes
Definition: asciidump.py:415
bool isAvailable() const
Definition: Service.h:47
static const std::string lumisummaryTableName()
Definition: LumiNames.cc:8
int j
Definition: DBlmapReader.cc:9
std::string pathname
Definition: LumiSummary.h:33
unsigned int bitnum
Definition: LumiProducer.cc:86
RunNumber_t run() const
virtual void beginRun(edm::Run &, edm::EventSetup const &)
unsigned int m_cachedrun
tuple doc
Definition: asciidump.py:381
void disconnect(coral::ISessionProxy *session)
Definition: DBService.cc:46
tuple input
Definition: collect_tpl.py:10
void setLumiVersion(const std::string &lumiversion)
Definition: LumiSummary.cc:135
virtual void endLuminosityBlock(edm::LuminosityBlock &lumiBlock, edm::EventSetup const &c)
void setLumiData(float instlumi, float instlumierr, short lumiquality)
Definition: LumiSummary.cc:139
std::string m_siteconfpath
static const std::string hltTableName()
Definition: LumiNames.cc:17
std::map< unsigned int, PerLSData > m_lscache
std::vector< L1Data > l1data
static const std::string lumidetailTableName()
Definition: LumiNames.cc:11
unsigned int ratecount
Definition: LumiSummary.h:27
void swapL1Data(std::vector< L1 > &l1data)
Definition: LumiSummary.cc:158
unsigned int m_cachesize
unsigned long long deadcount
Definition: LumiProducer.cc:98
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
virtual void beginLuminosityBlock(edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup)
void fillBeamIntensities(std::vector< float > const &beam1Intensities, std::vector< float > const &beam2Intensities)
Definition: LumiDetails.cc:74
std::string m_lumiversion
bool fillLumi(edm::LuminosityBlock &iLBlock)
unsigned int acceptcount
Definition: LumiProducer.cc:83
coral::ISessionProxy * connectReadOnly(const std::string &connectstring)
Definition: DBService.cc:42
const std::string servletTranslation(const std::string &servlet) const
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< std::pair< std::string, std::vector< short > > > bunchlumiquality
void setDeadtime(unsigned long long deadcount)
Definition: LumiSummary.cc:145
Definition: Run.h:31
std::vector< float > beam2intensity
PerRunData m_runcache
unsigned int prescale
Definition: LumiSummary.h:36
tuple lsdata
Definition: lumiCalc.py:197
void put(std::auto_ptr< PROD > product)
Put a new product.
void fillRunCache(unsigned int runnumber)