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 
19 #include <cstdio>
20 
21 namespace cscdqm {
22 
28  config = p_config;
29  }
30 
31 
37 
38  LOG_INFO << "Reading histograms from " << config->getBOOKING_XML_FILE();
39 
40  if (config->getBOOKING_XML_FILE().empty()) {
41  return;
42  }
43 
44  try {
45 
46  XMLPlatformUtils::Initialize();
47 
48  {
49 
51 
52  parser.setValidationScheme(XercesDOMParser::Val_Always);
53  parser.setDoNamespaces(true);
54  parser.setDoSchema(true);
55  parser.setExitOnFirstFatalError(true);
56  parser.setValidationConstraintFatal(true);
58  parser.setErrorHandler(&eh);
59 
60  parser.parse(config->getBOOKING_XML_FILE().c_str());
61  DOMDocument *doc = parser.getDocument();
62  DOMNode *docNode = (DOMNode*) doc->getDocumentElement();
63 
64  DOMNodeList *itemList = docNode->getChildNodes();
65 
66  CoHisto definitions;
67  for (uint32_t i = 0; i < itemList->getLength(); i++) {
68 
69  DOMNode* node = itemList->item(i);
70  if (node->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }
71 
72  std::string nodeName = XMLString::transcode(node->getNodeName());
73 
77  if (nodeName.compare(XML_BOOK_DEFINITION) == 0) {
78 
79  CoHistoProps dp;
80  getNodeProperties(node, dp);
81 
82  DOMElement* el = dynamic_cast<DOMElement*>(node);
83  std::string id(XMLString::transcode(el->getAttribute(XMLString::transcode(XML_BOOK_DEFINITION_ID))));
84  definitions.insert(make_pair(id, dp));
85 
86  } else
87 
91  if (nodeName.compare(XML_BOOK_HISTOGRAM) == 0) {
92 
93  CoHistoProps hp;
94 
95  DOMElement* el = dynamic_cast<DOMElement*>(node);
96  if (el->hasAttribute(XMLString::transcode(XML_BOOK_DEFINITION_REF))) {
97  std::string id(XMLString::transcode(el->getAttribute(XMLString::transcode(XML_BOOK_DEFINITION_REF))));
98  CoHistoProps d = definitions[id];
99  for (CoHistoProps::iterator it = d.begin(); it != d.end(); it++) {
100  hp[it->first] = it->second;
101  }
102  }
103 
104  getNodeProperties(node, hp);
105 
106  std::string name = hp[XML_BOOK_HISTO_NAME];
107  std::string prefix = hp[XML_BOOK_HISTO_PREFIX];
108 
109  // Check if this histogram is an ON DEMAND histogram?
111 
112  LOG_DEBUG << "[Collection::load] loading " << prefix << "::" << name << " XML_BOOK_ONDEMAND = " << hp[XML_BOOK_ONDEMAND];
113 
114  CoHistoMap::iterator it = collection.find(prefix);
115  if (it == collection.end()) {
116  CoHisto h;
117  h[name] = hp;
118  collection[prefix] = h;
119  } else {
120  it->second.insert(make_pair(name, hp));
121  }
122 
123  }
124  }
125 
126  }
127 
128  XMLPlatformUtils::Terminate();
129 
130  } catch (XMLException& e) {
131  char* message = XMLString::transcode(e.getMessage());
132  throw Exception(message);
133  }
134 
135  for (CoHistoMap::const_iterator i = collection.begin(); i != collection.end(); i++) {
136  LOG_INFO << i->second.size() << " " << i->first << " histograms defined";
137  }
138 
139  }
140 
149  DOMNodeList *props = node->getChildNodes();
150  for(uint32_t j = 0; j < props->getLength(); j++) {
151  DOMNode* node = props->item(j);
152  if (node->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }
153  std::string name = XMLString::transcode(node->getNodeName());
154  std::string value = XMLString::transcode(node->getTextContent());
155  DOMNamedNodeMap* attributes = node->getAttributes();
156  if (attributes) {
157  for (uint32_t i = 0; i < attributes->getLength(); i++) {
158  DOMNode* attribute = attributes->item(i);
159  std::string aname = XMLString::transcode(attribute->getNodeName());
160  std::string avalue = XMLString::transcode(attribute->getNodeValue());
161  p[name + "_" + aname] = avalue;
162  }
163  }
164  p[name] = value;
165  }
166  }
167 
175  const bool Collection::checkHistoValue(const CoHistoProps& h, const std::string& name, std::string& value) {
176  CoHistoProps::const_iterator i = h.find(name);
177  if(i == h.end()) {
178  return false;
179  }
180  value = i->second;
181  return true;
182  }
183 
191  const bool Collection::checkHistoValue(const CoHistoProps& h, const std::string& name, int& value) {
192  CoHistoProps::const_iterator i = h.find(name);
193  if(i == h.end()) {
194  return false;
195  }
196  if(EOF == std::sscanf(i->second.c_str(), "%d", &value)) {
197  return false;
198  }
199  return true;
200  }
201 
210  const bool Collection::checkHistoValue(const CoHistoProps& h, const std::string name, double& value) {
211  CoHistoProps::const_iterator i = h.find(name);
212  if(i == h.end()) {
213  return false;
214  }
215  if(EOF == std::sscanf(i->second.c_str(), "%lf", &value)) {
216  return false;
217  }
218  return true;
219  }
220 
229  std::string& Collection::getHistoValue(const CoHistoProps& h, const std::string& name, std::string& value, const std::string& def_value) {
230  if (!checkHistoValue(h, name, value)) {
231  value = def_value;
232  }
233  return value;
234  }
235 
244  int& Collection::getHistoValue(const CoHistoProps& h, const std::string& name, int& value, const int& def_value) {
245  if (!checkHistoValue(h, name, value)) {
246  value = def_value;
247  }
248  return value;
249  }
250 
259  double& Collection::getHistoValue(const CoHistoProps& h, const std::string name, double& value, const int def_value) {
260  if (!checkHistoValue(h, name, value)) {
261  value = def_value;
262  }
263  return value;
264  }
265 
272  const int Collection::ParseAxisLabels(const std::string& s, std::map<int, std::string>& labels) {
273  std::string tmp = s;
274  std::string::size_type pos = tmp.find("|");
275  char* stopstring = NULL;
276 
277  while (pos != std::string::npos) {
278  std::string label_pair = tmp.substr(0, pos);
279  tmp.replace(0, pos + 1, "");
280  if (label_pair.find("=") != std::string::npos) {
281  int nbin = strtol(label_pair.substr(0, label_pair.find("=")).c_str(), &stopstring, 10);
282  std::string label = label_pair.substr(label_pair.find("=") + 1, label_pair.length());
283  while (label.find("\'") != std::string::npos) {
284  label.erase(label.find("\'"), 1);
285  }
286  labels[nbin] = label;
287  }
288  pos = tmp.find("|");
289  }
290  return labels.size();
291  }
292 
298  CoHistoMap::const_iterator i = collection.find("EMU");
299  if (i != collection.end()) {
300  const CoHisto hs = i->second;
301  for (CoHisto::const_iterator j = hs.begin(); j != hs.end(); j++) {
302  std::string s = "";
304  HistoId hid = 0;
305  if (HistoDef::getHistoIdByName(j->first, hid)) {
306  EMUHistoDef hdef(hid);
307  book(hdef, j->second, config->getFOLDER_EMU());
308  }
309  }
310  }
311  }
312  }
313 
319  void Collection::bookDDUHistos(const HwId dduId) const {
320  CoHistoMap::const_iterator i = collection.find("DDU");
321  if (i != collection.end()) {
322  const CoHisto hs = i->second;
323  for (CoHisto::const_iterator j = hs.begin(); j != hs.end(); j++) {
324  std::string s = "";
326  HistoId hid = 0;
327  if (HistoDef::getHistoIdByName(j->first, hid)) {
328  DDUHistoDef hdef(hid, dduId);
329  book(hdef, j->second, config->getFOLDER_DDU());
330  }
331  }
332  }
333  }
334  }
335 
342  void Collection::bookCSCHistos(const HwId crateId, const HwId dmbId) const {
343  CoHistoMap::const_iterator i = collection.find("CSC");
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 = "";
348  HistoId hid = 0;
349  if (HistoDef::getHistoIdByName(j->first, hid)) {
351  CSCHistoDef hdef(hid, crateId, dmbId);
352  book(hdef, j->second, config->getFOLDER_CSC());
353  } else {
354  int from = 0, to = 0;
355  if (checkHistoValue(j->second, XML_BOOK_NAME_FROM, from) && checkHistoValue(j->second, XML_BOOK_NAME_TO, to)) {
356  for (int k = from; k <= to; k++) {
357  CSCHistoDef hdef(hid, crateId, dmbId, k);
358  book(hdef, j->second, config->getFOLDER_CSC());
359  }
360  }
361  }
362  }
363  }
364  }
365  }
366 
375  void Collection::bookCSCHistos(const HistoId hid, const HwId crateId, const HwId dmbId, const HwId addId) const {
376  CoHistoMap::const_iterator i = collection.find("CSC");
377  if (i != collection.end()) {
378  CoHisto::const_iterator j = i->second.find(h::names[hid]);
379  if (j != i->second.end()) {
380  CSCHistoDef hdef(hid, crateId, dmbId, addId);
381  book(hdef, j->second, config->getFOLDER_CSC());
382  }
383  }
384  }
385 
393  void Collection::book(const HistoDef& h, const CoHistoProps& p, const std::string& folder) const {
394 
395  MonitorObject* me = NULL;
396  std::string name = h.getName(), type, title, s;
397 
399  if (!config->needBookMO(h.getFullPath())) {
400  LOG_INFO << "MOFilter excluded " << name << " from booking";
401  config->fnPutHisto(h, me);
402  return;
403  }
404 
405  int i1, i2, i3;
406  double d1, d2, d3, d4, d5, d6;
407  bool ondemand = (getHistoValue(p, XML_BOOK_ONDEMAND, s, XML_BOOK_ONDEMAND_FALSE) == XML_BOOK_ONDEMAND_TRUE ? true : false);
408 
409  if (!checkHistoValue(p, XML_BOOK_HISTO_TYPE, type)) { throw Exception("Histogram does not have type!"); }
411 
412  if (ondemand) {
413  title = h.processTitle(title);
414  }
415 
416  if (type == "h1") {
417  me = config->fnBook(
418  HistoBookRequest(h, H1D, type, folder, title,
419  getHistoValue(p, "XBins", i1, 1),
420  getHistoValue(p, "XMin", d1, 0),
421  getHistoValue(p, "XMax", d2, 1)));
422  } else
423  if(type == "h2") {
424  me = config->fnBook(
425  HistoBookRequest(h, H2D, type, folder, title,
426  getHistoValue(p, "XBins", i1, 1),
427  getHistoValue(p, "XMin", d1, 0),
428  getHistoValue(p, "XMax", d2, 1),
429  getHistoValue(p, "YBins", i2, 1),
430  getHistoValue(p, "YMin", d3, 0),
431  getHistoValue(p, "YMax", d4, 1)));
432  } else
433  if(type == "h3") {
434  me = config->fnBook(
435  HistoBookRequest(h, H3D, type, folder, title,
436  getHistoValue(p, "XBins", i1, 1),
437  getHistoValue(p, "XMin", d1, 0),
438  getHistoValue(p, "XMax", d2, 1),
439  getHistoValue(p, "YBins", i2, 1),
440  getHistoValue(p, "YMin", d3, 0),
441  getHistoValue(p, "YMax", d4, 1),
442  getHistoValue(p, "ZBins", i3, 1),
443  getHistoValue(p, "ZMin", d5, 0),
444  getHistoValue(p, "ZMax", d6, 1)));
445  } else
446  if(type == "hp") {
447  me = config->fnBook(
448  HistoBookRequest(h, PROFILE, type, folder, title,
449  getHistoValue(p, "XBins", i1, 1),
450  getHistoValue(p, "XMin", d1, 0),
451  getHistoValue(p, "XMax", d2, 1),
452  getHistoValue(p, "YBins", i2, 1),
453  getHistoValue(p, "YMin", d3, 0),
454  getHistoValue(p, "YMax", d4, 1)));
455  } else
456  if(type == "hp2") {
457  me = config->fnBook(
458  HistoBookRequest(h, PROFILE2D, type, folder, title,
459  getHistoValue(p, "XBins", i1, 1),
460  getHistoValue(p, "XMin", d1, 0),
461  getHistoValue(p, "XMax", d2, 1),
462  getHistoValue(p, "YBins", i2, 1),
463  getHistoValue(p, "YMin", d3, 0),
464  getHistoValue(p, "YMax", d4, 1),
465  getHistoValue(p, "ZBins", i3, 1),
466  getHistoValue(p, "ZMin", d5, 0),
467  getHistoValue(p, "ZMax", d6, 1)));
468  } else {
469  throw Exception("Can not book histogram with type: " + type);
470  }
471 
472  if(me != NULL) {
473 
474  LockType lock(me->mutex);
475  TH1 *th = me->getTH1Lock();
476 
477  if(checkHistoValue(p, "XTitle", s)) {
478  if (ondemand) {
479  s = h.processTitle(s);
480  }
481  me->setAxisTitle(s, 1);
482  }
483 
484  if(checkHistoValue(p, "YTitle", s)) {
485  if (ondemand) {
486  s = h.processTitle(s);
487  }
488  me->setAxisTitle(s, 2);
489  }
490 
491  if(checkHistoValue(p, "ZTitle", s)) {
492  if (ondemand) {
493  s = h.processTitle(s);
494  }
495  me->setAxisTitle(s, 3);
496  }
497 
498  if(checkHistoValue(p, "SetOption", s)) th->SetOption(s.c_str());
499  if(checkHistoValue(p, "SetStats", i1)) th->SetStats(i1);
500  th->SetFillColor(getHistoValue(p, "SetFillColor", i1, DEF_HISTO_COLOR));
501  if(checkHistoValue(p, "SetXLabels", s)) {
502  std::map<int, std::string> labels;
503  ParseAxisLabels(s, labels);
504  for (std::map<int, std::string>::iterator l_itr = labels.begin(); l_itr != labels.end(); ++l_itr) {
505  th->GetXaxis()->SetBinLabel(l_itr->first, l_itr->second.c_str());
506  }
507  }
508  if(checkHistoValue(p, "SetYLabels", s)) {
509  std::map<int, std::string> labels;
510  ParseAxisLabels(s, labels);
511  for (std::map<int, std::string>::iterator l_itr = labels.begin(); l_itr != labels.end(); ++l_itr) {
512  th->GetYaxis()->SetBinLabel(l_itr->first, l_itr->second.c_str());
513  }
514  }
515  if(checkHistoValue(p, "LabelOption", s)) {
516  std::vector<std::string> v;
517  if(2 == Utility::tokenize(s, v, ",")) {
518  th->LabelsOption(v[0].c_str(), v[1].c_str());
519  }
520  }
521  if(checkHistoValue(p, "SetLabelSize", s)) {
522  std::vector<std::string> v;
523  if(2 == Utility::tokenize(s, v, ",")) {
524  th->SetLabelSize((double) atof(v[0].c_str()), v[1].c_str());
525  }
526  }
527  if(checkHistoValue(p, "SetTitleOffset", s)) {
528  std::vector<std::string> v;
529  if(2 == Utility::tokenize(s, v, ",")) {
530  th->SetTitleOffset((double) atof(v[0].c_str()), v[1].c_str());
531  }
532  }
533  if(checkHistoValue(p, "SetMinimum", d1)) th->SetMinimum(d1);
534  if(checkHistoValue(p, "SetMaximum", d1)) me->SetMaximum(d1);
535  if(checkHistoValue(p, "SetNdivisionsX", i1)) {
536  th->SetNdivisions(i1, "X");
537  th->GetXaxis()->CenterLabels(true);
538  }
539  if(checkHistoValue(p, "SetNdivisionsY", i1)) {
540  th->SetNdivisions(i1, "Y");
541  th->GetYaxis()->CenterLabels(true);
542  }
543  if(checkHistoValue(p, "SetTickLengthX", d1)) th->SetTickLength(d1, "X");
544  if(checkHistoValue(p, "SetTickLengthY", d1)) th->SetTickLength(d1, "Y");
545  if(checkHistoValue(p, "SetLabelSizeX", d1)) th->SetLabelSize(d1, "X");
546  if(checkHistoValue(p, "SetLabelSizeY", d1)) th->SetLabelSize(d1, "Y");
547  if(checkHistoValue(p, "SetLabelSizeZ", d1)) th->SetLabelSize(d1, "Z");
548  if(checkHistoValue(p, "SetErrorOption", s)) reinterpret_cast<TProfile*>(th)->SetErrorOption(s.c_str());
549 
550  lock.unlock();
551 
552  }
553 
554  LOG_DEBUG << "[Collection::book] booked " << h.getFullPath() << " (" << me << ")";
555 
557  config->fnPutHisto(h, me);
558 
559  }
560 
566  const bool Collection::isOnDemand(const HistoName& name) const {
567  CoHistoMap::const_iterator i = collection.find("CSC");
568  if (i != collection.end()) {
569  CoHisto hs = i->second;
570  CoHisto::const_iterator j = hs.find(name);
571  if (j != hs.end()) {
572  std::string s;
574  }
575  }
576  return false;
577  }
578 
584 
585  std::ostringstream buffer;
586  for(CoHistoMap::const_iterator hdmi = collection.begin(); hdmi != collection.end(); hdmi++) {
587  buffer << hdmi->first << " [" << std::endl;
588  for(CoHisto::const_iterator hdi = hdmi->second.begin(); hdi != hdmi->second.end(); hdi++) {
589  buffer << " " << hdi->first << " [" << std::endl;
590  for(CoHistoProps::const_iterator hi = hdi->second.begin(); hi != hdi->second.end(); hi++) {
591  buffer << " " << hi->first << " = " << hi->second << std::endl;
592  }
593  buffer << " ]" << std::endl;
594  }
595  buffer << " ]" << std::endl;
596  }
597  LOG_INFO << buffer.str();
598  }
599 
600 }
type
Definition: HCALResponse.h:22
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[]
const std::string & label
Definition: MVAComputer.cc:186
static const char XML_BOOK_NAME_FROM[]
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 ...
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.
CSC Level Histogram Type.
Collection(Configuration *const p_config)
Constructor.
tuple d1
Definition: debug_cff.py:7
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
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)
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
static std::string from(" from ")
tuple labels
Definition: L1TDQM_cfg.py:62
std::map< std::string, CoHistoProps > CoHisto
static const int DEF_HISTO_COLOR
static const char XML_BOOK_DEFINITION[]
void bookDDUHistos(const HwId dduId) const
Book DDU histograms.
string message
Definition: argparse.py:126
void book(const HistoDef &h, const CoHistoProps &p, const std::string &folder) const
Book histogram.
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[]
string s
Definition: asciidump.py:422
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.
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 HistoName names[]
mathSSE::Vec4< T > v
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