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"
61 #include <xercesc/dom/DOM.hpp>
62 #include <xercesc/parsers/XercesDOMParser.hpp>
63 #include <xercesc/util/PlatformUtils.hpp>
64 #include <xercesc/util/XMLString.hpp>
66 #include "boost/filesystem/path.hpp"
67 #include "boost/filesystem/operations.hpp"
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;
150 std::string
tmp(xercesc::XMLString::transcode(toTranscode));
156 XMLCh* buff = xercesc::XMLString::transcode(temp.c_str());
162 std::ostringstream oss;
163 xercesc::DOMNodeList *childList = nodeToConvert.getChildNodes();
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)
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)
177 xercesc::DOMAttr *attribute = static_cast <xercesc::DOMAttr *> (attributeNode);
179 oss <<
"(" <<
x2s(child->getTagName()) <<
180 x2s(attribute->getName()) <<
"=" <<
181 x2s(attribute->getValue()) <<
")";
189 std::string frontierConnect;
190 std::string realconnect;
191 xercesc::XMLPlatformUtils::Initialize();
192 std::auto_ptr< xercesc::XercesDOMParser >
parser(
new xercesc::XercesDOMParser);
194 parser->setValidationScheme(xercesc::XercesDOMParser::Val_Auto);
195 parser->setDoNamespaces(
false);
197 xercesc::DOMDocument*
doc=parser->getDocument();
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));
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);
219 realconnect.append(frontierConnect, nextparen,frontierConnect.length()-nextparen);
220 }
catch(xercesc::DOMException &
e){
226 LumiProducer::LumiProducer(
const edm::ParameterSet& iConfig):m_cachedrun(0),m_isNullRun(
false),m_cachesize(0)
229 produces<LumiSummary, edm::InLumi>();
230 produces<LumiDetails, edm::InLumi>();
232 std::string connectStr=iConfig.
getParameter<std::string>(
"connect");
235 const std::string fproto(
"frontier://");
237 if(connectStr.substr(0,fproto.length())==fproto){
240 if(endservlet==std::string::npos){
241 endservlet=connectStr.rfind(
'/',connectStr.length());
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=
"";
248 if(siteconfpath.length()==0){
250 char *
tmp = getenv (
"CMS_PATH");
290 std::auto_ptr<LumiSummary> pOut1;
291 std::auto_ptr<LumiDetails> pOut2;
312 throw cms::Exception(
"Non existing service lumi::service::DBService");
317 session->transaction().start(
true);
318 coral::ISchema&
schema=session->nominalSchema();
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();
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>()));
348 session->transaction().commit();
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();
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();
370 unsigned int pathcount=0;
371 while( hltcursor.next() ){
372 const coral::AttributeList& row=hltcursor.currentRow();
380 session->transaction().commit();
384 session->transaction().commit();
386 session->transaction().rollback();
415 throw cms::Exception(
"Non existing service lumi::service::DBService");
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));
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));
440 coral::IQuery* lumisummaryQuery=schema.newQuery();
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>();
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>();
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());
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];
487 ::free(beam1intensity);
488 ::free(beam2intensity);
496 delete lumisummaryQuery;
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));
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;
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));
517 coral::IQuery* lumidetailQuery=schema.newQuery();
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>();
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));
551 lsdata.bunchlumivalue.push_back(std::make_pair(algoname,bxlumivalueVec));
552 std::vector<float> bxlumierrorVec(bxlumierror,bxlumierror+bxlumierrorBlob.size()/
sizeof(float));
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);
560 delete lumidetailQuery;
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));
578 coral::IQuery* trgQuery=schema.newQuery();
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>();
594 lsdata.deadcount=row[
"deadtime"].data<
unsigned long long>();
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);
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();
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();
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>();
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){
647 session->transaction().commit();
649 session->transaction().rollback();
657 std::auto_ptr<LumiSummary> pOut1;
658 std::auto_ptr<LumiDetails> pOut2;
675 std::vector<LumiSummary::L1> l1temp;
676 for(std::vector< L1Data >::iterator it=lsdata.
l1data.begin();it!=lsdata.
l1data.end();++it){
681 l1temp.push_back(trgtmp);
683 std::vector<LumiSummary::HLT> hlttemp;
684 for(std::vector< HLTData >::iterator it=lsdata.
hltdata.begin();it!=lsdata.
hltdata.end();++it){
690 hlttemp.push_back(hlttmp);
698 if(algoname==
"OCC1"){
700 }
else if(algoname==
"OCC2"){
702 }
else if(algoname==
"ET"){
704 }
else if(algoname==
"PLT"){
void writeProductsForEntry(edm::LuminosityBlock &iLBlock, unsigned int runnumber, unsigned int luminum)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::pair< std::string, std::vector< float > > > bunchlumivalue
static const std::string trgTableName()
std::vector< float > beam1intensity
#define DEFINE_FWK_MODULE(type)
LumiProducer(const edm::ParameterSet &)
void swapHLTData(std::vector< HLT > &hltdata)
std::string x2s(const XMLCh *input) const
XMLCh * s2x(const std::string &input) const
std::map< unsigned int, std::string > HLTPathNames
LuminosityBlockNumber_t luminosityBlock() const
void setLumiVersion(std::string const &lumiVersion)
void setlsnumber(unsigned int lsnumber)
std::map< unsigned int, std::string > TRGBitNames
void setOrbitData(unsigned int startorbit, unsigned int numorbit)
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)
void fillLSCache(unsigned int luminum)
std::vector< HLTData > hltdata
static const std::string lumisummaryTableName()
virtual void beginRun(edm::Run &, edm::EventSetup const &)
void disconnect(coral::ISessionProxy *session)
void setLumiVersion(const std::string &lumiversion)
virtual void endLuminosityBlock(edm::LuminosityBlock &lumiBlock, edm::EventSetup const &c)
void setLumiData(float instlumi, float instlumierr, short lumiquality)
std::string m_siteconfpath
static const std::string hltTableName()
std::map< unsigned int, PerLSData > m_lscache
std::vector< L1Data > l1data
static const std::string lumidetailTableName()
void swapL1Data(std::vector< L1 > &l1data)
unsigned long long deadcount
std::vector< std::vector< double > > tmp
virtual void beginLuminosityBlock(edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup)
void fillBeamIntensities(std::vector< float > const &beam1Intensities, std::vector< float > const &beam2Intensities)
std::string m_lumiversion
bool fillLumi(edm::LuminosityBlock &iLBlock)
coral::ISessionProxy * connectReadOnly(const std::string &connectstring)
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)
std::vector< float > beam2intensity
void put(std::auto_ptr< PROD > product)
Put a new product.
void fillRunCache(unsigned int runnumber)