Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:49

0001 //G.Benelli Aug 26 2010
0002 //Plugin adapted from Andrea Venturi's myTkAnalyses/PSTools to create Voltage (LV/HV) ON/OFF Tracke maps in the context of Strip DCS O2O.
0003 
0004 // system include files
0005 #include <memory>
0006 
0007 // user include files
0008 
0009 #include <iostream>
0010 #include <fstream>
0011 #include <string>
0012 
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0015 
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 
0023 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0024 
0025 #include "DQM/SiStripCommon/interface/TkHistoMap.h"
0026 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0027 
0028 //
0029 // class decleration
0030 //
0031 
0032 class TkVoltageMapCreator : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0033 public:
0034   explicit TkVoltageMapCreator(const edm::ParameterSet&);
0035   ~TkVoltageMapCreator() override;
0036 
0037 private:
0038   void beginJob() override;
0039   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0040   void endRun(const edm::Run&, const edm::EventSetup&) override;
0041   void analyze(const edm::Event&, const edm::EventSetup&) override;
0042   void endJob() override;
0043 
0044   // ----------member data ---------------------------
0045 
0046   const std::string _lvfile;
0047   const std::string _lvtkmapname;
0048   const std::string _hvfile;
0049   const std::string _hvtkmapname;
0050 
0051   edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tkDetMapToken_;
0052 };
0053 
0054 //
0055 // constants, enums and typedefs
0056 //
0057 
0058 //
0059 // static data member definitions
0060 //
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 TkVoltageMapCreator::TkVoltageMapCreator(const edm::ParameterSet& iConfig)
0066     : _lvfile(iConfig.getParameter<std::string>("LVStatusFile")),
0067       _lvtkmapname(iConfig.getParameter<std::string>("LVTkMapName")),
0068       _hvfile(iConfig.getParameter<std::string>("HVStatusFile")),
0069       _hvtkmapname(iConfig.getParameter<std::string>("HVTkMapName")),
0070       tkDetMapToken_(esConsumes<edm::Transition::BeginRun>())
0071 
0072 {
0073   //now do what ever initialization is needed
0074 }
0075 
0076 TkVoltageMapCreator::~TkVoltageMapCreator() = default;
0077 
0078 //
0079 // member functions
0080 //
0081 
0082 // ------------ method called to for each event  ------------
0083 void TkVoltageMapCreator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; }
0084 
0085 void TkVoltageMapCreator::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0086   const TkDetMap* tkDetMap = &iSetup.getData(tkDetMapToken_);
0087 
0088   TrackerMap lvmap, hvmap;
0089 
0090   TkHistoMap lvhisto(tkDetMap, "LV_Status", "LV_Status", -1);
0091   TkHistoMap hvhisto(tkDetMap, "HV_Status", "HV_Status", -1);
0092 
0093   std::ifstream lvdata(_lvfile.c_str());
0094   std::ifstream hvdata(_hvfile.c_str());
0095 
0096   // HV channel map filling
0097 
0098   unsigned int detid;
0099   std::string lvstatus;
0100 
0101   while (lvdata >> detid >> lvstatus) {
0102     double cha = 0.;
0103     if (lvstatus == "ON")
0104       cha = 0.5;  //GREEN
0105     if (lvstatus == "OFF")
0106       cha = 1.;  //RED
0107     lvhisto.fill(detid, cha);
0108   }
0109 
0110   std::string hvstatus;
0111 
0112   while (hvdata >> detid >> hvstatus) {
0113     double cha = 0.;
0114     if (hvstatus == "ON")
0115       cha = 0.5;  //GREEN
0116     if (hvstatus == "OFF")
0117       cha = 1.;  //RED
0118     hvhisto.fill(detid, cha);
0119   }
0120 
0121   lvmap.setPalette(1);
0122   hvmap.setPalette(1);
0123 
0124   lvhisto.dumpInTkMap(&lvmap);
0125   hvhisto.dumpInTkMap(&hvmap);
0126 
0127   lvmap.save(true, 0, 0, _lvtkmapname);
0128   hvmap.save(true, 0, 0, _hvtkmapname);
0129 
0130   //TODO could make the root file name a parameter to avoid overwriting everytime...
0131   std::string rootmapname = "VoltageStatus.root";
0132   lvhisto.save(rootmapname);
0133   hvhisto.save(rootmapname);
0134 }
0135 
0136 void TkVoltageMapCreator::endRun(const edm::Run& iRun, const edm::EventSetup&) {}
0137 
0138 // ------------ method called once each job just before starting event loop  ------------
0139 void TkVoltageMapCreator::beginJob() {}
0140 
0141 // ------------ method called once each job just after ending the event loop  ------------
0142 void TkVoltageMapCreator::endJob() {}
0143 
0144 //define this as a plug-in
0145 DEFINE_FWK_MODULE(TkVoltageMapCreator);