CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQMServices/ClientConfig/src/QTestConfigure.cc

Go to the documentation of this file.
00001 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "DQMServices/ClientConfig/interface/QTestConfigure.h"
00011 #include "DQMServices/Core/interface/QTest.h"
00012 #include "DQMServices/Core/interface/DQMStore.h"
00013 #include <cstring>
00014 #include <cstdlib>
00015 
00016 
00017 const char * QTestConfigure::findOrDefault(const std::map<std::string, std::string> &m,
00018                                            const char * item,
00019                                            const char * default_value) const {
00020   std::map<std::string, std::string>::const_iterator iter;
00021   if (( iter = m.find(std::string(item))) != m.end()) {
00022     return (*iter).second.c_str();
00023   }
00024   edm::LogWarning("QTestConfigure") << "Warning, using default value for parameter "
00025                                     << item << " with default_value: "
00026                                     << default_value << std::endl;
00027   return default_value;
00028 }
00029 
00030 bool QTestConfigure::enableTests(
00031     const std::map<std::string, std::map<std::string, std::string> > & tests,
00032     DQMStore * bei) {
00033   testsConfigured.clear();
00034   std::map<std::string, std::map<std::string, std::string> >::const_iterator itr;
00035   for (itr = tests.begin(); itr!= tests.end();++itr) {
00036     const std::map<std::string, std::string> &params= itr->second;
00037 
00038     std::string testName = itr->first;
00039     std::string testType = params.at("type");
00040 
00041     if(!std::strcmp(testType.c_str(),ContentsXRange::getAlgoName().c_str()))
00042       this->EnableXRangeTest(testName, params,bei);
00043     if(!std::strcmp(testType.c_str(),ContentsYRange::getAlgoName().c_str()))
00044       this->EnableYRangeTest(testName, params,bei);
00045     if(!std::strcmp(testType.c_str(),DeadChannel::getAlgoName().c_str()))
00046       this->EnableDeadChannelTest(testName, params,bei);
00047     if(!std::strcmp(testType.c_str(),NoisyChannel::getAlgoName().c_str()))
00048       this->EnableNoisyChannelTest(testName, params,bei);
00049     if(!std::strcmp(testType.c_str(),MeanWithinExpected::getAlgoName().c_str()))
00050       this->EnableMeanWithinExpectedTest(testName, params,bei);
00051     if(!std::strcmp(testType.c_str(),Comp2RefEqualH::getAlgoName().c_str()))
00052       this->EnableComp2RefEqualHTest(testName, params,bei);
00053     if(!std::strcmp(testType.c_str(),  Comp2RefChi2::getAlgoName().c_str()))
00054       this->EnableComp2RefChi2Test(testName, params,bei);
00055     if(!std::strcmp(testType.c_str(),Comp2RefKolmogorov::getAlgoName().c_str()))
00056       this->EnableComp2RefKolmogorovTest(testName, params,bei);
00057     if(!std::strcmp(testType.c_str(),ContentsWithinExpected::getAlgoName().c_str()))
00058       this->EnableContentsWithinExpectedTest(testName, params, bei);
00059     if(!std::strcmp(testType.c_str(),CompareToMedian::getAlgoName().c_str()))
00060       this->EnableCompareToMedianTest(testName, params, bei);
00061     if(!std::strcmp(testType.c_str(),CompareLastFilledBin::getAlgoName().c_str()))
00062       this->EnableCompareLastFilledBinTest(testName, params, bei);
00063 
00064   }
00065   return false;
00066 }
00067 
00068 void QTestConfigure::EnableComp2RefEqualHTest(std::string testName,
00069                                               const std::map<std::string, std::string> & params,
00070                                               DQMStore *bei) {
00071   QCriterion * qc1;
00072   if (! bei->getQCriterion(testName)) {
00073     testsConfigured.push_back(testName);
00074     qc1 = bei->createQTest(Comp2RefEqualH::getAlgoName(), testName);
00075   } else {
00076     qc1 = bei->getQCriterion(testName);
00077   }
00078   Comp2RefEqualH * me_qc1 = (Comp2RefEqualH *) qc1;
00079   double warning = atof(findOrDefault(params, "warning", "0"));
00080   double error   = atof(findOrDefault(params, "error", "0"));
00081   me_qc1->setWarningProb(warning);
00082   me_qc1->setErrorProb(error);
00083 }
00084 
00085 void QTestConfigure::EnableComp2RefChi2Test(std::string testName,
00086                                             const std::map<std::string, std::string> & params,
00087                                             DQMStore *bei) {
00088   QCriterion * qc1;
00089   if (! bei->getQCriterion(testName)) {
00090     testsConfigured.push_back(testName);
00091     qc1 = bei->createQTest(Comp2RefChi2::getAlgoName(), testName);
00092   } else {
00093     qc1 = bei->getQCriterion(testName);
00094   }
00095   Comp2RefChi2 * me_qc1 = (Comp2RefChi2 *) qc1;
00096   double warning = atof(findOrDefault(params, "warning", "0"));
00097   double error   = atof(findOrDefault(params, "error", "0"));
00098   me_qc1->setWarningProb(warning);
00099   me_qc1->setErrorProb(error);
00100 }
00101 
00102 
00103 void QTestConfigure::EnableComp2RefKolmogorovTest(std::string testName,
00104                                                   const std::map<std::string, std::string> & params,
00105                                                   DQMStore *bei) {
00106   QCriterion * qc1;
00107   if (! bei->getQCriterion(testName)) {
00108     testsConfigured.push_back(testName);
00109     qc1 = bei->createQTest(Comp2RefKolmogorov::getAlgoName(), testName);
00110   } else {
00111     qc1 = bei->getQCriterion(testName);
00112   }
00113   Comp2RefKolmogorov * me_qc1 = (Comp2RefKolmogorov *) qc1;
00114   double warning = atof(findOrDefault(params, "warning", "0"));
00115   double error   = atof(findOrDefault(params, "error", "0"));
00116   me_qc1->setWarningProb(warning);
00117   me_qc1->setErrorProb(error);
00118 }
00119 
00120 void QTestConfigure::EnableXRangeTest(std::string testName,
00121                                       const std::map<std::string, std::string> & params,
00122                                       DQMStore *bei) {
00123   QCriterion * qc1;
00124   if (! bei->getQCriterion(testName)) {
00125     testsConfigured.push_back(testName);
00126     qc1 = bei->createQTest(ContentsXRange::getAlgoName(),testName);
00127   } else {
00128     qc1 = bei->getQCriterion(testName);
00129   }
00130   ContentsXRange * me_qc1 = (ContentsXRange *) qc1;
00131   double xmin    = atof(findOrDefault(params, "xmin", "0"));
00132   double xmax    = atof(findOrDefault(params, "xmax", "0"));
00133   double warning = atof(findOrDefault(params, "warning", "0"));
00134   double error   = atof(findOrDefault(params, "error", "0"));
00135   me_qc1->setAllowedXRange(xmin, xmax);
00136   me_qc1->setWarningProb(warning);
00137   me_qc1->setErrorProb(error);
00138 }
00139 
00140 void QTestConfigure::EnableYRangeTest(std::string testName,
00141                                       const std::map<std::string, std::string> & params,
00142                                       DQMStore *bei) {
00143   QCriterion * qc1;
00144   if (! bei->getQCriterion(testName)) {
00145     testsConfigured.push_back(testName);
00146     qc1 = bei->createQTest(ContentsYRange::getAlgoName(), testName);
00147   } else {
00148     qc1 = bei->getQCriterion(testName);
00149   }
00150   ContentsYRange * me_qc1 = (ContentsYRange *) qc1;
00151   double ymin    = atof(findOrDefault(params, "ymin", "0"));
00152   double ymax    = atof(findOrDefault(params, "ymax", "0"));
00153   double warning = atof(findOrDefault(params, "warning", "0"));
00154   double error   = atof(findOrDefault(params, "error", "0"));
00155   unsigned int useEmptyBins = (unsigned int)atof(findOrDefault(params, "useEmptyBins", "0"));
00156   me_qc1->setAllowedYRange(ymin, ymax);
00157   me_qc1->setWarningProb(warning);
00158   me_qc1->setErrorProb(error);
00159   me_qc1->setUseEmptyBins(useEmptyBins);
00160 }
00161 
00162 void QTestConfigure::EnableDeadChannelTest(std::string testName,
00163                                            const std::map<std::string, std::string> & params,
00164                                            DQMStore *bei) {
00165   QCriterion * qc1;
00166   if (! bei->getQCriterion(testName)) {
00167     testsConfigured.push_back(testName);
00168     qc1 = bei->createQTest(DeadChannel::getAlgoName(), testName);
00169   } else {
00170     qc1 = bei->getQCriterion(testName);
00171   }
00172   DeadChannel * me_qc1 = ( DeadChannel *) qc1;
00173   unsigned int threshold =(unsigned int) atof(findOrDefault(params, "threshold", "0"));
00174   double warning = atof(findOrDefault(params, "warning", "0"));
00175   double error   = atof(findOrDefault(params, "error", "0"));
00176   me_qc1->setThreshold(threshold);
00177   me_qc1->setWarningProb(warning);
00178   me_qc1->setErrorProb(error);
00179 }
00180 
00181 void QTestConfigure::EnableNoisyChannelTest(std::string testName,
00182                                             const std::map<std::string, std::string> & params,
00183                                             DQMStore *bei) {
00184   QCriterion * qc1;
00185   if (! bei->getQCriterion(testName)) {
00186     testsConfigured.push_back(testName);
00187     qc1 = bei->createQTest(NoisyChannel::getAlgoName(), testName);
00188   } else {
00189     qc1 = bei->getQCriterion(testName);
00190   }
00191   NoisyChannel * me_qc1  = (NoisyChannel *) qc1;
00192   unsigned int neighbors = (unsigned int) atof(findOrDefault(params, "neighbours", "0"));
00193   double tolerance = atof(findOrDefault(params, "tolerance", "0"));
00194   double warning   = atof(findOrDefault(params, "warning", "0"));
00195   double error     = atof(findOrDefault(params, "error", "0"));
00196   me_qc1->setNumNeighbors (neighbors);
00197   me_qc1->setTolerance (tolerance);
00198   me_qc1->setWarningProb(warning);
00199   me_qc1->setErrorProb(error);
00200 }
00201 
00202 void QTestConfigure::EnableMeanWithinExpectedTest(std::string testName,
00203                                                   const std::map<std::string, std::string> & params,
00204                                                   DQMStore *bei) {
00205   QCriterion * qc1;
00206   if (! bei->getQCriterion(testName)) {
00207     testsConfigured.push_back(testName);
00208     qc1 = bei->createQTest(MeanWithinExpected::getAlgoName(), testName);
00209   } else {
00210     qc1 = bei->getQCriterion(testName);
00211   }
00212   MeanWithinExpected * me_qc1 = (MeanWithinExpected *) qc1;
00213   double warning     = atof(findOrDefault(params, "warning", "0"));
00214   double error       = atof(findOrDefault(params, "error", "0"));
00215   double mean        = atof(findOrDefault(params, "mean", "0"));
00216   int minEntries     = atoi(findOrDefault(params, "minEntries", "0"));
00217   double useRMSVal   = atof(findOrDefault(params, "useRMS", "0"));
00218   double useSigmaVal = atof(findOrDefault(params, "useSigma", "0"));
00219   double useRangeVal = atof(findOrDefault(params, "useRange", "0"));
00220   me_qc1->setWarningProb(warning);
00221   me_qc1->setErrorProb(error);
00222   me_qc1->setExpectedMean(mean);
00223 
00224   if (minEntries != 0)
00225     me_qc1->setMinimumEntries(minEntries);
00226 
00227   if (useRMSVal && useSigmaVal && useRangeVal)
00228     return;
00229 
00230   if (useRMSVal) {
00231     me_qc1->useRMS();
00232     return;
00233   }
00234 
00235   if (useSigmaVal) {
00236     me_qc1->useSigma(useSigmaVal);
00237     return;
00238   }
00239 
00240   if(useRangeVal) {
00241     float xmin = atof(findOrDefault(params, "xmin", "0"));
00242     float xmax = atof(findOrDefault(params, "xmax", "0"));
00243     me_qc1->useRange(xmin,xmax);
00244     return;
00245   }
00246 }
00247 
00248 void QTestConfigure::EnableCompareToMedianTest(std::string testName,
00249                                                const std::map<std::string, std::string> & params,
00250                                                DQMStore *bei) {
00251   QCriterion *qc1;
00252   if (! bei->getQCriterion(testName)) {
00253     testsConfigured.push_back(testName);
00254     qc1 = bei->createQTest(CompareToMedian::getAlgoName(), testName);
00255   } else {
00256     qc1 = bei->getQCriterion(testName);
00257   }
00258   CompareToMedian* vtm = (CompareToMedian*) qc1;
00259   vtm->setMin( (double) atof(findOrDefault(params, "MinRel", "0")));
00260   vtm->setMax( (double) atof(findOrDefault(params, "MaxRel", "0")));
00261   vtm->setEmptyBins( (int) atoi(findOrDefault(params, "UseEmptyBins", "0")));
00262   vtm->setMinMedian( (double) atof(findOrDefault(params, "MinAbs", "0")));
00263   vtm->setMaxMedian( (double) atof(findOrDefault(params, "MaxAbs", "0")));
00264   vtm->setWarningProb( (double) atof(findOrDefault(params, "warning", "0")));
00265   vtm->setErrorProb( (double) atof(findOrDefault(params, "error", "0")));
00266   vtm->setStatCut( (double) atof(findOrDefault(params, "StatCut", "0")));
00267 }
00268 
00269 /*
00270   void QTestConfigure::EnableMostProbableLandauTest(
00271   const std::string                        &roTEST_NAME,
00272   std::map<std::string, std::string> &roMParams,
00273   DQMStore                     *bei) {
00274 
00275   // Create QTest or Get already assigned one
00276   MostProbableLandau *poQTest = 0;
00277   if( QCriterion *poQCriteration = bei->getQCriterion( roTEST_NAME)) {
00278   // Current already assigned to given ME.
00279   poQTest = dynamic_cast<MostProbableLandau *>( poQCriteration);
00280   } else {
00281   // Test does not exist: create one
00282   testsConfigured.push_back( roTEST_NAME);
00283   poQCriteration = bei->createQTest( MostProbableLandau::getAlgoName(),
00284   roTEST_NAME);
00285 
00286   poQTest = dynamic_cast<MostProbableLandau *>( poQCriteration);
00287   }
00288 
00289   // Set probabilities thresholds.
00290   poQTest->setErrorProb    ( atof( roMfindOrDefault(params, "error", "0") );
00291   poQTest->setWarningProb  ( atof( roMfindOrDefault(params, "warning", "0") );
00292   poQTest->setXMin         ( atof( roMfindOrDefault(params, "xmin", "0") );
00293   poQTest->setXMax         ( atof( roMfindOrDefault(params, "xmax", "0") );
00294   poQTest->setNormalization( atof( roMfindOrDefault(params, "normalization", "0") );
00295   poQTest->setMostProbable ( atof( roMfindOrDefault(params, "mostprobable", "0") );
00296   poQTest->setSigma        ( atof( roMfindOrDefault(params, "sigma", "0") );
00297   }
00298 */
00299 void QTestConfigure::EnableContentsWithinExpectedTest(std::string testName,
00300                                                       const std::map<std::string, std::string> & params,
00301                                                       DQMStore *bei) {
00302   QCriterion * qc1;
00303   if (! bei->getQCriterion(testName)) {
00304     testsConfigured.push_back(testName);
00305     qc1 = bei->createQTest(ContentsWithinExpected::getAlgoName(), testName);
00306   } else {
00307     qc1 = bei->getQCriterion(testName);
00308   }
00309   ContentsWithinExpected * me_qc1 = (ContentsWithinExpected *) qc1;
00310   unsigned int useEmptyBins = (unsigned int) atof(findOrDefault(params, "useEmptyBins", "0"));
00311   double warning       = atof(findOrDefault(params, "warning", "0"));
00312   double error         = atof(findOrDefault(params, "error", "0"));
00313   double minMean       = atof(findOrDefault(params, "minMean", "0"));
00314   double maxMean       = atof(findOrDefault(params, "maxMean", "0"));
00315   double minRMS        = atof(findOrDefault(params, "minRMS", "0"));
00316   double maxRMS        = atof(findOrDefault(params, "maxRMS", "0"));
00317   double toleranceMean = atof(findOrDefault(params, "toleranceMean", "0"));
00318   int minEntries       = atoi(findOrDefault(params, "minEntries", "0"));
00319   me_qc1->setUseEmptyBins(useEmptyBins);
00320   me_qc1->setWarningProb(warning);
00321   me_qc1->setErrorProb(error);
00322 
00323   if ( minMean != 0 || maxMean != 0 )
00324     me_qc1->setMeanRange(minMean, maxMean);
00325 
00326   if ( minRMS != 0 || maxRMS != 0 )
00327     me_qc1->setRMSRange(minRMS, maxRMS);
00328 
00329   if ( toleranceMean != 0 )
00330     me_qc1->setMeanTolerance(toleranceMean);
00331 
00332   if ( minEntries != 0 )
00333     me_qc1->setMinimumEntries(minEntries);
00334 }
00335 
00336 void QTestConfigure::EnableCompareLastFilledBinTest(std::string testName,
00337                                                     const std::map<std::string, std::string> & params,
00338                                                     DQMStore *bei) {
00339   QCriterion * qc1;
00340   if (! bei->getQCriterion(testName)) {
00341     testsConfigured.push_back(testName);
00342     qc1 = bei->createQTest(CompareLastFilledBin::getAlgoName(), testName);
00343   } else {
00344     qc1 = bei->getQCriterion(testName);
00345   }
00346   CompareLastFilledBin * me_qc1 = (CompareLastFilledBin *) qc1;
00347 
00348   double warning = atof(findOrDefault(params, "warning", "0"));
00349   double error   = atof(findOrDefault(params, "error", "0"));
00350   double avVal   = atof(findOrDefault(params, "AvVal", "0"));
00351   double minVal  = atof(findOrDefault(params, "MinVal", "0"));
00352   double maxVal  = atof(findOrDefault(params, "MaxVal", "0"));
00353   me_qc1->setWarningProb(warning);
00354   me_qc1->setErrorProb(error);
00355   me_qc1->setAverage(avVal);
00356   me_qc1->setMin(minVal);
00357   me_qc1->setMax(maxVal);
00358 }
00359 
00360 /* void QTestConfigure::EnableContentsWithinExpectedASTest(std::string testName, std::map<std::string, std::string> params, DQMStore *bei){
00361 
00362 QCriterion * qc1;
00363 if(! bei->getQCriterion(testName) ){
00364 testsConfigured.push_back(testName);
00365 qc1 = bei->createQTest(ContentsWithinExpectedAS::getAlgoName(),testName);
00366 }else{
00367 qc1 = bei->getQCriterion(testName);
00368 }
00369 ContentsWithinExpectedAS * me_qc1 = (ContentsWithinExpectedAS *) qc1;
00370 
00371 double warning=atof(findOrDefault(params, "warning", "0");
00372 double error=atof(findOrDefault(params, "error", "0");
00373 me_qc1->setWarningProb(warning);
00374 me_qc1->setErrorProb(error);
00375 
00376 double minCont=atof(findOrDefault(params, "minCont", "0");
00377 double maxCont=atof(findOrDefault(params, "maxCont", "0");
00378 if ( minCont != 0 || maxCont != 0 ) me_qc1->setContentsRange(minCont, maxCont);
00379 
00380 
00381 } */
00382