Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef _CSCBADSTRIPSCONDITIONS_H
0002 #define _CSCBADSTRIPSCONDITIONS_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/CSCBadStrips.h"
0017 #include "CondFormats/DataRecord/interface/CSCBadStripsRcd.h"
0018 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0019 
0020 class CSCBadStripsConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0021 public:
0022   CSCBadStripsConditions(const edm::ParameterSet &);
0023   ~CSCBadStripsConditions() override;
0024 
0025   inline static CSCBadStrips *prefillBadStrips();
0026 
0027   typedef std::unique_ptr<CSCBadStrips> ReturnType;
0028 
0029   ReturnType produceBadStrips(const CSCBadStripsRcd &);
0030 
0031 private:
0032   // ----------member data ---------------------------
0033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0034                       const edm::IOVSyncValue &,
0035                       edm::ValidityInterval &) override;
0036   CSCBadStrips *cndbBadStrips;
0037 };
0038 
0039 #include <fstream>
0040 #include <iostream>
0041 #include <vector>
0042 
0043 // to workaround plugin library
0044 inline CSCBadStrips *CSCBadStripsConditions::prefillBadStrips() {
0045   CSCBadStrips *cndbbadstrips = new CSCBadStrips();
0046 
0047   int new_index, new_chan;
0048   int new_layer, new_channel, new_flag1, new_flag2, new_flag3, new_pointer;
0049   std::vector<int> new_index_id;
0050   std::vector<short int> new_layer_id;
0051   std::vector<short int> new_chan_id;
0052   std::vector<int> new_badchannels;
0053   std::vector<short int> new_flag1_id;
0054   std::vector<short int> new_flag2_id;
0055   std::vector<short int> new_flag3_id;
0056   std::vector<int> new_cham_id;
0057   std::vector<int> new_point;
0058 
0059   // when bad channels exist use the following
0060   int new_nrlines1 = 0;
0061   int new_nrlines2 = 0;
0062   // when empty
0063   // int new_nrlines1=-1;
0064   // int new_nrlines2=-1;
0065 
0066   std::ifstream newdata1;
0067   std::ifstream newdata2;
0068 
0069   newdata1.open("badstrips1.dat", std::ios::in);  // chambercontainer
0070   if (!newdata1) {
0071     std::cerr << "Error: badstrips1.dat -> no such file!" << std::endl;
0072     exit(1);
0073   }
0074   newdata2.open("badstrips2.dat", std::ios::in);  // channelcontainer
0075   if (!newdata2) {
0076     std::cerr << "Error: badstrips2.dat -> no such file!" << std::endl;
0077     exit(1);
0078   }
0079 
0080   while (!newdata1.eof()) {
0081     newdata1 >> new_index >> new_pointer >> new_chan;
0082     new_index_id.push_back(new_index);
0083     new_point.push_back(new_pointer);
0084     new_badchannels.push_back(new_chan);
0085     new_nrlines1++;
0086   }
0087   newdata1.close();
0088 
0089   while (!newdata2.eof()) {
0090     newdata2 >> new_layer >> new_channel >> new_flag1 >> new_flag2 >> new_flag3;
0091     new_layer_id.push_back(new_layer);
0092     new_chan_id.push_back(new_channel);
0093     new_flag1_id.push_back(new_flag1);
0094     new_flag2_id.push_back(new_flag2);
0095     new_flag3_id.push_back(new_flag3);
0096     new_nrlines2++;
0097   }
0098   newdata2.close();
0099 
0100   CSCBadStrips::BadChamberContainer &itemvector1 = cndbbadstrips->chambers;
0101   itemvector1.resize(new_nrlines1);
0102 
0103   CSCBadStrips::BadChannelContainer &itemvector2 = cndbbadstrips->channels;
0104   itemvector2.resize(new_nrlines2);
0105 
0106   cndbbadstrips->numberOfBadChannels = new_nrlines2;
0107 
0108   for (int i = 0; i < new_nrlines1; i++) {
0109     itemvector1[i].chamber_index = new_index_id[i];
0110     itemvector1[i].pointer = new_point[i];
0111     itemvector1[i].bad_channels = new_badchannels[i];
0112   }
0113 
0114   for (int j = 0; j < new_nrlines2; j++) {
0115     itemvector2[j].layer = new_layer_id[j];
0116     itemvector2[j].channel = new_chan_id[j];
0117     itemvector2[j].flag1 = new_flag1_id[j];
0118     itemvector2[j].flag2 = new_flag2_id[j];
0119     itemvector2[j].flag3 = new_flag3_id[j];
0120   }
0121 
0122   return cndbbadstrips;
0123 }
0124 
0125 #endif