CMS 3D CMS Logo

DTMapGenerator.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author G. Cerminara, S. Bolognesi - INFN Torino
5  */
6 
8 
9 #include "DTMapGenerator.h"
10 
11 #include <iostream>
12 #include <fstream>
13 #include <sstream>
14 
15 using namespace edm;
16 using namespace std;
17 
19  // The output file with the map
20  outputMapName = pset.getUntrackedParameter<string>("outputFileName", "output.map");
21  // The input file with the base map (DDU ROS -> Wheel, Station, Sector)
22  inputMapName = pset.getUntrackedParameter<string>("inputFileName", "basemap.txt");
23  //The ros type: ROS8 for commissioning, ROS25 otherwise
24  rosType = pset.getUntrackedParameter<int>("rosType", 25);
25  if (rosType != 8 && rosType != 25) {
26  cout << "[DTMapGenerator]: wrong ros type (8 for commissioning, 25 otherwise)" << endl;
27  abort();
28  }
29 }
30 
32  cout << "DTMapGenerator: Output Map: " << outputMapName << " ROS Type: " << rosType << endl;
33 
34  // Read the existing wires
35  ifstream existingChannels("/afs/cern.ch/cms/Physics/muon/CMSSW/DT/channelsMaps/existing_channels.txt");
36 
37  set<DTWireId> wireMap; //FIXME:MAYBE YOU NEED THE > and == operators to use set?
38 
39  // Read the map between DDU - ROS and Chambers
40  string lineMap;
41  while (getline(existingChannels, lineMap)) {
42  if (lineMap.empty() || lineMap[0] == '#')
43  continue; // Skip comments and empty lines
44  stringstream linestr;
45  linestr << lineMap;
46  int wheelEx, stationEx, sectorEx, slEx, layerEx, wireEx;
47  linestr >> wheelEx >> sectorEx >> stationEx >> slEx >> layerEx >> wireEx;
48  DTWireId wireIdEx(wheelEx, stationEx, sectorEx, slEx, layerEx, wireEx);
49  wireMap.insert(wireIdEx);
50  }
51  cout << "Map size: " << wireMap.size() << endl;
52 
53  // The map between DDU - ROS and Chambers
54  ifstream skeletonMap(inputMapName.c_str());
55 
56  // The output map in the CMSSW format
57  ofstream outputMap(outputMapName.c_str());
58 
59  // Read the map between DDU - ROS and Chambers
60  string line;
61  while (getline(skeletonMap, line)) {
62  if (line.empty() || line[0] == '#')
63  continue; // Skip comments and empty lines
64  stringstream linestr;
65  linestr << line;
66  int ddu, ros, wheel, station, sector;
67  linestr >> ddu >> ros >> wheel >> station >> sector;
68  cout << "DDU: " << ddu << endl
69  << "ROS: " << ros << endl
70  << "Connected to chamber in Wh: " << wheel << " St: " << station << " Sec: " << sector << endl;
71 
72  int previousROB = -1;
73  int robCounter = -1;
74  // The chamber map in ORCA commissioning format
75  string fileName;
76  stringstream nameTmp;
77  nameTmp << "/afs/cern.ch/cms/Physics/muon/CMSSW/DT/channelsMaps/templates/MB" << station << "_" << sector << ".map";
78  nameTmp >> fileName;
79  ifstream chamberMap(fileName.c_str());
80 
81  string lineChamberMap;
82  while (getline(chamberMap, lineChamberMap)) {
83  if (lineChamberMap.empty() || lineChamberMap[0] == '#')
84  continue; // Skip comments and empty lines
85  stringstream chamberMapStr;
86  chamberMapStr << lineChamberMap;
87 
88  int rob, tdc, tdcChannel, sl, layer, wire;
89  int unusedRos, unusedChamberCode;
90  int outRob = -1;
91  chamberMapStr >> unusedRos >> rob >> tdc >> tdcChannel >> unusedChamberCode >> sl >> layer >> wire;
92 
93  // Check if the channel really exists
94  if (!checkWireExist(wireMap, wheel, station, sector, sl, layer, wire))
95  continue;
96 
97  if (rob > previousROB) {
98  previousROB = rob;
99  robCounter++;
100  } else if (rob < previousROB) {
101  cout << "Error: ROB number is not uniformly increasing!" << endl;
102  abort();
103  }
104  // Set the ROB id within the ros
105  if (rosType == 25) {
106  if (station == 1) { //MB1
107  outRob = robCounter;
108  } else if (station == 2) { //MB2
109  outRob = robCounter + 6;
110  } else if (station == 3) { //MB3
111  if (robCounter < 3)
112  outRob = robCounter + 12;
113  else if (robCounter == 3)
114  outRob = 24;
115  else if (robCounter > 3)
116  outRob = robCounter + 11;
117  } else if (station == 4) { //MB4
118  if (sector == 14) {
119  if (robCounter == 3) {
120  continue;
121  }
122  outRob = robCounter + 18;
123  } else if (sector == 10) {
124  if (robCounter == 3) {
125  continue;
126  } else if (robCounter == 0) {
127  outRob = 21;
128  } else {
129  outRob = robCounter + 21;
130  }
131  } else if (sector == 4) {
132  if (robCounter == 3 || robCounter == 4) {
133  continue;
134  }
135  outRob = robCounter + 18;
136  } else if (sector == 13) {
137  if (robCounter == 3 || robCounter == 4) {
138  continue;
139  } else if (robCounter == 0) {
140  outRob = 21;
141  } else {
142  outRob = robCounter + 21;
143  }
144  } else if (sector == 11 || sector == 9) {
145  outRob = robCounter + 18;
146  if (robCounter == 3) {
147  continue;
148  }
149  }
150  //else if(sector==12 || sector == 8 || sector == 7 || sector == 6 || sector == 5 || sector == 3 || sector == 2 ||sector == 1 ){
151  else {
152  outRob = robCounter + 18;
153  }
154  }
155  } else {
156  outRob = rob;
157  }
158  outputMap << ddu << " " << ros << " " << outRob << " " << tdc << " " << tdcChannel << " " << wheel << " "
159  << station << " " << sector << " " << sl << " " << layer << " " << wire << endl;
160  }
161  }
162 }
163 
165  const set<DTWireId>& wireMap, int wheel, int station, int sector, int sl, int layer, int wire) {
166  DTWireId wireId(wheel, station, sector, sl, layer, wire);
167  if (wireMap.find(wireId) == wireMap.end()) {
168  cout << "Skipping channel: Wh: " << wheel << ", st: " << station << ", sec: " << sector << ", sl: " << sl
169  << ", lay: " << layer << ", wire: " << wire << endl;
170  return false;
171  }
172 
173  return true;
174 }
void endJob() override
DTMapGenerator(const edm::ParameterSet &pset)
Constructor.
bool checkWireExist(const std::set< DTWireId > &wireMap, int wheel, int station, int sector, int sl, int layer, int wire)
constexpr std::array< uint8_t, layerIndexSize > layer
HLT enums.