CMS 3D CMS Logo

LMap.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: XMLTools
4 // Class : LMap
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Gena Kukartsev, kukarzev@fnal.gov
10 // Created: Tue Oct 23 14:30:20 CDT 2007
11 //
12 
13 // system include files
14 #include <cstdio>
15 #include <iostream>
16 #include <fstream>
17 #include <sstream>
18 #include <vector>
19 
20 
21 // user include files
28 
29 using namespace std;
30 
31 
32 
33 class LMap::impl {
34 public:
35  impl(){ }
36  ~impl(){ }
37 
38  int read( std::string accessor, std::string type );
39  std::map<int,LMapRow> & get_map( void ){ return _lmap; };
40 
41 private:
42  std::vector<LMapRow> _table;
43  std::map<int,LMapRow> _lmap;
44 
45 };
46 
47 
48 
49 LMap::LMap() : p_impl( new impl ) { }
50 
52 
53 
54 
56 {
57  return p_impl -> read( accessor, type );
58 }
59 
60 std::map<int,LMapRow> & LMap::get_map( void )
61 {
62  return p_impl -> get_map();
63 }
64 
66 {
67 
69 
70  std::string _row;
71  ifstream inFile( map_file . c_str(), std::ios::in );
72  if (!inFile)
73  {
74  edm::LogError("LMap") << "Unable to open file with the logical map: " << map_file;
75  }
76  else
77  {
78  edm::LogInfo("LMap") << "File with the logical map opened successfully: " << map_file << std::endl
79  << "Type: " << type;
80  }
81  while (getline( inFile, _row ))
82  {
83  LMapRow aRow;
84  char det[32];
85  char rbx[32];
86  char fpga[32];
87  char slbin[32];
88  char slbin2[32];
89  char slnam[32];
90  char rctnam[32];
91 
92  const char * let_code = "Z";
93 
94  int _read = 0;
95  if ( type == "HBEF" )
96  {
97  const char * _format = " %d %d %d %d %d %s %s %d %d %d %d %d %d %d %d %d %s %d %d %d %d %d %s %s %s %d %d %d %s %d";
98  _read = sscanf( _row . c_str(), _format,
99  &(aRow.side),
100  &(aRow.eta), &(aRow.phi), &(aRow.dphi), &(aRow.depth),
101  det,
102  rbx,
103  &(aRow.wedge), &(aRow.rm), &(aRow.pixel), &(aRow.qie), &(aRow.adc), &(aRow.rm_fi), &(aRow.fi_ch),
104  &(aRow.crate), &(aRow.htr),
105  fpga,
106  &(aRow.htr_fi),
107  &(aRow.dcc_sl), &(aRow.spigo), &(aRow.dcc), &(aRow.slb),
108  slbin, slbin2, slnam,
109  &(aRow.rctcra), &(aRow.rctcar), &(aRow.rctcon),
110  rctnam,
111  &(aRow.fedid) );
112  }
113  else if ( type == "HO" )
114  {
115  const char * _format = " %d %d %d %d %d %s %s %d %d %d %d %d %d %d %s %d %d %s %d %d %d %d %d";
116  _read = sscanf( _row . c_str(), _format,
117  &(aRow.side),
118  &(aRow.eta), &(aRow.phi), &(aRow.dphi), &(aRow.depth),
119  det,
120  rbx,
121  &(aRow.wedge), &(aRow.rm), &(aRow.pixel), &(aRow.qie), &(aRow.adc), &(aRow.rm_fi), &(aRow.fi_ch),
122  &let_code,
123  &(aRow.crate), &(aRow.htr),
124  fpga,
125  &(aRow.htr_fi),
126  &(aRow.dcc_sl), &(aRow.spigo), &(aRow.dcc), &(aRow.slb) );
127  //slbin, slbin2, slnam,
128  //&(aRow.rctcra), &(aRow.rctcar), &(aRow.rctcon),
129  //rctnam,
130  //&(aRow.fedid) );
131  }
132  if ( _read >= 23 )
133  {
134  lines . count();
135 
136  std::string _det(det);
137  if ( _det.find("HB") != std::string::npos ) aRow . det = HcalBarrel;
138  else if ( _det.find("HE") != std::string::npos ) aRow . det = HcalEndcap;
139  else if ( _det.find("HF") != std::string::npos ) aRow . det = HcalForward;
140  else if ( _det.find("HO") != std::string::npos ) aRow . det = HcalOuter;
141  else aRow . det = HcalOther;
142 
143  aRow . rbx .append( rbx );
144  aRow . fpga .append( fpga );
145  aRow . slbin .append( slbin );
146  aRow . slbin2 .append( slbin2 );
147  aRow . slnam .append( slnam );
148  aRow . rctnam .append( rctnam );
149  aRow . let_code .append( let_code );
150 
151  _table . push_back( aRow );
152 
153  HcalDetId _hdid(aRow.det, aRow.side*aRow.eta, aRow.phi, aRow.depth);
154 
155  _lmap[_hdid.rawId()] = aRow;
156 
157  }
158  }
159  inFile.close();
160  edm::LogInfo("LMap") << lines . getCount() << " lines read";
161 
162  return 0;
163 }
164 
165 //_______________________________________________________________________
166 //
167 //_____ EMAP stuff
168 //
169 //_______________________________________________________________________
170 
172  if (emap){
173  HcalAssistant _ass;
174  //
175  //_____ precision channels __________________________________________
176  //
177  std::vector <HcalElectronicsId> v_eId = emap->allElectronicsIdPrecision();
178  for (std::vector <HcalElectronicsId>::const_iterator eId=v_eId.begin();
179  eId!=v_eId.end();
180  eId++){
181  EMapRow row;
182  //row.rawId = eId->rawId();
183  row.crate = eId->readoutVMECrateId();
184  row.slot = eId->htrSlot();
185  row.dcc = eId->dccid();
186  row.spigot = eId->spigot();
187  row.fiber = eId->fiberIndex();
188  row.fiberchan = eId->fiberChanId();
189  if (eId->htrTopBottom()==1) row.topbottom = "t";
190  else if (eId->htrTopBottom()==0) row.topbottom = "b";
191  else row.topbottom = "u";
192  //
193  HcalGenericDetId _gid( emap->lookup(*eId) );
194  if ( !(_gid.null()) &&
195  (_gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
196  _gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap ||
197  _gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
198  _gid.genericSubdet()==HcalGenericDetId::HcalGenOuter
199  )
200  ){
201  HcalDetId _id( emap->lookup(*eId) );
202  row.rawId = _id.rawId();
203  row.ieta = _id.ieta();
204  row.iphi = _id.iphi();
205  row.idepth = _id.depth();
206  row.subdet = _ass.getSubdetectorString(_id.subdet());
207  // fill the map
208  map.push_back(row);
209  }
210  // ZDC channels
211  else if ( !(_gid.null()) &&
212  _gid.genericSubdet()==HcalGenericDetId::HcalGenZDC
213  ){
214  HcalZDCDetId _id( emap->lookup(*eId) );
215  row.zdc_channel = _id.channel();
216  row.zdc_section = _ass.getZDCSectionString(_id.section());
217  row.idepth = _id.depth();
218  row.zdc_zside = _id.zside();
219  // fill the map
220  map.push_back(row);
221  }
222  }
223  //
224  //_____ trigger channels __________________________________________
225  //
226  v_eId = emap->allElectronicsIdTrigger();
227  for (std::vector <HcalElectronicsId>::const_iterator eId=v_eId.begin();
228  eId!=v_eId.end();
229  eId++){
230  EMapRow row;
231  //row.rawId = eId->rawId();
232  row.crate = eId->readoutVMECrateId();
233  row.slot = eId->htrSlot();
234  row.dcc = eId->dccid();
235  row.spigot = eId->spigot();
236  row.fiber = eId->isVMEid() ? eId->slbSiteNumber() : eId->fiberIndex();
237  row.fiberchan = eId->isVMEid() ? eId->slbChannelIndex() : eId->fiberChanId();
238  if (eId->htrTopBottom()==1) row.topbottom = "t";
239  else if (eId->htrTopBottom()==0) row.topbottom = "b";
240  else row.topbottom = "u";
241  //
242  HcalTrigTowerDetId _id( emap->lookupTrigger(*eId) );
243  if ( !(_id.null()) ){
244  row.rawId = _id.rawId();
245  row.ieta = _id.ieta();
246  row.iphi = _id.iphi();
247  row.idepth = _id.depth();
248  row.subdet = _ass.getSubdetectorString(_id.subdet());
249  // fill the map
250  map.push_back(row);
251  }
252  }
253  }
254  else{
255  edm::LogError("EMap") << "Pointer to HcalElectronicsMap is 0!!!";
256  }
257 }
258 
259 
261 {
263 
264  std::string _row;
265  ifstream inFile( filename . c_str(), std::ios::in );
266  if (!inFile){
267  edm::LogError("EMap") << "Unable to open file with the electronic map: " << filename;
268  }
269  else{
270  edm::LogInfo("EMap") << "File with the electronic map opened successfully: " << filename;
271  }
272  while (getline( inFile, _row )) {
273  EMapRow aRow;
274  char fpga[32];
275  char subdet[32];
276 
277  int _read;
278  const char * _format = "%d %d %d %s %d %d %d %d %s %d %d %d";
279  _read = sscanf( _row . c_str(), _format,
280  &(aRow.rawId),
281  &(aRow.crate), &(aRow.slot),
282  fpga,
283  &(aRow.dcc),
284  &(aRow.spigot),&(aRow.fiber),&(aRow.fiberchan),
285  subdet,
286  &(aRow.ieta), &(aRow.iphi), &(aRow.idepth) );
287  if ( _read >= 12 ){
288  lines . count();
289 
290  aRow . subdet .append( subdet );
291  aRow . topbottom .append( fpga );
292 
293  map . push_back( aRow );
294  //std::cout << "DEBUG: " << _row << std::endl;
295  //std::cout << "DEBUG: " << aRow.ieta << std::endl;
296  }
297  }
298  inFile.close();
299  edm::LogInfo("EMap") << lines . getCount() << " lines read";
300 
301  return 0;
302 }
303 
304 
305 
306 std::vector<EMap::EMapRow> & EMap::get_map( void )
307 {
308  return map;
309 }
310 
311 
313  return rawId < other.rawId;
314 }
315 
316 
317 
318 
319 // ===> test procedures for the EMap class
321 {
322  EMap map( filename );
323  return 0;
324 }
325 
326 // ===> test procedures for the LMap class
327 LMap_test::LMap_test() :_lmap(new LMap){ }
328 
330 {
331  _lmap -> read(accessor,type);
332  return 0;
333 }
type
Definition: HCALResponse.h:21
int slot
Definition: LMap.h:105
int rctcra
Definition: LMap.h:51
std::string getSubdetectorString(HcalSubdetector _det)
int read_map(std::string filename)
Definition: LMap.cc:260
int dphi
Definition: LMap.h:41
int zdc_channel
Definition: LMap.h:109
int phi
Definition: LMap.h:41
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
int pixel
Definition: LMap.h:45
~LMap()
Definition: LMap.cc:51
std::string zdc_section
Definition: LMap.h:110
int qie
Definition: LMap.h:45
int zdc_zside
Definition: LMap.h:109
int iphi
Definition: LMap.h:105
int fedid
Definition: LMap.h:53
int ieta
Definition: LMap.h:105
std::string getZDCSectionString(HcalZDCDetId::Section _section)
std::map< int, LMapRow > & get_map(void)
Definition: LMap.cc:39
int rawId
Definition: LMap.h:105
int fiber
Definition: LMap.h:105
int spigot
Definition: LMap.h:105
boost::shared_ptr< LMap > _lmap
Definition: LMap.h:152
int slb
Definition: LMap.h:49
int htr
Definition: LMap.h:46
std::string subdet
Definition: LMap.h:106
std::map< int, LMapRow > & get_map(void)
Definition: LMap.cc:60
int depth
Definition: LMap.h:41
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
int spigo
Definition: LMap.h:49
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
int test_read(std::string accessor, std::string type="HBEF")
Definition: LMap.cc:329
std::map< int, LMapRow > _lmap
Definition: LMap.cc:43
int dcc_sl
Definition: LMap.h:49
int fi_ch
Definition: LMap.h:45
int adc
Definition: LMap.h:45
int read(std::string accessor, std::string type="HBEF")
Definition: LMap.cc:55
impl()
Definition: LMap.cc:35
bool operator<(const EMapRow &other) const
Definition: LMap.cc:312
int crate
Definition: LMap.h:46
int read(std::string accessor, std::string type)
Definition: LMap.cc:65
boost::shared_ptr< impl > p_impl
Definition: LMap.h:88
int fiberchan
Definition: LMap.h:105
int dcc
Definition: LMap.h:105
int side
Definition: LMap.h:38
int crate
Definition: LMap.h:105
int rm_fi
Definition: LMap.h:45
LMap_test()
Definition: LMap.cc:327
int dcc
Definition: LMap.h:49
std::string topbottom
Definition: LMap.h:106
int wedge
Definition: LMap.h:45
if(dp >Float(M_PI)) dp-
int rctcon
Definition: LMap.h:51
LMap()
Definition: LMap.cc:49
int rctcar
Definition: LMap.h:51
int test_read_map(std::string filename)
Definition: LMap.cc:320
std::vector< EMap::EMapRow > & get_map(void)
Definition: LMap.cc:306
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Definition: LMap.h:94
int idepth
Definition: LMap.h:105
int htr_fi
Definition: LMap.h:48
HcalSubdetector det
Definition: LMap.h:43
Definition: LMap.h:34
~impl()
Definition: LMap.cc:36
Definition: LMap.h:75
EMap()
Definition: LMap.h:97
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
int eta
Definition: LMap.h:41
int rm
Definition: LMap.h:45