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: 2010/01/12 13:00:00 $
0005  *  $Revision: 1.1 $
0006  *  \author Paolo Ronchese INFN Padova
0007  *
0008  */
0009 
0010 //-----------------------
0011 // This Class' Header --
0012 //-----------------------
0013 #include "CondTools/DT/test/validate/DTHVStatusValidateHandler.h"
0014 
0015 //-------------------------------
0016 // Collaborating Class Headers --
0017 //-------------------------------
0018 #include "CondFormats/DTObjects/interface/DTHVStatus.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 DTHVStatusValidateHandler::DTHVStatusValidateHandler(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 DTHVStatusValidateHandler::~DTHVStatusValidateHandler() {}
0047 
0048 //--------------
0049 // Operations --
0050 //--------------
0051 void DTHVStatusValidateHandler::getNewObjects() {
0052   int runNumber = firstRun;
0053   while (runNumber <= lastRun)
0054     addNewObject(runNumber++);
0055   return;
0056 }
0057 
0058 void DTHVStatusValidateHandler::addNewObject(int runNumber) {
0059   DTHVStatus* hv = new DTHVStatus(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 l_p;
0073   int fCell;
0074   int lCell;
0075   int flagA;
0076   int flagC;
0077   int flagS;
0078   int ckfCell;
0079   int cklCell;
0080   int ckflagA;
0081   int ckflagC;
0082   int ckflagS;
0083 
0084   whe = 3;
0085   while (--whe >= -2) {
0086     sta = 5;
0087     while (--sta) {
0088       if (sta == 4)
0089         sec = 15;
0090       else
0091         sec = 13;
0092       while (--sec) {
0093         qua = 4;
0094         while (--qua) {
0095           lay = 5;
0096           while (--lay) {
0097             fCell = 1;
0098             lCell = 99;
0099             if ((sta == 4) && (qua == 2))
0100               continue;
0101             if (qua == 2) {
0102               lCell = 56;
0103             } else {
0104               if (sta == 1)
0105                 lCell = 48;
0106               if (sta == 2)
0107                 lCell = 60;
0108               if (sta == 3)
0109                 lCell = 72;
0110               if (sta == 4) {
0111                 if ((sec >= 1) && (sec <= 3))
0112                   lCell = 96;
0113                 if ((sec == 4) || (sec == 13))
0114                   lCell = 72;
0115                 if ((sec >= 5) && (sec <= 7))
0116                   lCell = 96;
0117                 if ((sec == 8) || (sec == 12))
0118                   lCell = 92;
0119                 if ((sec == 9) || (sec == 11))
0120                   lCell = 48;
0121                 if ((sec == 10) || (sec == 14))
0122                   lCell = 60;
0123               }
0124             }
0125             fCell = lCell / 2;
0126             l_p = 2;
0127             while (l_p--) {
0128               if (l_p == 0) {
0129                 lCell = fCell - 1;
0130                 fCell = (lay == 4 ? 2 : 1);
0131               }
0132               flagA = random() & 0x0000000f;
0133               flagC = random() & 0x0000000f;
0134               flagS = random() & 0x0000000f;
0135               if ((flagA == 3) || (flagA >= 7))
0136                 flagA = 0;
0137               if ((flagC == 3) || (flagC >= 7))
0138                 flagC = 0;
0139               if ((flagS == 3) || (flagS >= 7))
0140                 flagS = 0;
0141               if (flagA || flagC || flagS)
0142                 status = hv->set(whe, sta, sec, qua, lay, l_p, fCell, lCell, flagA, flagC, flagS);
0143               else
0144                 status = 0;
0145               outFile << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << l_p << " " << fCell
0146                       << " " << lCell << " " << flagA << " " << flagC << " " << flagS << std::endl;
0147               if (status)
0148                 logFile << "ERROR while setting HV status" << whe << " " << sta << " " << sec << " " << qua << " "
0149                         << lay << " " << l_p << " , status = " << status << std::endl;
0150               ckfCell = fCell;
0151               cklCell = lCell;
0152               ckflagA = ckflagC = ckflagS = 0;
0153               if (flagA || flagC || flagS)
0154                 status = hv->get(whe, sta, sec, qua, lay, l_p, ckfCell, cklCell, ckflagA, ckflagC, ckflagS);
0155               else
0156                 status = 0;
0157               if (status)
0158                 logFile << "ERROR while checking HV status " << whe << " " << sta << " " << sec << " " << qua << " "
0159                         << lay << " " << l_p << " , status = " << status << std::endl;
0160               if ((ckfCell != fCell) || (cklCell != lCell) || (ckflagA != flagA) || (ckflagC != flagC) ||
0161                   (ckflagS != flagS))
0162                 logFile << "MISMATCH WHEN WRITING HV status " << whe << " " << sta << " " << sec << " " << qua << " "
0163                         << lay << " " << l_p << " : " << fCell << " " << lCell << " " << flagA << " " << flagC << " "
0164                         << flagS << " -> " << ckfCell << " " << cklCell << " " << ckflagA << " " << ckflagC << " "
0165                         << ckflagS << std::endl;
0166             }
0167           }
0168         }
0169       }
0170     }
0171   }
0172 
0173   cond::Time_t snc = runNumber;
0174   m_to_transfer.push_back(std::make_pair(hv, snc));
0175 
0176   return;
0177 }
0178 
0179 std::string DTHVStatusValidateHandler::id() const { return dataVersion; }