Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:49

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  $Date: 2008/09/29 13:12:53 $
0005  *  $Revision: 1.2 $
0006  *  \author Paolo Ronchese INFN Padova
0007  *
0008  */
0009 
0010 //-----------------------
0011 // This Class' Header --
0012 //-----------------------
0013 #include "CondTools/DT/test/validate/DTStatusFlagValidateHandler.h"
0014 
0015 //-------------------------------
0016 // Collaborating Class Headers --
0017 //-------------------------------
0018 #include "CondFormats/DTObjects/interface/DTStatusFlag.h"
0019 
0020 //---------------
0021 // C++ Headers --
0022 //---------------
0023 #include <iostream>
0024 #include <fstream>
0025 #include <sstream>
0026 
0027 //-------------------
0028 // Initializations --
0029 //-------------------
0030 
0031 //----------------
0032 // Constructors --
0033 //----------------
0034 DTStatusFlagValidateHandler::DTStatusFlagValidateHandler(const edm::ParameterSet& ps)
0035     : firstRun(ps.getParameter<unsigned int>("firstRun")),
0036       lastRun(ps.getParameter<unsigned int>("lastRun")),
0037       dataVersion(ps.getParameter<std::string>("version")),
0038       dataFileName(ps.getParameter<std::string>("outFile")),
0039       elogFileName(ps.getParameter<std::string>("logFile")) {
0040   std::ofstream logFile(elogFileName.c_str());
0041 }
0042 
0043 //--------------
0044 // Destructor --
0045 //--------------
0046 DTStatusFlagValidateHandler::~DTStatusFlagValidateHandler() {}
0047 
0048 //--------------
0049 // Operations --
0050 //--------------
0051 void DTStatusFlagValidateHandler::getNewObjects() {
0052   int runNumber = firstRun;
0053   while (runNumber <= lastRun)
0054     addNewObject(runNumber++);
0055   return;
0056 }
0057 
0058 void DTStatusFlagValidateHandler::addNewObject(int runNumber) {
0059   DTStatusFlag* sf = new DTStatusFlag(dataVersion);
0060 
0061   std::stringstream run_fn;
0062   run_fn << "run" << runNumber << dataFileName;
0063 
0064   int status = 0;
0065   std::ofstream outFile(run_fn.str().c_str());
0066   std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
0067   int whe;
0068   int sta;
0069   int sec;
0070   int qua;
0071   int lay;
0072   int cel;
0073 
0074   bool noiseFlag;
0075   bool feMask;
0076   bool tdcMask;
0077   bool trigMask;
0078   bool deadFlag;
0079   bool nohvFlag;
0080   bool cknoiseFlag;
0081   bool ckfeMask;
0082   bool cktdcMask;
0083   bool cktrigMask;
0084   bool ckdeadFlag;
0085   bool cknohvFlag;
0086 
0087   int sampleLimit = 100;
0088 
0089   whe = 3;
0090   while (--whe >= -2) {
0091     sta = 5;
0092     while (--sta) {
0093       if (sta == 4)
0094         sec = 15;
0095       else
0096         sec = 13;
0097       while (--sec) {
0098         qua = 4;
0099         while (--qua) {
0100           if ((sta == 4) && (qua == 2))
0101             continue;
0102           lay = 5;
0103           while (--lay) {
0104             cel = 48;
0105             while (--cel) {
0106               noiseFlag = ((random() & 0x0000ffff) < 500);
0107               feMask = ((random() & 0x0000ffff) < 500);
0108               tdcMask = ((random() & 0x0000ffff) < 500);
0109               trigMask = ((random() & 0x0000ffff) < 500);
0110               deadFlag = ((random() & 0x0000ffff) < 500);
0111               nohvFlag = ((random() & 0x0000ffff) < 500);
0112               cknoiseFlag = ckfeMask = cktdcMask = cktrigMask = ckdeadFlag = cknohvFlag = false;
0113               if (noiseFlag || feMask || tdcMask || trigMask || deadFlag || nohvFlag) {
0114                 if (sampleLimit--) {
0115                   status =
0116                       sf->set(whe, sta, sec, qua, lay, cel, noiseFlag, feMask, tdcMask, trigMask, deadFlag, nohvFlag);
0117                 } else {
0118                   status = sf->setCellNoise(whe, sta, sec, qua, lay, cel, noiseFlag);
0119                   status = sf->setCellFEMask(whe, sta, sec, qua, lay, cel, feMask);
0120                   status = sf->setCellTDCMask(whe, sta, sec, qua, lay, cel, tdcMask);
0121                   status = sf->setCellTrigMask(whe, sta, sec, qua, lay, cel, trigMask);
0122                   status = sf->setCellDead(whe, sta, sec, qua, lay, cel, deadFlag);
0123                   status = sf->setCellNoHV(whe, sta, sec, qua, lay, cel, nohvFlag);
0124                 }
0125               } else {
0126                 status = 0;
0127               }
0128 
0129               outFile << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << " " << noiseFlag
0130                       << " " << feMask << " " << tdcMask << " " << trigMask << " " << deadFlag << " " << nohvFlag
0131                       << std::endl;
0132               if (status)
0133                 logFile << "ERROR while setting cell flags " << whe << " " << sta << " " << sec << " " << qua << " "
0134                         << lay << " " << cel << " , status = " << status << std::endl;
0135               if (noiseFlag || feMask || tdcMask || trigMask || deadFlag || nohvFlag)
0136                 status = sf->get(
0137                     whe, sta, sec, qua, lay, cel, cknoiseFlag, ckfeMask, cktdcMask, cktrigMask, ckdeadFlag, cknohvFlag);
0138               else
0139                 status = 0;
0140               if (status)
0141                 logFile << "ERROR while checking cell flags " << whe << " " << sta << " " << sec << " " << qua << " "
0142                         << lay << " " << cel << " , status = " << status << std::endl;
0143               if ((cknoiseFlag != noiseFlag) || (ckfeMask != feMask) || (cktdcMask != tdcMask) ||
0144                   (cktrigMask != trigMask) || (ckdeadFlag != deadFlag) || (cknohvFlag != nohvFlag))
0145                 logFile << "MISMATCH WHEN WRITING cell flags " << whe << " " << sta << " " << sec << " " << qua << " "
0146                         << lay << " " << cel << " : " << noiseFlag << " " << feMask << " " << tdcMask << " " << trigMask
0147                         << " " << deadFlag << " " << nohvFlag << " -> " << cknoiseFlag << " " << ckfeMask << " "
0148                         << cktdcMask << " " << cktrigMask << " " << ckdeadFlag << " " << cknohvFlag << std::endl;
0149               //              }
0150             }
0151           }
0152         }
0153       }
0154     }
0155   }
0156 
0157   cond::Time_t snc = runNumber;
0158   m_to_transfer.push_back(std::make_pair(sf, snc));
0159 
0160   return;
0161 }
0162 
0163 std::string DTStatusFlagValidateHandler::id() const { return dataVersion; }