CMS 3D CMS Logo

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