Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:32

0001 #ifndef _CSCBADCHAMBERSCONDITIONS_H
0002 #define _CSCBADCHAMBERSCONDITIONS_H
0003 
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/ESProducer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/SourceFactory.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include <cmath>
0014 #include <memory>
0015 
0016 #include "CondFormats/CSCObjects/interface/CSCBadChambers.h"
0017 #include "CondFormats/DataRecord/interface/CSCBadChambersRcd.h"
0018 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0019 
0020 class CSCBadChambersConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0021 public:
0022   CSCBadChambersConditions(const edm::ParameterSet &);
0023   ~CSCBadChambersConditions() override;
0024 
0025   inline static CSCBadChambers *prefillBadChambers();
0026 
0027   typedef std::unique_ptr<CSCBadChambers> ReturnType;
0028 
0029   ReturnType produceBadChambers(const CSCBadChambersRcd &);
0030 
0031 private:
0032   // ----------member data ---------------------------
0033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0034                       const edm::IOVSyncValue &,
0035                       edm::ValidityInterval &) override;
0036   CSCBadChambers *cndbBadChambers;
0037 };
0038 
0039 #include <fstream>
0040 #include <iostream>
0041 #include <vector>
0042 
0043 // to workaround plugin library
0044 inline CSCBadChambers *CSCBadChambersConditions::prefillBadChambers() {
0045   //  const int MAX_SIZE = 468;
0046   // cndbbadchambers = new CSCBadChambers();
0047 
0048   int new_chambers;
0049   std::vector<int> new_badchambers;
0050   int old_chamber = -1;
0051   int new_nrlines;
0052   new_nrlines = 0;
0053 
0054   std::ifstream newdata;
0055 
0056   newdata.open("badchambers.dat", std::ios::in);
0057   if (!newdata) {
0058     std::cerr << "Error: badchambers.dat -> no such file!" << std::endl;
0059     exit(1);
0060   }
0061 
0062   while (!newdata.eof()) {
0063     newdata >> new_chambers;
0064     if (new_chambers != old_chamber) {
0065       new_badchambers.push_back(new_chambers);
0066       std::cout << new_chambers << std::endl;
0067       ++new_nrlines;
0068     }
0069     old_chamber = new_chambers;
0070   }
0071   newdata.close();
0072 
0073   CSCBadChambers *cndbbadchambers = new CSCBadChambers(new_nrlines, new_badchambers);
0074 
0075   // std::cout <<"numberOfBadChambers "<<new_nrlines<<std::endl;
0076 
0077   return cndbbadchambers;
0078 }
0079 
0080 #endif