CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCDQM_Collection.cc
Go to the documentation of this file.
1 /* =====================================================================================
2  *
3  * Filename: CSCDQM_Collection.cc
4  *
5  * Description: Histogram booking code
6  *
7  * Version: 1.0
8  * Created: 04/18/2008 03:39:49 PM
9  * Revision: none
10  * Compiler: gcc
11  *
12  * Author: Valdas Rapsevicius (VR), Valdas.Rapsevicius@cern.ch
13  * Company: CERN, CH
14  *
15  * =====================================================================================
16  */
17 
18 #include "CSCDQM_Collection.h"
20 #include <cstdio>
21 
22 namespace cscdqm {
23 
29  config = p_config;
30  }
31 
32 
38 
39  LOG_INFO << "Reading histograms from " << config->getBOOKING_XML_FILE();
40 
41  if (config->getBOOKING_XML_FILE().empty()) {
42  return;
43  }
44 
45  try {
46 
48 
49  {
50 
52 
53  parser.setValidationScheme(XercesDOMParser::Val_Always);
54  parser.setDoNamespaces(true);
55  parser.setDoSchema(true);
56  parser.setExitOnFirstFatalError(true);
57  parser.setValidationConstraintFatal(true);
59  parser.setErrorHandler(&eh);
60 
61  parser.parse(config->getBOOKING_XML_FILE().c_str());
62  DOMDocument *doc = parser.getDocument();
63  DOMNode *docNode = (DOMNode*) doc->getDocumentElement();
64 
65  DOMNodeList *itemList = docNode->getChildNodes();
66 
67  CoHisto definitions;
68  for (uint32_t i = 0; i < itemList->getLength(); i++) {
69 
70  DOMNode* node = itemList->item(i);
71  if (node->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }
72 
73  std::string nodeName = XMLString::transcode(node->getNodeName());
74 
78  if (nodeName.compare(XML_BOOK_DEFINITION) == 0) {
79 
81  getNodeProperties(node, dp);
82 
83  DOMElement* el = dynamic_cast<DOMElement*>(node);
84  std::string id(XMLString::transcode(el->getAttribute(XMLString::transcode(XML_BOOK_DEFINITION_ID))));
85  definitions.insert(make_pair(id, dp));
86 
87  } else
88 
92  if (nodeName.compare(XML_BOOK_HISTOGRAM) == 0) {
93 
95 
96  DOMElement* el = dynamic_cast<DOMElement*>(node);
97  if (el->hasAttribute(XMLString::transcode(XML_BOOK_DEFINITION_REF))) {
98  std::string id(XMLString::transcode(el->getAttribute(XMLString::transcode(XML_BOOK_DEFINITION_REF))));
99  CoHistoProps d = definitions[id];
100  for (CoHistoProps::iterator it = d.begin(); it != d.end(); it++) {
101  hp[it->first] = it->second;
102  }
103  }
104 
105  getNodeProperties(node, hp);
106 
109 
110  // Check if this histogram is an ON DEMAND histogram?
112 
113  LOG_DEBUG << "[Collection::load] loading " << prefix << "::" << name << " XML_BOOK_ONDEMAND = " << hp[XML_BOOK_ONDEMAND];
114 
115  CoHistoMap::iterator it = collection.find(prefix);
116  if (it == collection.end()) {
117  CoHisto h;
118  h[name] = hp;
119  collection[prefix] = h;
120  } else {
121  it->second.insert(make_pair(name, hp));
122  }
123 
124  }
125  }
126 
127  }
128 
130 
131  } catch (XMLException& e) {
132  char* message = XMLString::transcode(e.getMessage());
133  throw Exception(message);
134  }
135 
136  for (CoHistoMap::const_iterator i = collection.begin(); i != collection.end(); i++) {
137  LOG_INFO << i->second.size() << " " << i->first << " histograms defined";
138  }
139 
140  }
141 
150  DOMNodeList *props = node->getChildNodes();
151  for(uint32_t j = 0; j < props->getLength(); j++) {
152  DOMNode* node = props->item(j);
153  if (node->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }
154  std::string name = XMLString::transcode(node->getNodeName());
155  std::string value = XMLString::transcode(node->getTextContent());
156  DOMNamedNodeMap* attributes = node->getAttributes();
157  if (attributes) {
158  for (uint32_t i = 0; i < attributes->getLength(); i++) {
159  DOMNode* attribute = attributes->item(i);
160  std::string aname = XMLString::transcode(attribute->getNodeName());
161  std::string avalue = XMLString::transcode(attribute->getNodeValue());
162  p[name + "_" + aname] = avalue;
163  }
164  }
165  p[name] = value;
166  }
167  }
168 
177  CoHistoProps::const_iterator i = h.find(name);
178  if(i == h.end()) {
179  return false;
180  }
181  value = i->second;
182  return true;
183  }
184 
192  const bool Collection::checkHistoValue(const CoHistoProps& h, const std::string& name, int& value) {
193  CoHistoProps::const_iterator i = h.find(name);
194  if(i == h.end()) {
195  return false;
196  }
197  if(EOF == std::sscanf(i->second.c_str(), "%d", &value)) {
198  return false;
199  }
200  return true;
201  }
202 
211  const bool Collection::checkHistoValue(const CoHistoProps& h, const std::string name, double& value) {
212  CoHistoProps::const_iterator i = h.find(name);
213  if(i == h.end()) {
214  return false;
215  }
216  if(EOF == std::sscanf(i->second.c_str(), "%lf", &value)) {
217  return false;
218  }
219  return true;
220  }
221 
231  if (!checkHistoValue(h, name, value)) {
232  value = def_value;
233  }
234  return value;
235  }
236 
245  int& Collection::getHistoValue(const CoHistoProps& h, const std::string& name, int& value, const int& def_value) {
246  if (!checkHistoValue(h, name, value)) {
247  value = def_value;
248  }
249  return value;
250  }
251 
260  double& Collection::getHistoValue(const CoHistoProps& h, const std::string name, double& value, const int def_value) {
261  if (!checkHistoValue(h, name, value)) {
262  value = def_value;
263  }
264  return value;
265  }
266 
273  const int Collection::ParseAxisLabels(const std::string& s, std::map<int, std::string>& labels) {
274  std::string tmp = s;
275  std::string::size_type pos = tmp.find("|");
276  char* stopstring = NULL;
277 
278  while (pos != std::string::npos) {
279  std::string label_pair = tmp.substr(0, pos);
280  tmp.replace(0, pos + 1, "");
281  if (label_pair.find("=") != std::string::npos) {
282  int nbin = strtol(label_pair.substr(0, label_pair.find("=")).c_str(), &stopstring, 10);
283  std::string label = label_pair.substr(label_pair.find("=") + 1, label_pair.length());
284  while (label.find("\'") != std::string::npos) {
285  label.erase(label.find("\'"), 1);
286  }
287  labels[nbin] = label;
288  }
289  pos = tmp.find("|");
290  }
291  return labels.size();
292  }
293 
299  CoHistoMap::const_iterator i = collection.find("EMU");
300  if (i != collection.end()) {
301  const CoHisto hs = i->second;
302  for (CoHisto::const_iterator j = hs.begin(); j != hs.end(); j++) {
303  std::string s = "";
305  HistoId hid = 0;
306  if (HistoDef::getHistoIdByName(j->first, hid)) {
307  EMUHistoDef hdef(hid);
308  book(hdef, j->second, config->getFOLDER_EMU());
309  }
310  }
311  }
312  }
313  }
314 
320  void Collection::bookFEDHistos(const HwId fedId) const {
321  CoHistoMap::const_iterator i = collection.find("FED");
322  if (i != collection.end()) {
323  const CoHisto hs = i->second;
324  for (CoHisto::const_iterator j = hs.begin(); j != hs.end(); j++) {
325  std::string s = "";
327  HistoId hid = 0;
328  if (HistoDef::getHistoIdByName(j->first, hid)) {
329  FEDHistoDef hdef(hid, fedId);
330  book(hdef, j->second, config->getFOLDER_FED());
331  }
332  }
333  }
334  }
335  }
336 
342  void Collection::bookDDUHistos(const HwId dduId) const {
343  CoHistoMap::const_iterator i = collection.find("DDU");
344  if (i != collection.end()) {
345  const CoHisto hs = i->second;
346  for (CoHisto::const_iterator j = hs.begin(); j != hs.end(); j++) {
347  std::string s = "";
349  HistoId hid = 0;
350  if (HistoDef::getHistoIdByName(j->first, hid)) {
351  DDUHistoDef hdef(hid, dduId);
352  book(hdef, j->second, config->getFOLDER_DDU());
353  }
354  }
355  }
356  }
357  }
358 
365  void Collection::bookCSCHistos(const HwId crateId, const HwId dmbId) const {
366  CoHistoMap::const_iterator i = collection.find("CSC");
367  if (i != collection.end()) {
368  const CoHisto hs = i->second;
369  for (CoHisto::const_iterator j = hs.begin(); j != hs.end(); j++) {
370  std::string s = "";
371  HistoId hid = 0;
372  if (HistoDef::getHistoIdByName(j->first, hid)) {
374  CSCHistoDef hdef(hid, crateId, dmbId);
375  book(hdef, j->second, config->getFOLDER_CSC());
376  } else {
377  int from = 0, to = 0;
378  if (checkHistoValue(j->second, XML_BOOK_NAME_FROM, from) && checkHistoValue(j->second, XML_BOOK_NAME_TO, to)) {
379  for (int k = from; k <= to; k++) {
380  CSCHistoDef hdef(hid, crateId, dmbId, k);
381  book(hdef, j->second, config->getFOLDER_CSC());
382  }
383  }
384  }
385  }
386  }
387  }
388  }
389 
390 
391 
400  void Collection::bookCSCHistos(const HistoId hid, const HwId crateId, const HwId dmbId, const HwId addId) const {
401  CoHistoMap::const_iterator i = collection.find("CSC");
402  if (i != collection.end()) {
403  CoHisto::const_iterator j = i->second.find(h::names[hid]);
404  if (j != i->second.end()) {
405  CSCHistoDef hdef(hid, crateId, dmbId, addId);
406  book(hdef, j->second, config->getFOLDER_CSC());
407  }
408  }
409  }
410 
418  void Collection::book(const HistoDef& h, const CoHistoProps& p, const std::string& folder) const {
419 
420  MonitorObject* me = NULL;
421  std::string name = h.getName(), type, title, s;
422 
424  if (!config->needBookMO(h.getFullPath())) {
425  LOG_INFO << "MOFilter excluded " << name << " from booking";
426  config->fnPutHisto(h, me);
427  return;
428  }
429 
430  int i1, i2, i3;
431  double d1, d2, d3, d4, d5, d6;
432  bool ondemand = (getHistoValue(p, XML_BOOK_ONDEMAND, s, XML_BOOK_ONDEMAND_FALSE) == XML_BOOK_ONDEMAND_TRUE ? true : false);
433 
434  if (!checkHistoValue(p, XML_BOOK_HISTO_TYPE, type)) { throw Exception("Histogram does not have type!"); }
436 
437  if (ondemand) {
438  title = h.processTitle(title);
439  }
440 
441  if (type == "h1") {
442  me = config->fnBook(
443  HistoBookRequest(h, H1D, type, folder, title,
444  getHistoValue(p, "XBins", i1, 1),
445  getHistoValue(p, "XMin", d1, 0),
446  getHistoValue(p, "XMax", d2, 1)));
447  } else
448  if(type == "h2") {
449  me = config->fnBook(
450  HistoBookRequest(h, H2D, type, folder, title,
451  getHistoValue(p, "XBins", i1, 1),
452  getHistoValue(p, "XMin", d1, 0),
453  getHistoValue(p, "XMax", d2, 1),
454  getHistoValue(p, "YBins", i2, 1),
455  getHistoValue(p, "YMin", d3, 0),
456  getHistoValue(p, "YMax", d4, 1)));
457  } else
458  if(type == "h3") {
459  me = config->fnBook(
460  HistoBookRequest(h, H3D, type, folder, title,
461  getHistoValue(p, "XBins", i1, 1),
462  getHistoValue(p, "XMin", d1, 0),
463  getHistoValue(p, "XMax", d2, 1),
464  getHistoValue(p, "YBins", i2, 1),
465  getHistoValue(p, "YMin", d3, 0),
466  getHistoValue(p, "YMax", d4, 1),
467  getHistoValue(p, "ZBins", i3, 1),
468  getHistoValue(p, "ZMin", d5, 0),
469  getHistoValue(p, "ZMax", d6, 1)));
470  } else
471  if(type == "hp") {
472  me = config->fnBook(
473  HistoBookRequest(h, PROFILE, type, folder, title,
474  getHistoValue(p, "XBins", i1, 1),
475  getHistoValue(p, "XMin", d1, 0),
476  getHistoValue(p, "XMax", d2, 1)));
477  /*
478  HistoBookRequest(h, PROFILE, type, folder, title,
479  getHistoValue(p, "XBins", i1, 1),
480  getHistoValue(p, "XMin", d1, 0),
481  getHistoValue(p, "XMax", d2, 1),
482  getHistoValue(p, "YBins", i2, 1),
483  getHistoValue(p, "YMin", d3, 0),
484  getHistoValue(p, "YMax", d4, 1)));
485  */
486  } else
487  if(type == "hp2") {
488  me = config->fnBook(
489  HistoBookRequest(h, PROFILE2D, type, folder, title,
490  getHistoValue(p, "XBins", i1, 1),
491  getHistoValue(p, "XMin", d1, 0),
492  getHistoValue(p, "XMax", d2, 1),
493  getHistoValue(p, "YBins", i2, 1),
494  getHistoValue(p, "YMin", d3, 0),
495  getHistoValue(p, "YMax", d4, 1),
496  getHistoValue(p, "ZBins", i3, 1),
497  getHistoValue(p, "ZMin", d5, 0),
498  getHistoValue(p, "ZMax", d6, 1)));
499  } else {
500  throw Exception("Can not book histogram with type: " + type);
501  }
502 
503  if(me != NULL) {
504 
505  LockType lock(me->mutex);
506  TH1 *th = me->getTH1Lock();
507 
508  if(checkHistoValue(p, "XTitle", s)) {
509  if (ondemand) {
510  s = h.processTitle(s);
511  }
512  me->setAxisTitle(s, 1);
513  }
514 
515  if(checkHistoValue(p, "YTitle", s)) {
516  if (ondemand) {
517  s = h.processTitle(s);
518  }
519  me->setAxisTitle(s, 2);
520  }
521 
522  if(checkHistoValue(p, "ZTitle", s)) {
523  if (ondemand) {
524  s = h.processTitle(s);
525  }
526  me->setAxisTitle(s, 3);
527  }
528 
529  if(checkHistoValue(p, "SetOption", s)) th->SetOption(s.c_str());
530  if(checkHistoValue(p, "SetStats", i1)) th->SetStats(i1);
531  th->SetFillColor(getHistoValue(p, "SetFillColor", i1, DEF_HISTO_COLOR));
532  if(checkHistoValue(p, "SetXLabels", s)) {
533  std::map<int, std::string> labels;
534  ParseAxisLabels(s, labels);
535  for (std::map<int, std::string>::iterator l_itr = labels.begin(); l_itr != labels.end(); ++l_itr) {
536  th->GetXaxis()->SetBinLabel(l_itr->first, l_itr->second.c_str());
537  }
538  }
539  if(checkHistoValue(p, "SetYLabels", s)) {
540  std::map<int, std::string> labels;
541  ParseAxisLabels(s, labels);
542  for (std::map<int, std::string>::iterator l_itr = labels.begin(); l_itr != labels.end(); ++l_itr) {
543  th->GetYaxis()->SetBinLabel(l_itr->first, l_itr->second.c_str());
544  }
545  }
546  if(checkHistoValue(p, "LabelOption", s)) {
547  std::vector<std::string> v;
548  if(2 == Utility::tokenize(s, v, ",")) {
549  th->LabelsOption(v[0].c_str(), v[1].c_str());
550  }
551  }
552  if(checkHistoValue(p, "SetLabelSize", s)) {
553  std::vector<std::string> v;
554  if(2 == Utility::tokenize(s, v, ",")) {
555  th->SetLabelSize((double) atof(v[0].c_str()), v[1].c_str());
556  }
557  }
558  if(checkHistoValue(p, "SetTitleOffset", s)) {
559  std::vector<std::string> v;
560  if(2 == Utility::tokenize(s, v, ",")) {
561  th->SetTitleOffset((double) atof(v[0].c_str()), v[1].c_str());
562  }
563  }
564  if(checkHistoValue(p, "SetMinimum", d1)) th->SetMinimum(d1);
565  if(checkHistoValue(p, "SetMaximum", d1)) me->SetMaximum(d1);
566  if(checkHistoValue(p, "SetNdivisionsX", i1)) {
567  th->SetNdivisions(i1, "X");
568  th->GetXaxis()->CenterLabels(true);
569  }
570  if(checkHistoValue(p, "SetNdivisionsY", i1)) {
571  th->SetNdivisions(i1, "Y");
572  th->GetYaxis()->CenterLabels(true);
573  }
574  if(checkHistoValue(p, "SetTickLengthX", d1)) th->SetTickLength(d1, "X");
575  if(checkHistoValue(p, "SetTickLengthY", d1)) th->SetTickLength(d1, "Y");
576  if(checkHistoValue(p, "SetLabelSizeX", d1)) th->SetLabelSize(d1, "X");
577  if(checkHistoValue(p, "SetLabelSizeY", d1)) th->SetLabelSize(d1, "Y");
578  if(checkHistoValue(p, "SetLabelSizeZ", d1)) th->SetLabelSize(d1, "Z");
579  if(checkHistoValue(p, "SetErrorOption", s)) reinterpret_cast<TProfile*>(th)->SetErrorOption(s.c_str());
580 
581  lock.unlock();
582 
583  }
584 
585  LOG_DEBUG << "[Collection::book] booked " << h.getFullPath() << " (" << me << ")";
586 
588  config->fnPutHisto(h, me);
589 
590  }
591 
597  const bool Collection::isOnDemand(const HistoName& name) const {
598  CoHistoMap::const_iterator i = collection.find("CSC");
599  if (i != collection.end()) {
600  CoHisto hs = i->second;
601  CoHisto::const_iterator j = hs.find(name);
602  if (j != hs.end()) {
603  std::string s;
605  }
606  }
607  return false;
608  }
609 
615 
616  std::ostringstream buffer;
617  for(CoHistoMap::const_iterator hdmi = collection.begin(); hdmi != collection.end(); hdmi++) {
618  buffer << hdmi->first << " [" << std::endl;
619  for(CoHisto::const_iterator hdi = hdmi->second.begin(); hdi != hdmi->second.end(); hdi++) {
620  buffer << " " << hdi->first << " [" << std::endl;
621  for(CoHistoProps::const_iterator hi = hdi->second.begin(); hi != hdi->second.end(); hi++) {
622  buffer << " " << hi->first << " = " << hi->second << std::endl;
623  }
624  buffer << " ]" << std::endl;
625  }
626  buffer << " ]" << std::endl;
627  }
628  LOG_INFO << buffer.str();
629  }
630 
631 }
type
Definition: HCALResponse.h:21
static const bool getHistoIdByName(const std::string &p_name, HistoId &p_id)
Get Histogram ID by name.
int i
Definition: DBlmapReader.cc:9
static const char XML_BOOK_DEFINITION_ID[]
static const char XML_BOOK_ONDEMAND_FALSE[]
unsigned int HwId
static const char XML_BOOK_HISTO_TYPE[]
static const char XML_BOOK_NAME_FROM[]
static const HistoName names[]
virtual const std::string processTitle(const std::string &p_title) const
Process Title by Adding appropriate ID.
#define LOG_INFO
Definition: CSCDQM_Logger.h:43
void bookEMUHistos() const
Book EMU histograms.
Monitoring Object interface used to cover Root object and provide common interface to EventProcessor ...
void xercesTerminate()
Definition: Xerces.cc:22
Abstract Base Histogram Definition.
static const char XML_BOOK_NAME_TO[]
static const char XML_BOOK_ONDEMAND[]
static const char XML_BOOK_DEFINITION_REF[]
static const char XML_BOOK_HISTOGRAM[]
xercesc::DOMDocument DOMDocument
#define NULL
Definition: scimark2.h:8
const bool isOnDemand(const HistoName &name) const
Check if the histogram is on demand (by histogram name)
static bool regexMatch(const std::string &expression, const std::string &message)
Match RegExp expression string against string message and return result.
void xercesInitialize()
Definition: Xerces.cc:17
CSC Level Histogram Type.
Collection(Configuration *const p_config)
Constructor.
uint16_t size_type
tuple node
Definition: Node.py:50
CSCDQM Framework Global Configuration.
unsigned int HistoId
static const char XML_BOOK_HISTO_PREFIX[]
virtual TH1 * getTH1Lock(void)=0
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
Configuration * config
static void getNodeProperties(DOMNode *&node, CoHistoProps &hp)
Extract and write single histogram properties from XML node to map.
list attributes
Definition: asciidump.py:415
xercesc::DOMNode DOMNode
static std::string & getHistoValue(const CoHistoProps &h, const std::string &name, std::string &value, const std::string &def_value="")
Find string histogram value in map.
xercesc::DOMElement DOMElement
int j
Definition: DBlmapReader.cc:9
EMU Level Histogram Definition.
const bool needBookMO(const std::string name) const
Check if MO is not excluded by MO Filter.
void load()
Load XML file and fill definition map(s)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static const bool checkHistoValue(const CoHistoProps &h, const std::string &name, std::string &value)
Find string histogram value in map.
tuple doc
Definition: asciidump.py:381
xercesc::DOMNodeList DOMNodeList
DDU Level Histogram Definition.
boost::function< MonitorObject *(const HistoBookRequest &) > fnBook
static const char XML_BOOK_ONDEMAND_TRUE[]
int k[5][pyjets_maxn]
xercesc::XercesDOMParser XercesDOMParser
void bookFEDHistos(const HwId fedId) const
Book FED histograms.
std::map< std::string, CoHistoProps > CoHisto
auto dp
Definition: deltaR.h:24
static const int DEF_HISTO_COLOR
static const char XML_BOOK_DEFINITION[]
void bookDDUHistos(const HwId dduId) const
Book DDU histograms.
void book(const HistoDef &h, const CoHistoProps &p, const std::string &folder) const
Book histogram.
FED Level Histogram Definition.
xercesc::DOMNamedNodeMap DOMNamedNodeMap
std::string HistoName
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
boost::function< void(const HistoDef &histoT, MonitorObject *&) > fnPutHisto
const std::string getFullPath() const
Get full path of the histogram. It is being constructed by appending path and histogam name...
virtual const std::string getName() const
Get processed histogram name. It can include additional parameter in formated name. This Name is being constructed from raw name and additional parameter.
void bookCSCHistos(const HwId crateId, const HwId dmbId) const
Book Chamber Histograms.
static const TPRegexp REGEXP_ONDEMAND("^.*%d.*$")
Takes care of errors and warnings while parsing XML files file in XML format.
static const char XML_BOOK_HISTO_NAME[]
void printCollection() const
Print collection of available histograms and their parameters.
static const char XML_BOOK_HISTO_TITLE[]
virtual void SetMaximum(const double d)=0
static const int ParseAxisLabels(const std::string &s, std::map< int, std::string > &labels)
Parse Axis label string and return values in vector.
std::map< std::string, std::string > CoHistoProps
static int tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
Break string into tokens.
virtual void setAxisTitle(const std::string title, const int axisN)=0
xercesc::XMLException XMLException