File indexing completed on 2024-04-06 11:58:20
0001 #ifndef _CSCBADWIRESCONDITIONS_H
0002 #define _CSCBADWIRESCONDITIONS_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/CSCBadWires.h"
0017 #include "CondFormats/DataRecord/interface/CSCBadWiresRcd.h"
0018 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0019
0020 class CSCBadWiresConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0021 public:
0022 CSCBadWiresConditions(const edm::ParameterSet &);
0023 ~CSCBadWiresConditions() override;
0024
0025 inline static CSCBadWires *prefillBadWires();
0026
0027 typedef std::unique_ptr<CSCBadWires> ReturnType;
0028
0029 ReturnType produceBadWires(const CSCBadWiresRcd &);
0030
0031 private:
0032
0033 void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0034 const edm::IOVSyncValue &,
0035 edm::ValidityInterval &) override;
0036 CSCBadWires *cndbBadWires;
0037 };
0038
0039 #include <fstream>
0040 #include <iostream>
0041 #include <vector>
0042
0043
0044 inline CSCBadWires *CSCBadWiresConditions::prefillBadWires() {
0045 CSCBadWires *cndbbadwires = new CSCBadWires();
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
0060 int new_nrlines1 = 0;
0061 int new_nrlines2 = 0;
0062
0063
0064
0065
0066 std::ifstream newdata1;
0067 std::ifstream newdata2;
0068
0069 newdata1.open("badwires1.dat", std::ios::in);
0070 if (!newdata1) {
0071 std::cerr << "Error: badwires1.dat -> no such file!" << std::endl;
0072 exit(1);
0073 }
0074 newdata2.open("badwires2.dat", std::ios::in);
0075 if (!newdata2) {
0076 std::cerr << "Error: badwires2.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 CSCBadWires::BadChamberContainer &itemvector1 = cndbbadwires->chambers;
0101 itemvector1.resize(new_nrlines1);
0102
0103 CSCBadWires::BadChannelContainer &itemvector2 = cndbbadwires->channels;
0104 itemvector2.resize(new_nrlines2);
0105
0106 cndbbadwires->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 cndbbadwires;
0123 }
0124
0125 #endif