CMS 3D CMS Logo

CSCMonitorModule_collection.cc

Go to the documentation of this file.
00001 /*  =====================================================================================
00002  *
00003  *       Filename:  CSCMonitorModule_collection.cc
00004  *
00005  *    Description:  Method loadXMLBookingInfo implementation
00006  *
00007  *        Version:  1.0
00008  *        Created:  04/18/2008 03:39:49 PM
00009  *       Revision:  none
00010  *       Compiler:  gcc
00011  *
00012  *         Author:  Valdas Rapsevicius (VR), Valdas.Rapsevicius@cern.ch
00013  *        Company:  CERN, CH
00014  *
00015  *  =====================================================================================
00016  */
00017 
00018 #include "DQM/CSCMonitorModule/interface/CSCMonitorModule.h"
00019 #include <xercesc/parsers/XercesDOMParser.hpp>
00020 #include <xercesc/dom/DOMNodeList.hpp>
00021 
00022 #define DEF_HISTO_COLOR 48
00023 #define findHistoValue(a,b,c) CSCUtility::findHistoValue(a,b,c)
00024 #define getHistoValue(a,b,c,d) CSCUtility::getHistoValue(a,b,c,d)
00025 #define ParseAxisLabels(a,b) CSCUtility::ParseAxisLabels(a,b)
00026 #define tokenize(a,b,c) CSCUtility::tokenize(a,b,c)
00027 
00028 using namespace XERCES_CPP_NAMESPACE;
00029 
00030 
00037 const bool CSCMonitorModule::isMEValid(const std::string name, MonitorElement*& me) {
00038   me = dbe->get(name);
00039   if(me == NULL) {
00040     LOGINFO("ME not found") << "MonitorElement [" << name << "] not found.";
00041     return false;
00042   } else {
00043     return true;
00044   }
00045 }
00046 
00053 const bool CSCMonitorModule::MEEventInfo(const std::string name, MonitorElement*& me) {
00054   return isMEValid(rootDir + EVENTINFO_FOLDER + name, me);
00055 }
00056 
00063 const bool CSCMonitorModule::MEReportSummaryContents(const std::string name, MonitorElement*& me) {
00064   return isMEValid(rootDir + SUMCONTENTS_FOLDER + name, me);
00065 }
00066 
00073 const bool CSCMonitorModule::MEEMU(const std::string name, MonitorElement*& me) {
00074   return isMEValid(rootDir + SUMMARY_FOLDER + name, me);
00075 }
00076 
00077 
00085 const bool CSCMonitorModule::MEDDU(const unsigned int dduId, const std::string name, MonitorElement*& me) {
00086 
00087   std::string buffer;
00088 
00089   bool result = isMEValid(rootDir + DDU_FOLDER + CSCUtility::getDDUTag(dduId, buffer) + "/" + name, me);
00090   if (!result && hitBookDDU) {
00091     LOGINFO("DDU ME booking on demand") << "DDU id = " << dduId << " is being booked on demand (hitBookDDU = " << std::boolalpha << hitBookDDU << ")";
00092     dbe->setCurrentFolder(rootDir + DDU_FOLDER + CSCUtility::getDDUTag(dduId, buffer));
00093     book("DDU");
00094     result = isMEValid(rootDir + DDU_FOLDER + CSCUtility::getDDUTag(dduId, buffer) + "/" + name, me);
00095   }
00096 
00097   return result;
00098 
00099 }
00100 
00101 
00107 int CSCMonitorModule::loadCollection() {
00108 
00109   XMLPlatformUtils::Initialize();
00110   XercesDOMParser *parser = new XercesDOMParser();
00111   parser->setValidationScheme(XercesDOMParser::Val_Always);
00112   parser->setDoNamespaces(true);
00113   parser->setDoSchema(true);
00114   parser->setValidationSchemaFullChecking(false); // this is default
00115   parser->setCreateEntityReferenceNodes(true);  // this is default
00116   parser->setIncludeIgnorableWhitespace (false);
00117 
00118   parser->parse(bookingFile.c_str());
00119   DOMDocument *doc = parser->getDocument();
00120   DOMNode *docNode = (DOMNode*) doc->getDocumentElement();
00121   
00122   std::string nodeName = XMLString::transcode(docNode->getNodeName());
00123   if( nodeName != "Booking" ){
00124     LOGERROR("loadCollection") << "Wrong booking root node: " << XMLString::transcode(docNode->getNodeName());
00125     delete parser;
00126     return 1;
00127   }
00128   DOMNodeList *itemList = docNode->getChildNodes();
00129 
00130   for(uint32_t i=0; i < itemList->getLength(); i++) {
00131 
00132     nodeName = XMLString::transcode(itemList->item(i)->getNodeName());
00133     if(nodeName != "Histogram") {
00134       continue;
00135     }
00136 
00137     DOMNodeList *props  = itemList->item(i)->getChildNodes();
00138     Histo h;
00139     std::string prefix = "", name = "";
00140     for(uint32_t j = 0; j < props->getLength(); j++) {
00141       std::string tname  = XMLString::transcode(props->item(j)->getNodeName());
00142       std::string tvalue = XMLString::transcode(props->item(j)->getTextContent());
00143       h.insert(std::make_pair(tname, tvalue));
00144       if(tname == "Name")   name   = tvalue;
00145       if(tname == "Prefix") prefix = tvalue;
00146     }
00147 
00148     if(!name.empty() && !prefix.empty()) {
00149       HistoDefMapIter it = collection.find(prefix);
00150       if( it == collection.end()) {
00151         HistoDef hd;
00152         hd.insert(make_pair(name, h));
00153         collection.insert(make_pair(prefix, hd)); 
00154       } else {
00155         it->second.insert(make_pair(name, h));
00156       }
00157     }
00158 
00159   }
00160 
00161   delete parser;
00162 
00163   std::ostringstream buffer;
00164   buffer << std::endl;
00165   for(HistoDefMapIter hdmi = collection.begin(); hdmi != collection.end(); hdmi++) {
00166     buffer << " # of " << hdmi->first << " histograms loaded =  " << hdmi->second.size() << std::endl;
00167   }
00168   LOGINFO("Histograms loaded") << buffer.str();
00169 
00170   return 0;
00171 }
00172 
00173 
00179 void CSCMonitorModule::book(const std::string prefix) {
00180 
00181   HistoDefMapIter hdmi = collection.find(prefix);
00182 
00183   if( hdmi != collection.end()) {
00184 
00185     for(HistoDefIter hdi = hdmi->second.begin(); hdi != hdmi->second.end(); hdi++) {
00186       
00187       MonitorElement* me = NULL;
00188       std::string name, type, title, s;
00189       int i, j, l;
00190       double d, e, f, g, h, k;
00191       
00192       name  = hdi->first;
00193       type  = getHistoValue(hdi->second, "Type", type, "h1");
00194       title = getHistoValue(hdi->second, "Title", title, hdi->first);
00195 
00196       if (type == "h1") {
00197         me = dbe->book1D(name, title,
00198             getHistoValue(hdi->second, "XBins", i, 1),
00199             getHistoValue(hdi->second, "XMin",  d, 0),
00200             getHistoValue(hdi->second, "XMax",  e, 1));
00201       }
00202       if(type == "h2") {
00203         me = dbe->book2D(name, title,
00204             getHistoValue(hdi->second, "XBins", i, 1),
00205             getHistoValue(hdi->second, "XMin",  d, 0),
00206             getHistoValue(hdi->second, "XMax",  e, 1),
00207             getHistoValue(hdi->second, "YBins", j, 1),
00208             getHistoValue(hdi->second, "YMin",  f, 0),
00209             getHistoValue(hdi->second, "YMax",  g, 1));
00210       }
00211       if(type == "h3") {
00212         me = dbe->book3D(name, title,
00213             getHistoValue(hdi->second, "XBins", i, 1),
00214             getHistoValue(hdi->second, "XMin",  d, 0),
00215             getHistoValue(hdi->second, "XMax",  e, 1),
00216             getHistoValue(hdi->second, "YBins", j, 1),
00217             getHistoValue(hdi->second, "YMin",  f, 0),
00218             getHistoValue(hdi->second, "YMax",  g, 1),
00219             getHistoValue(hdi->second, "ZBins", l, 1),
00220             getHistoValue(hdi->second, "ZMin",  h, 0),
00221             getHistoValue(hdi->second, "ZMax",  k, 1));
00222       }
00223       if(type == "hp") {
00224         me = dbe->bookProfile(name, title,
00225             getHistoValue(hdi->second, "XBins", i, 1),
00226             getHistoValue(hdi->second, "XMin",  d, 0),
00227             getHistoValue(hdi->second, "XMax",  e, 1),
00228             getHistoValue(hdi->second, "YBins", j, 1),
00229             getHistoValue(hdi->second, "YMin",  f, 0),
00230             getHistoValue(hdi->second, "YMax",  g, 1));
00231       }
00232       if(type == "hp2") {
00233         me = dbe->bookProfile2D(name, title,
00234             getHistoValue(hdi->second, "XBins", i, 1),
00235             getHistoValue(hdi->second, "XMin",  d, 0),
00236             getHistoValue(hdi->second, "XMax",  e, 1),
00237             getHistoValue(hdi->second, "YBins", j, 1),
00238             getHistoValue(hdi->second, "YMin",  f, 0),
00239             getHistoValue(hdi->second, "YMax",  g, 1),
00240             getHistoValue(hdi->second, "ZBins", l, 1),
00241             getHistoValue(hdi->second, "ZMin",  h, 0),
00242             getHistoValue(hdi->second, "ZMax",  k, 1));
00243       }
00244 
00245       if(me != NULL) {
00246         TH1 *h = me->getTH1();
00247         if(findHistoValue(hdi->second, "XTitle", s)) me->setAxisTitle(s, 1);
00248         if(findHistoValue(hdi->second, "YTitle", s)) me->setAxisTitle(s, 2);
00249         if(findHistoValue(hdi->second, "ZTitle", s)) me->setAxisTitle(s, 3);
00250         if(findHistoValue(hdi->second, "SetOption", s)) h->SetOption(s.c_str());
00251         if(findHistoValue(hdi->second, "SetStats", i)) h->SetStats(i);
00252         h->SetFillColor(getHistoValue(hdi->second, "SetFillColor", i, DEF_HISTO_COLOR));
00253         if(findHistoValue(hdi->second, "SetXLabels", s)) {
00254           std::map<int, std::string> labels;
00255           ParseAxisLabels(s, labels);
00256           for (std::map<int, std::string>::iterator l_itr = labels.begin(); l_itr != labels.end(); ++l_itr) {
00257             h->GetXaxis()->SetBinLabel(l_itr->first, l_itr->second.c_str());
00258           }
00259         }
00260         if(findHistoValue(hdi->second, "SetYLabels", s)) {
00261           std::map<int, std::string> labels;
00262           ParseAxisLabels(s, labels);
00263           for (std::map<int, std::string>::iterator l_itr = labels.begin(); l_itr != labels.end(); ++l_itr) {
00264             h->GetYaxis()->SetBinLabel(l_itr->first, l_itr->second.c_str());
00265           }
00266         }
00267         if(findHistoValue(hdi->second, "LabelOption", s)) {
00268           std::vector<std::string> v;
00269           if(2 == tokenize(s, v, ",")) {
00270             h->LabelsOption(v[0].c_str(), v[1].c_str());
00271           }
00272         }
00273         if(findHistoValue(hdi->second, "SetLabelSize", s)) {
00274           std::vector<std::string> v;
00275           if(2 == tokenize(s, v, ",")) {
00276             h->SetLabelSize((double) atof(v[0].c_str()), v[1].c_str());
00277           }
00278         }
00279         if(findHistoValue(hdi->second, "SetTitleOffset", s)) {
00280           std::vector<std::string> v;
00281           if(2 == tokenize(s, v, ",")) {
00282             h->SetTitleOffset((double) atof(v[0].c_str()), v[1].c_str());
00283           }
00284         }
00285         if(findHistoValue(hdi->second, "SetMinimum", d)) h->SetMinimum(d);
00286         if(findHistoValue(hdi->second, "SetMaximum", d)) h->SetMaximum(d);
00287         if(findHistoValue(hdi->second, "SetNdivisionsX", i)) {
00288           h->SetNdivisions(i, "X");
00289           h->GetXaxis()->CenterLabels(true);
00290         }
00291         if(findHistoValue(hdi->second, "SetNdivisionsY", i)) {
00292           h->SetNdivisions(i, "Y");
00293           h->GetYaxis()->CenterLabels(true);
00294         }
00295         if(findHistoValue(hdi->second, "SetTickLengthX", d)) h->SetTickLength(d, "X");
00296         if(findHistoValue(hdi->second, "SetTickLengthY", d)) h->SetTickLength(d, "Y");
00297         if(findHistoValue(hdi->second, "SetLabelSizeX", d)) h->SetLabelSize(d, "X");
00298         if(findHistoValue(hdi->second, "SetLabelSizeY", d)) h->SetLabelSize(d, "Y");
00299         if(findHistoValue(hdi->second, "SetLabelSizeZ", d)) h->SetLabelSize(d, "Z");
00300         if(findHistoValue(hdi->second, "SetErrorOption", s)) reinterpret_cast<TProfile*>(h)->SetErrorOption(s.c_str());
00301 
00302       }
00303 
00304     }
00305   }
00306 }
00307 
00313 void CSCMonitorModule::printCollection(){
00314 
00315   std::ostringstream buffer;
00316   for(HistoDefMapIter hdmi = collection.begin(); hdmi != collection.end(); hdmi++) {
00317     buffer << hdmi->first << " [" << std::endl;
00318     for(HistoDefIter hdi = hdmi->second.begin(); hdi != hdmi->second.end(); hdi++) {
00319       buffer << "   " << hdi->first << " [" << std::endl;
00320       for(HistoIter hi = hdi->second.begin(); hi != hdi->second.end(); hi++) {
00321         buffer << "     " << hi->first << " = " << hi->second << std::endl;
00322       }
00323       buffer << "   ]" << std::endl;
00324     }
00325     buffer << " ]" << std::endl;
00326   }
00327   LOGINFO("Histogram collection") << buffer.str();
00328 
00329 }
00330 

Generated on Tue Jun 9 17:32:33 2009 for CMSSW by  doxygen 1.5.4