00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CSCDQM_Configuration_H
00020 #define CSCDQM_Configuration_H
00021
00022 #include <string>
00023 #include <sstream>
00024
00025 #include <xercesc/parsers/XercesDOMParser.hpp>
00026 #include <xercesc/dom/DOMNodeList.hpp>
00027 #include <xercesc/dom/DOMElement.hpp>
00028 #include <xercesc/dom/DOMComment.hpp>
00029 #include <xercesc/sax/ErrorHandler.hpp>
00030 #include <xercesc/sax/SAXParseException.hpp>
00031 #include <xercesc/dom/DOMImplementation.hpp>
00032 #include <xercesc/dom/DOMWriter.hpp>
00033 #include <xercesc/framework/StdOutFormatTarget.hpp>
00034 #include <xercesc/dom/DOM.hpp>
00035
00036 #include <boost/preprocessor/tuple/elem.hpp>
00037 #include <boost/preprocessor/seq/for_each_i.hpp>
00038 #include <boost/preprocessor/stringize.hpp>
00039 #include <boost/preprocessor/cat.hpp>
00040 #include <boost/preprocessor/comparison/equal.hpp>
00041
00042 #include <boost/shared_ptr.hpp>
00043 #include <boost/function.hpp>
00044 #include <boost/bind.hpp>
00045
00046 #include <boost/timer.hpp>
00047
00048 #ifdef DQMGLOBAL
00049
00050 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00051
00052 #endif
00053
00054 #include "DQM/CSCMonitorModule/interface/CSCDQM_MonitorObjectProvider.h"
00055 #include "DQM/CSCMonitorModule/interface/CSCDQM_Exception.h"
00056 #include "DQM/CSCMonitorModule/interface/CSCDQM_Utility.h"
00057 #include "DQM/CSCMonitorModule/interface/CSCDQM_Logger.h"
00058
00059 #define CONFIG_PARAMETERS_SEQ_LEN 4
00060
00061 #define CONFIG_PARAMETERS_SEQ \
00062 \
00063 \
00064 (( bool, PROCESS_DDU, true, "enter DDU (and latter Chamber) sections (EventProcessor flag)" )) \
00065 (( bool, PROCESS_CSC, true, "enter Chamber section (EventProcessor flag)" )) \
00066 (( bool, PROCESS_EFF_HISTOS, true, "calculate efficiency histograms (Dispatcher flag)" )) \
00067 (( bool, PROCESS_EFF_PARAMETERS, true, "calculate efficiency parameters (EventProcessor flag)" )) \
00068 (( bool, BINCHECKER_CRC_ALCT, false , "check ALCT CRC (CSCDCCExaminer flag)" )) \
00069 (( bool, BINCHECKER_CRC_CLCT, false , "check CLCT CRC (CSCDCCExaminer flag)" )) \
00070 (( bool, BINCHECKER_CRC_CFEB, false , "check CFEB CRC (CSCDCCExaminer flag)" )) \
00071 (( bool, BINCHECKER_MODE_DDU, true , "set DDU mode (CSCDCCExaminer flag)" )) \
00072 (( bool, BINCHECKER_OUTPUT, false , "print 1 and 2 output (CSCDCCExaminer flag)" )) \
00073 (( bool, FRAEFF_AUTO_UPDATE, false , "start fractional and efficiency histogram update automatically (Dispatcher flag)" )) \
00074 (( bool, FRAEFF_SEPARATE_THREAD, false , "start fractional and efficiency histogram update on separate thread (EventProcessor flag)" )) \
00075 (( std::string, BOOKING_XML_FILE, "" , "histogram description (booking) file in XML format (Collection)" )) \
00076 (( std::string, FOLDER_EMU, "" , "root file folder name to be used for EMU histograms (EventProcessor)" )) \
00077 (( std::string, FOLDER_DDU, "" , "root file folder name to be used for DDU histograms (EventProcessor)" )) \
00078 (( std::string, FOLDER_CSC, "" , "root file folder name to be used for CSC histograms (EventProcessor)" )) \
00079 (( std::string, FOLDER_PAR, "" , "root file folder name to be used for parameters (EventProcessor)" )) \
00080 (( unsigned int, DDU_CHECK_MASK, 0xFFFFFFFF , "mask for cumulative EmuFileReader DDU error flags (EventProcessor)" )) \
00081 (( unsigned int, DDU_BINCHECK_MASK, 0x02080016 , "mask for DDU level examiner errors (CSCDCCExaminer)" )) \
00082 (( unsigned int, BINCHECK_MASK, 0xFFFFFFFF , "mask for chamber level examiner errors (CSCDCCExaminer)" )) \
00083 (( unsigned int, FRAEFF_AUTO_UPDATE_START, 5 , "event number to start automatic fractional and efficiency histogram updates from (Dispatcer)" )) \
00084 (( unsigned int, FRAEFF_AUTO_UPDATE_FREQ, 1 , "frequency in events to perform automatic fractional and efficiency histogram updates (Dispatcher)" )) \
00085 (( double, EFF_COLD_THRESHOLD, 0.1 , "threshold in fraction to check for cold (not reporting) HW (EventProcessor)" )) \
00086 (( double, EFF_COLD_SIGFAIL, 5.0 , "statistical significance for cold (not reporting) HW (EventProcessor)" )) \
00087 (( double, EFF_HOT_THRESHOLD, 0.1 , "threshold in fraction to check for hot HW (EventProcessor)" )) \
00088 (( double, EFF_HOT_SIGFAIL, 5.0 , "statistical significance for hot HW (EventProcessor)" )) \
00089 (( double, EFF_ERR_THRESHOLD, 0.1 , "threshold in fraction to check for errors in HW (EventProcessor)" )) \
00090 (( double, EFF_ERR_SIGFAIL, 5.0 , "statistical significance for errors in HW (EventProcessor)" )) \
00091 (( double, EFF_NODATA_THRESHOLD, 0.1 , "threshold in fraction to check for not reporting elements in HW (EventProcessor)" )) \
00092 (( double, EFF_NODATA_SIGFAIL, 5.0 , "statistical significance for not reportingelements in HW (EventProcessor)" )) \
00093 (( unsigned int, EVENTS_ECHO, 1000, "frequency in events to print echo message (EventProcessor)" )) \
00094 \
00095 \
00096
00097
00098 #define CONFIG_PARAMETER_DEFINE_MACRO(r, data, i, elem) \
00099 BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 0, elem) BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem);
00100
00101 #define CONFIG_PARAMETER_DEFAULT_MACRO(r, data, i, elem) \
00102 BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem) = BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 2, elem);
00103
00104 #define CONFIG_PARAMETER_GETTER_MACRO(r, data, i, elem) \
00105 const BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 0, elem) BOOST_PP_CAT(get, BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem))() const { \
00106 return BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem); \
00107 } \
00108
00109 #define CONFIG_PARAMETER_SETTER_MACRO(r, data, i, elem) \
00110 void BOOST_PP_CAT(set, BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem))(BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 0, elem) p) { \
00111 BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem) = p; \
00112 } \
00113
00114 #define CONFIG_PARAMETER_LOADPS_MACRO(r, data, i, elem) \
00115 BOOST_PP_CAT(set, BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem))(ps.getUntrackedParameter<BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 0, elem)>(BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem)), BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 2, elem)));
00116
00117 #define CONFIG_PARAMETER_LOADXML_MACRO(r, data, i, elem) \
00118 if (nodeName.compare(BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem))) == 0) { \
00119 stm >> BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem); \
00120 continue; \
00121 } \
00122
00123 #define CONFIG_PARAMETER_PRINTXML_MACRO(r, data, i, elem) \
00124 { \
00125 DOMComment* comment = doc->createComment(XERCES_TRANSCODE(BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 3, elem))); \
00126 DOMElement* el = doc->createElement(XERCES_TRANSCODE(BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem)))); \
00127 std::string value = toString(config.BOOST_PP_CAT(get, BOOST_PP_TUPLE_ELEM(CONFIG_PARAMETERS_SEQ_LEN, 1, elem))()); \
00128 DOMText* tdata = doc->createTextNode(XERCES_TRANSCODE(value.c_str())); \
00129 el->appendChild(tdata); \
00130 rootElem->appendChild(comment); \
00131 rootElem->appendChild(el); \
00132 } \
00133
00134 namespace cscdqm {
00135
00136 using namespace XERCES_CPP_NAMESPACE;
00137
00138 typedef struct MOFilterItem {
00139
00140 TPRegexp pattern;
00141 bool include;
00142
00143 MOFilterItem(const std::string pattern_, const bool include_) :
00144 pattern(pattern_.c_str()), include(include_) { }
00145
00146 };
00147
00152 class Configuration {
00153
00154 private:
00155
00156 bool printStatsOnExit;
00157 std::vector<MOFilterItem> MOFilterItems;
00158 BOOST_PP_SEQ_FOR_EACH_I(CONFIG_PARAMETER_DEFINE_MACRO, _, CONFIG_PARAMETERS_SEQ)
00159
00160 public:
00161
00162 boost::function< bool (const HistoDef& histoT, MonitorObject*&) > fnGetHisto;
00163 boost::function< bool (const HistoId id, MonitorObject*& mo) > fnGetCacheEMUHisto;
00164 boost::function< bool (const HistoId id, const HwId& id1, MonitorObject*& mo) > fnGetCacheDDUHisto;
00165 boost::function< bool (const HistoId id, const HwId& id1, const HwId& id2, const HwId& id3, MonitorObject*& mo) > fnGetCacheCSCHisto;
00166 boost::function< bool (const HistoId id, MonitorObject*& mo) > fnGetCacheParHisto;
00167 boost::function< void (const HistoDef& histoT, MonitorObject*&) > fnPutHisto;
00168 boost::function< MonitorObject* (const HistoBookRequest&) > fnBook;
00169 boost::function< CSCDetId (const unsigned int, const unsigned int) > fnGetCSCDetId;
00170 boost::function< bool (unsigned int&, unsigned int&, unsigned int&) > fnNextBookedCSC;
00171 boost::function< bool (unsigned int&, unsigned int&) > fnIsBookedCSC;
00172 boost::function< bool (unsigned int&) > fnIsBookedDDU;
00173
00174 BOOST_PP_SEQ_FOR_EACH_I(CONFIG_PARAMETER_GETTER_MACRO, _, CONFIG_PARAMETERS_SEQ)
00175 BOOST_PP_SEQ_FOR_EACH_I(CONFIG_PARAMETER_SETTER_MACRO, _, CONFIG_PARAMETERS_SEQ)
00176
00177 Configuration(const bool p_printStatsOnExit = true) {
00178 printStatsOnExit = p_printStatsOnExit;
00179 BOOST_PP_SEQ_FOR_EACH_I(CONFIG_PARAMETER_DEFAULT_MACRO, _, CONFIG_PARAMETERS_SEQ)
00180 reset();
00181 }
00182
00183 ~Configuration() {
00184 if (printStatsOnExit) {
00185 printStats();
00186 }
00187 }
00188
00189 void load(const std::string& configFile) {
00190 XMLPlatformUtils::Initialize();
00191 boost::shared_ptr<XercesDOMParser> parser(new XercesDOMParser());
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 XMLFileErrorHandler eh;
00202 parser->setErrorHandler(&eh);
00203
00204 parser->parse(configFile.c_str());
00205 DOMDocument *doc = parser->getDocument();
00206 DOMNode *docNode = (DOMNode*) doc->getDocumentElement();
00207
00208 DOMNodeList *itemList = docNode->getChildNodes();
00209 for(uint32_t i = 0; i < itemList->getLength(); i++) {
00210 DOMNode* node = itemList->item(i);
00211 if (node->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }
00212
00213 std::string nodeName = XMLString::transcode(node->getNodeName());
00214 std::string value = XMLString::transcode(node->getTextContent());
00215 std::istringstream stm(value);
00216
00217 BOOST_PP_SEQ_FOR_EACH_I(CONFIG_PARAMETER_LOADXML_MACRO, _, CONFIG_PARAMETERS_SEQ)
00218
00219 if (nodeName.compare("MO_FILTER") == 0) {
00220 DOMNodeList *filterList = node->getChildNodes();
00221 for(uint32_t j = 0; j < filterList->getLength(); j++) {
00222 DOMNode* filter = filterList->item(j);
00223 if (filter->getNodeType() != DOMNode::ELEMENT_NODE) { continue; }
00224 std::string filterName = XMLString::transcode(filter->getNodeName());
00225 std::string filterValue = XMLString::transcode(filter->getTextContent());
00226 MOFilterItems.insert(MOFilterItems.end(), MOFilterItem(filterValue, (filterName.compare("INCLUDE") == 0)));
00227 }
00228 }
00229
00230 }
00231
00232
00233
00234
00235 }
00236
00237 static void printXML(const Configuration& config) {
00238 XMLPlatformUtils::Initialize();
00239
00240 DOMImplementation* domImpl = DOMImplementationRegistry::getDOMImplementation(XERCES_TRANSCODE("core"));
00241 DOMDocument *doc = domImpl->createDocument(0, XERCES_TRANSCODE("processor_configuration"), 0);
00242 DOMElement* rootElem = doc->getDocumentElement();
00243
00244 BOOST_PP_SEQ_FOR_EACH_I(CONFIG_PARAMETER_PRINTXML_MACRO, _, CONFIG_PARAMETERS_SEQ)
00245
00246 DOMWriter *ser = domImpl->createDOMWriter();
00247 if (ser->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true)) {
00248 ser->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00249 }
00250 XMLFileErrorHandler eh;
00251 ser->setErrorHandler((DOMErrorHandler*) &eh);
00252 ser->writeNode(new StdOutFormatTarget(), *doc);
00253
00254 doc->release();
00255 XMLPlatformUtils::Terminate();
00256 }
00257
00258 #ifdef DQMGLOBAL
00259
00260 void load(const edm::ParameterSet& ps) {
00261 BOOST_PP_SEQ_FOR_EACH_I(CONFIG_PARAMETER_LOADPS_MACRO, _, CONFIG_PARAMETERS_SEQ)
00262 }
00263
00264 #endif
00265
00270 private:
00271
00272 boost::timer globalTimer;
00273 boost::timer eventTimer;
00274 boost::timer fraTimer;
00275 boost::timer effTimer;
00276 double eventTimeSum;
00277 double fraTimeSum;
00278 double effTimeSum;
00279
00280 public:
00281
00282 #define STATFIELD(caption, value, units) \
00283 logger << std::setfill(' '); \
00284 logger << std::setiosflags(std::ios::right) << std::setw(25) << caption << ": "; \
00285 logger << std::setiosflags(std::ios::right) << std::setw(12); \
00286 if (value < 0) { \
00287 logger << "NA"; \
00288 } else { \
00289 logger << value; \
00290 } \
00291 logger << std::setiosflags(std::ios::left) << std::setw(2) << units; \
00292 logger << std::endl;
00293 #define SEPFIELD \
00294 logger << std::setfill('-'); \
00295 logger << std::setw(25) << ""; \
00296 logger << std::setw(10) << ""; \
00297 logger << std::setw(2) << ""; \
00298 logger << std::endl;
00299
00300 void printStats() {
00301
00302 double allTime = globalTimer.elapsed();
00303 LogInfo logger;
00304 logger << std::endl;
00305
00306 STATFIELD("Events processed", nEvents, "")
00307 STATFIELD("Bad events: ", nEventsBad, "")
00308 STATFIELD("Good events: ", nEventsGood, "")
00309 STATFIELD("CSC events: ", nEventsCSC, "")
00310 STATFIELD("Unpacked DMBs: ", nUnpackedDMB, "")
00311
00312 SEPFIELD
00313
00314 STATFIELD("All event time: ", eventTimeSum, "s")
00315 double eventTimeAverage = (nEvents > 0 ? eventTimeSum / nEvents : -1.0);
00316 STATFIELD("Avg. event time: ", eventTimeAverage, "s")
00317 double eventRateAverage = (eventTimeSum > 0 ? nEvents / eventTimeSum : -1.0);
00318 STATFIELD("Avg. event rate: ", eventRateAverage, "Hz")
00319
00320 SEPFIELD
00321
00322 STATFIELD("All fra update time: ", fraTimeSum, "s")
00323 double fraTimeAverage = (fraCount > 0 ? fraTimeSum / fraCount : -1.0);
00324 STATFIELD("Avg. fra update time: ", fraTimeAverage, "s")
00325
00326 SEPFIELD
00327
00328 STATFIELD("All eff update time: ", effTimeSum, "s")
00329 double effTimeAverage = (effCount > 0 ? effTimeSum / effCount : -1.0);
00330 STATFIELD("Avg. eff update time: ", effTimeAverage, "s")
00331
00332 SEPFIELD
00333
00334 STATFIELD("All time: ", allTime, "s")
00335 double allTimeAverage = (nEvents > 0 ? allTime / nEvents : -1.0);
00336 STATFIELD("Avg. event all time: ", allTimeAverage, "s")
00337 double allRateAverage = (allTime > 0 ? nEvents / allTime : -1.0);
00338 STATFIELD("Avg. event all rate: ", allRateAverage, "Hz")
00339
00340 }
00341
00342 #undef STATFIELD
00343 #undef SEPFIELD
00344
00345 const bool needBookMO(const std::string name) const {
00346 bool result = true;
00347 for (unsigned int i = 0; i < MOFilterItems.size(); i++) {
00348 const MOFilterItem* filter = &MOFilterItems.at(i);
00349 if (Utility::regexMatch(filter->pattern, name)) result = filter->include;
00350 }
00351 return result;
00352 }
00353
00358 public:
00359
00360 void reset() {
00361 nEvents = 0;
00362 nEventsBad = 0;
00363 nEventsGood = 0;
00364 nEventsCSC = 0;
00365 nUnpackedDMB = 0;
00366 fraCount = 0;
00367 effCount = 0;
00368 eventTimeSum = 0.0;
00369 fraTimeSum = 0.0;
00370 effTimeSum = 0.0;
00371 }
00372
00373 const unsigned long getNEvents() const { return nEvents; }
00374 const unsigned long getNEventsBad() const { return nEventsBad; }
00375 const unsigned long getNEventsGood() const { return nEventsGood; }
00376 const unsigned long getNEventsCSC() const { return nEventsCSC; }
00377 const unsigned long getNUnpackedDMB() const { return nUnpackedDMB; }
00378
00379 void eventProcessTimer(const bool start) {
00380 if (start) {
00381 eventTimer.restart();
00382 } else {
00383 eventTimeSum += eventTimer.elapsed();
00384 }
00385 }
00386
00387 void updateFraTimer(const bool start) {
00388 if (start) {
00389 fraTimer.restart();
00390 } else {
00391 fraTimeSum += fraTimer.elapsed();
00392 fraCount++;
00393 }
00394 }
00395
00396 void updateEffTimer(const bool start) {
00397 if (start) {
00398 effTimer.restart();
00399 } else {
00400 effTimeSum += effTimer.elapsed();
00401 effCount++;
00402 }
00403 }
00404
00405 void incNEvents() {
00406 nEvents++;
00407 if (getEVENTS_ECHO() > 0) {
00408 if (getNEvents() % getEVENTS_ECHO() == 0) {
00409 LOG_INFO << "(echo) Events processed: " << std::setw(12) << getNEvents();
00410 }
00411 }
00412 }
00413 void incNEventsBad() { nEventsBad++; }
00414 void incNEventsGood() { nEventsGood++; }
00415 void incNEventsCSC() { nEventsCSC++; }
00416 void incNUnpackedDMB() { nUnpackedDMB++; }
00417
00418 private:
00419
00420 unsigned long nEvents;
00421 unsigned long nEventsBad;
00422 unsigned long nEventsGood;
00423 unsigned long nEventsCSC;
00424 unsigned long nUnpackedDMB;
00425 unsigned long fraCount;
00426 unsigned long effCount;
00427
00428
00429
00430 };
00431
00432 }
00433
00434 #undef CONFIG_PARAMETERS_SEQ_LEN
00435 #undef CONFIG_PARAMETERS_SEQ
00436 #undef CONFIG_PARAMETER_DEFINE_MACRO
00437 #undef CONFIG_PARAMETER_DEFAULT_MACRO
00438 #undef CONFIG_PARAMETER_GETTER_MACRO
00439 #undef CONFIG_PARAMETER_SETTER_MACRO
00440 #undef CONFIG_PARAMETER_LOADPS_MACRO
00441 #undef CONFIG_PARAMETER_LOADXML_MACRO
00442 #undef CONFIG_PARAMETER_PRINTXML_MACRO
00443
00444 #endif