File indexing completed on 2024-04-06 11:58:25
0001
0002
0003
0004
0005
0006
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008
0009 #include "DTMapGenerator.h"
0010
0011 #include <iostream>
0012 #include <fstream>
0013 #include <sstream>
0014
0015 using namespace edm;
0016 using namespace std;
0017
0018 DTMapGenerator::DTMapGenerator(const ParameterSet& pset) {
0019
0020 outputMapName = pset.getUntrackedParameter<string>("outputFileName", "output.map");
0021
0022 inputMapName = pset.getUntrackedParameter<string>("inputFileName", "basemap.txt");
0023
0024 rosType = pset.getUntrackedParameter<int>("rosType", 25);
0025 if (rosType != 8 && rosType != 25) {
0026 cout << "[DTMapGenerator]: wrong ros type (8 for commissioning, 25 otherwise)" << endl;
0027 abort();
0028 }
0029 }
0030
0031 void DTMapGenerator::endJob() {
0032 cout << "DTMapGenerator: Output Map: " << outputMapName << " ROS Type: " << rosType << endl;
0033
0034
0035 ifstream existingChannels("/afs/cern.ch/cms/Physics/muon/CMSSW/DT/channelsMaps/existing_channels.txt");
0036
0037 set<DTWireId> wireMap;
0038
0039
0040 string lineMap;
0041 while (getline(existingChannels, lineMap)) {
0042 if (lineMap.empty() || lineMap[0] == '#')
0043 continue;
0044 stringstream linestr;
0045 linestr << lineMap;
0046 int wheelEx, stationEx, sectorEx, slEx, layerEx, wireEx;
0047 linestr >> wheelEx >> sectorEx >> stationEx >> slEx >> layerEx >> wireEx;
0048 DTWireId wireIdEx(wheelEx, stationEx, sectorEx, slEx, layerEx, wireEx);
0049 wireMap.insert(wireIdEx);
0050 }
0051 cout << "Map size: " << wireMap.size() << endl;
0052
0053
0054 ifstream skeletonMap(inputMapName.c_str());
0055
0056
0057 ofstream outputMap(outputMapName.c_str());
0058
0059
0060 string line;
0061 while (getline(skeletonMap, line)) {
0062 if (line.empty() || line[0] == '#')
0063 continue;
0064 stringstream linestr;
0065 linestr << line;
0066 int ddu, ros, wheel, station, sector;
0067 linestr >> ddu >> ros >> wheel >> station >> sector;
0068 cout << "DDU: " << ddu << endl
0069 << "ROS: " << ros << endl
0070 << "Connected to chamber in Wh: " << wheel << " St: " << station << " Sec: " << sector << endl;
0071
0072 int previousROB = -1;
0073 int robCounter = -1;
0074
0075 string fileName;
0076 stringstream nameTmp;
0077 nameTmp << "/afs/cern.ch/cms/Physics/muon/CMSSW/DT/channelsMaps/templates/MB" << station << "_" << sector << ".map";
0078 nameTmp >> fileName;
0079 ifstream chamberMap(fileName.c_str());
0080
0081 string lineChamberMap;
0082 while (getline(chamberMap, lineChamberMap)) {
0083 if (lineChamberMap.empty() || lineChamberMap[0] == '#')
0084 continue;
0085 stringstream chamberMapStr;
0086 chamberMapStr << lineChamberMap;
0087
0088 int rob, tdc, tdcChannel, sl, layer, wire;
0089 int unusedRos, unusedChamberCode;
0090 int outRob = -1;
0091 chamberMapStr >> unusedRos >> rob >> tdc >> tdcChannel >> unusedChamberCode >> sl >> layer >> wire;
0092
0093
0094 if (!checkWireExist(wireMap, wheel, station, sector, sl, layer, wire))
0095 continue;
0096
0097 if (rob > previousROB) {
0098 previousROB = rob;
0099 robCounter++;
0100 } else if (rob < previousROB) {
0101 cout << "Error: ROB number is not uniformly increasing!" << endl;
0102 abort();
0103 }
0104
0105 if (rosType == 25) {
0106 if (station == 1) {
0107 outRob = robCounter;
0108 } else if (station == 2) {
0109 outRob = robCounter + 6;
0110 } else if (station == 3) {
0111 if (robCounter < 3)
0112 outRob = robCounter + 12;
0113 else if (robCounter == 3)
0114 outRob = 24;
0115 else if (robCounter > 3)
0116 outRob = robCounter + 11;
0117 } else if (station == 4) {
0118 if (sector == 14) {
0119 if (robCounter == 3) {
0120 continue;
0121 }
0122 outRob = robCounter + 18;
0123 } else if (sector == 10) {
0124 if (robCounter == 3) {
0125 continue;
0126 } else if (robCounter == 0) {
0127 outRob = 21;
0128 } else {
0129 outRob = robCounter + 21;
0130 }
0131 } else if (sector == 4) {
0132 if (robCounter == 3 || robCounter == 4) {
0133 continue;
0134 }
0135 outRob = robCounter + 18;
0136 } else if (sector == 13) {
0137 if (robCounter == 3 || robCounter == 4) {
0138 continue;
0139 } else if (robCounter == 0) {
0140 outRob = 21;
0141 } else {
0142 outRob = robCounter + 21;
0143 }
0144 } else if (sector == 11 || sector == 9) {
0145 outRob = robCounter + 18;
0146 if (robCounter == 3) {
0147 continue;
0148 }
0149 }
0150
0151 else {
0152 outRob = robCounter + 18;
0153 }
0154 }
0155 } else {
0156 outRob = rob;
0157 }
0158 outputMap << ddu << " " << ros << " " << outRob << " " << tdc << " " << tdcChannel << " " << wheel << " "
0159 << station << " " << sector << " " << sl << " " << layer << " " << wire << endl;
0160 }
0161 }
0162 }
0163
0164 bool DTMapGenerator::checkWireExist(
0165 const set<DTWireId>& wireMap, int wheel, int station, int sector, int sl, int layer, int wire) {
0166 DTWireId wireId(wheel, station, sector, sl, layer, wire);
0167 if (wireMap.find(wireId) == wireMap.end()) {
0168 cout << "Skipping channel: Wh: " << wheel << ", st: " << station << ", sec: " << sector << ", sl: " << sl
0169 << ", lay: " << layer << ", wire: " << wire << endl;
0170 return false;
0171 }
0172
0173 return true;
0174 }