Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  $Date: 2010/01/20 17:29:27 $
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/DTTPGParametersValidateHandler.h"
0014 
0015 //-------------------------------
0016 // Collaborating Class Headers --
0017 //-------------------------------
0018 #include "CondFormats/DTObjects/interface/DTTPGParameters.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 DTTPGParametersValidateHandler::DTTPGParametersValidateHandler(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 DTTPGParametersValidateHandler::~DTTPGParametersValidateHandler() {}
0048 
0049 //--------------
0050 // Operations --
0051 //--------------
0052 void DTTPGParametersValidateHandler::getNewObjects() {
0053   int runNumber = firstRun;
0054   while (runNumber <= lastRun)
0055     addNewObject(runNumber++);
0056   return;
0057 }
0058 
0059 void DTTPGParametersValidateHandler::addNewObject(int runNumber) {
0060   DTTPGParameters* tpg = new DTTPGParameters(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 nClock;
0072   float tPhase;
0073   int ckclock;
0074   float ckphase;
0075 
0076   whe = 3;
0077   while (--whe >= -2) {
0078     sta = 5;
0079     while (--sta) {
0080       if (sta == 4)
0081         sec = 15;
0082       else
0083         sec = 13;
0084       while (--sec) {
0085         nClock = random() & 0x000000ff;
0086         tPhase = random() * 16.0 / 0x7fffffff;
0087         status = tpg->set(whe, sta, sec, nClock, tPhase, DTTimeUnits::counts);
0088         outFile << whe << " " << sta << " " << sec << " " << nClock << " " << tPhase << std::endl;
0089         if (status)
0090           logFile << "ERROR while setting cell TPGParameters " << whe << " " << sta << " " << sec
0091                   << " , status = " << status << std::endl;
0092         status = tpg->get(whe, sta, sec, ckclock, ckphase, DTTimeUnits::counts);
0093         if (status)
0094           logFile << "ERROR while checking cell TPGParameters " << whe << " " << sta << " " << sec
0095                   << " , status = " << status << std::endl;
0096         if ((std::abs(ckclock - nClock) > 0.0001) || (std::abs(ckphase - tPhase) > 0.0001))
0097           logFile << "MISMATCH WHEN WRITING cell TPGParameters " << whe << " " << sta << " " << sec << " : " << nClock
0098                   << " " << tPhase << " -> " << ckclock << " " << ckphase << std::endl;
0099       }
0100     }
0101   }
0102 
0103   cond::Time_t snc = runNumber;
0104   m_to_transfer.push_back(std::make_pair(tpg, snc));
0105 
0106   return;
0107 }
0108 
0109 std::string DTTPGParametersValidateHandler::id() const { return dataVersion; }