Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:08

0001 // -*- C++ -*-
0002 //
0003 // Package:    MapTester
0004 // Class:      MapTester
0005 //
0006 /**\class MapTester MapTester.cc UserCode/MapTester/src/MapTester.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jared Todd Sturdy
0015 //         Created:  Thu Oct 23 18:16:33 CEST 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <string>
0022 #include <iostream>
0023 #include <fstream>
0024 #include <sstream>
0025 
0026 // user include files
0027 #include "FWCore/Framework/interface/Frameworkfwd.h"
0028 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0029 
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 #include "CondFormats/HcalObjects/interface/HcalLogicalMap.h"
0035 #include "CalibCalorimetry/HcalAlgos/interface/HcalLogicalMapGenerator.h"
0036 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
0037 
0038 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0039 //
0040 // class decleration
0041 //
0042 
0043 class MapTester : public edm::one::EDAnalyzer<> {
0044 public:
0045   explicit MapTester(const edm::ParameterSet&);
0046   ~MapTester() override = default;
0047 
0048 private:
0049   unsigned int mapIOV_;  //1 for first set, 2 for second, ...
0050   bool generateTextfiles_;
0051   bool generateEmap_;
0052 
0053   void analyze(const edm::Event&, const edm::EventSetup&) override;
0054 
0055   // ----------member data ---------------------------
0056   const edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_topo_;
0057 };
0058 
0059 MapTester::MapTester(const edm::ParameterSet& iConfig) : tok_topo_(esConsumes<HcalTopology, HcalRecNumberingRecord>()) {
0060   mapIOV_ = iConfig.getParameter<unsigned int>("mapIOV");
0061   generateTextfiles_ = iConfig.getParameter<bool>("generateTextfiles");
0062   generateEmap_ = iConfig.getParameter<bool>("generateEmap");
0063 }
0064 
0065 // ------------ method called to for each event  ------------
0066 void MapTester::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0067   char tempbuff[128];
0068 
0069   time_t myTime;
0070   time(&myTime);
0071 
0072   strftime(tempbuff, 128, "%d.%b.%Y", localtime(&myTime));
0073 
0074   const HcalTopology* topo = &iSetup.getData(tok_topo_);
0075 
0076   HcalLogicalMapGenerator mygen;
0077   HcalLogicalMap mymap = mygen.createMap(topo, mapIOV_);
0078 
0079   if (generateTextfiles_)
0080     mymap.printMap(mapIOV_);
0081 
0082   mymap.checkIdFunctions();
0083   mymap.checkHashIds();
0084   mymap.checkElectronicsHashIds();
0085 
0086   if (generateEmap_) {
0087     std::ostringstream file;
0088     if (mapIOV_ == 1)
0089       file << "version_A_emap.txt";
0090     else if (mapIOV_ == 2)
0091       file << "version_B_emap.txt";
0092     else if (mapIOV_ == 3)
0093       file << "version_C_emap.txt";
0094     else if (mapIOV_ == 4)
0095       file << "version_D_emap.txt";
0096     else
0097       file << "version_E_emap.txt";
0098 
0099     std::ofstream outStream(file.str().c_str());
0100     char buf[1024];
0101     sprintf(buf, "#file creation series : %s", tempbuff);
0102     outStream << buf << std::endl;
0103 
0104     edm::LogInfo("MapTester") << "generating the emap..." << std::endl;
0105     auto myemap = mymap.generateHcalElectronicsMap();
0106     edm::LogInfo("MapTester") << "dumping the emap..." << std::endl;
0107     HcalDbASCIIIO::dumpObject(outStream, *myemap);
0108   }
0109 }
0110 
0111 //define this as a plug-in
0112 DEFINE_FWK_MODULE(MapTester);