Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:49

0001 /*
0002  *  see file for a description of this class.
0003  *
0004  *  $Date: 2012/02/07 18:35:00 $
0005  *  $Revision: 1.6.2.1 $
0006  *  \author Paolo Ronchese INFN Padova
0007  *
0008  */
0009 
0010 //-----------------------
0011 // This Class' Header --
0012 //-----------------------
0013 #include "CondTools/DT/test/validate/DTT0ValidateHandler.h"
0014 
0015 //-------------------------------
0016 // Collaborating Class Headers --
0017 //-------------------------------
0018 #include "CondFormats/DTObjects/interface/DTT0.h"
0019 
0020 //---------------
0021 // C++ Headers --
0022 //---------------
0023 #include <cmath>
0024 #include <iostream>
0025 #include <fstream>
0026 #include <sstream>
0027 
0028 //-------------------
0029 // Initializations --
0030 //-------------------
0031 
0032 //----------------
0033 // Constructors --
0034 //----------------
0035 DTT0ValidateHandler::DTT0ValidateHandler(const edm::ParameterSet& ps)
0036     : firstRun(ps.getParameter<unsigned int>("firstRun")),
0037       lastRun(ps.getParameter<unsigned int>("lastRun")),
0038       dataVersion(ps.getParameter<std::string>("version")),
0039       dataFileName(ps.getParameter<std::string>("outFile")),
0040       elogFileName(ps.getParameter<std::string>("logFile")) {
0041   std::ofstream logFile(elogFileName.c_str());
0042 }
0043 
0044 //--------------
0045 // Destructor --
0046 //--------------
0047 DTT0ValidateHandler::~DTT0ValidateHandler() {}
0048 
0049 //--------------
0050 // Operations --
0051 //--------------
0052 void DTT0ValidateHandler::getNewObjects() {
0053   int runNumber = firstRun;
0054   while (runNumber <= lastRun)
0055     addNewObject(runNumber++);
0056   return;
0057 }
0058 
0059 void DTT0ValidateHandler::addNewObject(int runNumber) {
0060   DTT0* t0 = new DTT0(dataVersion);
0061 
0062   std::stringstream run_fn;
0063   run_fn << "run" << runNumber << dataFileName;
0064 
0065   int status = 0;
0066   std::ofstream outFile(run_fn.str().c_str());
0067   std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
0068   int whe;
0069   int sta;
0070   int sec;
0071   int qua;
0072   int lay;
0073   int cel;
0074   int cur;
0075   int ndt = 20;
0076   float t0mean;
0077   float t0rms;
0078   float ckmean;
0079   float ckrms;
0080   int ckrun = runNumber % 3;
0081 
0082   whe = 3;
0083   while (--whe >= -2) {
0084     sta = 5;
0085     while (--sta) {
0086       if (sta == 4)
0087         sec = 15;
0088       else
0089         sec = 13;
0090       while (--sec) {
0091         qua = 4;
0092         while (--qua) {
0093           if ((sta == 4) && (qua == 2))
0094             continue;
0095           lay = 5;
0096           while (--lay) {
0097             cur = ndt;
0098             while (--cur) {
0099               cel = (ckrun ? cur : ndt - cur);
0100               t0mean = random() * 1.0 / 0x0fffffff;
0101               t0rms = random() * 0.2 / 0x7fffffff;
0102               t0mean -= 4.0;
0103               //              t0rms  /= 4.0;
0104               status = t0->set(whe, sta, sec, qua, lay, cel, t0mean, t0rms, DTTimeUnits::counts);
0105               outFile << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel << " " << t0mean
0106                       << " " << t0rms << std::endl;
0107               if (status)
0108                 logFile << "ERROR while setting cell T0 " << whe << " " << sta << " " << sec << " " << qua << " " << lay
0109                         << " " << cel << " , status = " << status << std::endl;
0110               status = t0->get(whe, sta, sec, qua, lay, cel, ckmean, ckrms, DTTimeUnits::counts);
0111               if (status)
0112                 logFile << "ERROR while checking cell T0 " << whe << " " << sta << " " << sec << " " << qua << " "
0113                         << lay << " " << cel << " , status = " << status << std::endl;
0114               if ((fabs(ckmean - t0mean) > 0.0001) || (fabs(ckrms - t0rms) > 0.0001))
0115                 logFile << "MISMATCH WHEN WRITING cell T0 " << whe << " " << sta << " " << sec << " " << qua << " "
0116                         << lay << " " << cel << " : " << t0mean << " " << t0rms << " -> " << ckmean << " " << ckrms
0117                         << std::endl;
0118             }
0119           }
0120         }
0121       }
0122     }
0123   }
0124 
0125   cond::Time_t snc = runNumber;
0126   m_to_transfer.push_back(std::make_pair(t0, snc));
0127 
0128   return;
0129 }
0130 
0131 std::string DTT0ValidateHandler::id() const { return dataVersion; }