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 
34 
35  cout << "DTMapGenerator: Output Map: " << outputMapName << " ROS Type: " << rosType << endl;
36 
37  // Read the existing wires
38  ifstream existingChannels("/afs/cern.ch/cms/Physics/muon/CMSSW/DT/channelsMaps/existing_channels.txt");
39 
40  set<DTWireId> wireMap; //FIXME:MAYBE YOU NEED THE > and == operators to use set?
41 
42  // Read the map between DDU - ROS and Chambers
43  string lineMap;
44  while (getline(existingChannels,lineMap)) {
45  if( lineMap == "" || lineMap[0] == '#' ) continue; // Skip comments and empty lines
46  stringstream linestr;
47  linestr << lineMap;
48  int wheelEx, stationEx, sectorEx, slEx, layerEx, wireEx;
49  linestr >> wheelEx >> sectorEx >> stationEx >> slEx >> layerEx >> wireEx;
50  DTWireId wireIdEx(wheelEx, stationEx, sectorEx, slEx, layerEx, wireEx);
51  wireMap.insert(wireIdEx);
52  }
53  cout << "Map size: " << wireMap.size() << endl;
54 
55  // The map between DDU - ROS and Chambers
56  ifstream skeletonMap(inputMapName.c_str());
57 
58  // The output map in the CMSSW format
59  ofstream outputMap(outputMapName.c_str());
60 
61  // Read the map between DDU - ROS and Chambers
62  string line;
63  while (getline(skeletonMap,line)) {
64  if( line == "" || line[0] == '#' ) continue; // Skip comments and empty lines
65  stringstream linestr;
66  linestr << line;
67  int ddu, ros, wheel, station, sector;
68  linestr >> ddu >> ros >> wheel >> station >> sector;
69  cout << "DDU: " << ddu << endl
70  << "ROS: " << ros << endl
71  << "Connected to chamber in Wh: " << wheel << " St: " << station << " Sec: " << sector << endl;
72 
73  int previousROB = -1;
74  int robCounter = -1;
75  // The chamber map in ORCA commissioning format
76  string fileName;
77  stringstream nameTmp;
78  nameTmp << "/afs/cern.ch/cms/Physics/muon/CMSSW/DT/channelsMaps/templates/MB" << station << "_" << sector << ".map";
79  nameTmp >> fileName;
80  ifstream chamberMap(fileName.c_str());
81 
82  string lineChamberMap;
83  while (getline(chamberMap,lineChamberMap)) {
84  if( lineChamberMap == "" || lineChamberMap[0] == '#' ) 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  }
132  if(sector == 4 ) {
133  if(robCounter == 3 || robCounter == 4 ) {
134  continue;
135  }
136  outRob = robCounter + 18;
137  } else if(sector == 13) {
138  if(robCounter == 3 || robCounter == 4) {
139  continue;
140  } else if(robCounter == 0) {
141  outRob = 21;
142  } else {
143  outRob = robCounter + 21;
144  }
145  } else if(sector == 11 || sector == 9) {
146  outRob = robCounter + 18;
147  if(robCounter == 3) {
148  continue;
149  }
150  }
151  //else if(sector==12 || sector == 8 || sector == 7 || sector == 6 || sector == 5 || sector == 3 || sector == 2 ||sector == 1 ){
152  else{
153  outRob = robCounter + 18;
154  }
155  }
156  } else {
157  outRob = rob;
158  }
159  outputMap << ddu << " "
160  << ros << " "
161  << outRob << " "
162  << tdc << " "
163  << tdcChannel << " "
164  << wheel << " "
165  << station << " "
166  << sector << " "
167  << sl << " "
168  << layer << " "
169  << wire << endl;
170  }
171  }
172 }
173 
174 bool DTMapGenerator::checkWireExist(const set<DTWireId>& wireMap, int wheel, int station, int sector, int sl, int layer, int wire) {
175  DTWireId wireId(wheel, station, sector, sl, layer, wire);
176  if(wireMap.find(wireId) == wireMap.end()) {
177  cout << "Skipping channel: Wh: " << wheel
178  << ", st: " << station
179  << ", sec: " << sector
180  << ", sl: " << sl
181  << ", lay: " << layer
182  << ", wire: " << wire << endl;
183  return false;
184  }
185 
186  return true;
187 }
188 
189 
void endJob() override
T getUntrackedParameter(std::string const &, T const &) const
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)
HLT enums.
~DTMapGenerator() override
Destructor.