Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-05 02:38:57

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 Toy EDAnalyzer for testing purposes only.
0005 
0006 ----------------------------------------------------------------------*/
0007 
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include <cmath>
0013 #include <fstream>
0014 #include <iostream>
0015 #include <map>
0016 #include <sstream>
0017 #include <stdexcept>
0018 #include <string>
0019 
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 
0023 #include "CondTools/DT/test/validate/DTCompMapValidateDBRead.h"
0024 #include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
0025 #include "CondFormats/DataRecord/interface/DTReadOutMappingRcd.h"
0026 
0027 DTCompMapValidateDBRead::DTCompMapValidateDBRead(edm::ParameterSet const& p)
0028     : dataFileName(p.getParameter<std::string>("chkFile")),
0029       elogFileName(p.getParameter<std::string>("logFile")),
0030       dtreadoutmappingToken_(esConsumes()) {}
0031 
0032 DTCompMapValidateDBRead::DTCompMapValidateDBRead(int i) : dtreadoutmappingToken_(esConsumes()) {}
0033 
0034 void DTCompMapValidateDBRead::analyze(const edm::Event& e, const edm::EventSetup& context) {
0035   using namespace edm::eventsetup;
0036   // Context is not used.
0037   std::cout << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0038   std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;
0039   std::stringstream run_fn;
0040   //  run_fn << "run" << e.id().run() << dataFileName;
0041   //  std::ifstream chkFile( run_fn.str().c_str() );
0042   std::ifstream chkFile(dataFileName.c_str());
0043   std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
0044   auto ro = context.getHandle(dtreadoutmappingToken_);
0045   std::cout << ro->mapRobRos() << " " << ro->mapCellTdc() << std::endl;
0046   std::cout << std::distance(ro->begin(), ro->end()) << " data in the container" << std::endl;
0047   int whe;
0048   int sta;
0049   int sec;
0050   int qua;
0051   int lay;
0052   int cel;
0053   int ddu;
0054   int ros;
0055   int rob;
0056   int tdc;
0057   int cha;
0058   int ckwhe;
0059   int cksta;
0060   int cksec;
0061   int ckqua;
0062   int cklay;
0063   int ckcel;
0064   int ckddu;
0065   int ckros;
0066   int ckrob;
0067   int cktdc;
0068   int ckcha;
0069   while (chkFile >> ckddu >> ckros >> ckrob >> cktdc >> ckcha >> ckwhe >> cksta >> cksec >> ckqua >> cklay >> ckcel) {
0070     /*
0071     if ( ( cklay ==  4 ) &&
0072          ( ckcel ==  1 ) ) continue;
0073     if ( ( cksta ==  4 ) &&
0074          ( cksec ==  8 ) &&
0075          ( ckcel >  92 ) ) continue;
0076     if ( ( cksta ==  4 ) &&
0077          ( cksec == 12 ) &&
0078          ( ckcel >  92 ) ) continue;
0079     if ( ( cksta ==  4 ) &&
0080          ( cksec ==  8 ) &&
0081          ( cklay ==  1 ) &&
0082          ( ckcel >  91 ) ) continue;
0083     if ( ( cksta ==  4 ) &&
0084          ( cksec == 12 ) &&
0085          ( cklay ==  1 ) &&
0086          ( ckcel >  91 ) ) continue;
0087     if ( ( ckwhe == -1 ) &&
0088          ( cksec ==  3 ) &&
0089          ( ckqua ==  2 ) &&
0090          ( ckcel >  48 ) ) continue;
0091     if ( ( ckwhe ==  1 ) &&
0092          ( cksec ==  4 ) &&
0093          ( ckqua ==  2 ) &&
0094          ( ckcel >  48 ) ) continue;
0095 */
0096     ro->readOutToGeometry(ckddu, ckros, ckrob, cktdc, ckcha, whe, sta, sec, qua, lay, cel);
0097     if ((ckwhe != whe) || (cksta != sta) || (cksec != sec) || (ckqua != qua) || (cklay != lay) || (ckcel != cel))
0098       logFile << "MISMATCH IN WRITING AND READING chan->cell map " << ckddu << " " << ckros << " " << ckrob << " "
0099               << cktdc << " " << ckcha << " : " << ckwhe << " " << cksta << " " << cksec << " " << ckqua << " " << cklay
0100               << " " << ckcel << " -> " << whe << " " << sta << " " << sec << " " << qua << " " << lay << " " << cel
0101               << std::endl;
0102     ro->geometryToReadOut(ckwhe, cksta, cksec, ckqua, cklay, ckcel, ddu, ros, rob, tdc, cha);
0103     if ((ckddu != ddu) || (ckros != ros) || (ckrob != rob) || (cktdc != tdc) || (ckcha != cha))
0104       logFile << "MISMATCH IN WRITING AND READING cell->chan map " << ckwhe << " " << cksta << " " << cksec << " "
0105               << ckqua << " " << cklay << " " << ckcel << " : " << ckddu << " " << ckros << " " << ckrob << " " << cktdc
0106               << " " << ckcha << " -> " << ddu << " " << ros << " " << rob << " " << tdc << " " << cha << std::endl;
0107   }
0108 }
0109 
0110 void DTCompMapValidateDBRead::endJob() {
0111   std::ifstream logFile(elogFileName.c_str());
0112   char* line = new char[1000];
0113   int errors = 0;
0114   std::cout << "ReadOut Map validation result:" << std::endl;
0115   while (logFile.getline(line, 1000)) {
0116     std::cout << line << std::endl;
0117     errors++;
0118   }
0119   if (!errors) {
0120     std::cout << " ********************************* " << std::endl;
0121     std::cout << " ***                           *** " << std::endl;
0122     std::cout << " ***      NO ERRORS FOUND      *** " << std::endl;
0123     std::cout << " ***                           *** " << std::endl;
0124     std::cout << " ********************************* " << std::endl;
0125   }
0126   return;
0127 }
0128 
0129 DEFINE_FWK_MODULE(DTCompMapValidateDBRead);