CMS 3D CMS Logo

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