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
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 row.topbottom = "b";
191  //
192  HcalGenericDetId _gid( emap->lookup(*eId) );
193  if ( !(_gid.null()) &&
194  (_gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
195  _gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap ||
196  _gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
197  _gid.genericSubdet()==HcalGenericDetId::HcalGenOuter
198  )
199  ){
200  HcalDetId _id( emap->lookup(*eId) );
201  row.rawId = _id.rawId();
202  row.ieta = _id.ieta();
203  row.iphi = _id.iphi();
204  row.idepth = _id.depth();
205  row.subdet = _ass.getSubdetectorString(_id.subdet());
206  // fill the map
207  map.push_back(row);
208  }
209  // ZDC channels
210  else if ( !(_gid.null()) &&
211  _gid.genericSubdet()==HcalGenericDetId::HcalGenZDC
212  ){
213  HcalZDCDetId _id( emap->lookup(*eId) );
214  row.zdc_channel = _id.channel();
215  row.zdc_section = _ass.getZDCSectionString(_id.section());
216  row.idepth = _id.depth();
217  row.zdc_zside = _id.zside();
218  // fill the map
219  map.push_back(row);
220  }
221  }
222  //
223  //_____ trigger channels __________________________________________
224  //
225  v_eId = emap->allElectronicsIdTrigger();
226  for (std::vector <HcalElectronicsId>::const_iterator eId=v_eId.begin();
227  eId!=v_eId.end();
228  eId++){
229  EMapRow row;
230  //row.rawId = eId->rawId();
231  row.crate = eId->readoutVMECrateId();
232  row.slot = eId->htrSlot();
233  row.dcc = eId->dccid();
234  row.spigot = eId->spigot();
235  row.fiber = eId->isVMEid() ? eId->slbSiteNumber() : eId->fiberIndex();
236  row.fiberchan = eId->isVMEid() ? eId->slbChannelIndex() : eId->fiberChanId();
237  if (eId->htrTopBottom()==1) row.topbottom = "t";
238  else row.topbottom = "b";
239  //
240  HcalTrigTowerDetId _id( emap->lookupTrigger(*eId) );
241  if ( !(_id.null()) ){
242  row.rawId = _id.rawId();
243  row.ieta = _id.ieta();
244  row.iphi = _id.iphi();
245  row.idepth = _id.depth();
246  row.subdet = _ass.getSubdetectorString(_id.subdet());
247  // fill the map
248  map.push_back(row);
249  }
250  }
251  }
252  else{
253  edm::LogError("EMap") << "Pointer to HcalElectronicsMap is 0!!!";
254  }
255 }
256 
257 
259 {
261 
262  std::string _row;
263  ifstream inFile( filename . c_str(), std::ios::in );
264  if (!inFile){
265  edm::LogError("EMap") << "Unable to open file with the electronic map: " << filename;
266  }
267  else{
268  edm::LogInfo("EMap") << "File with the electronic map opened successfully: " << filename;
269  }
270  while (getline( inFile, _row )) {
271  EMapRow aRow;
272  char fpga[32];
273  char subdet[32];
274 
275  int _read;
276  const char * _format = "%d %d %d %s %d %d %d %d %s %d %d %d";
277  _read = sscanf( _row . c_str(), _format,
278  &(aRow.rawId),
279  &(aRow.crate), &(aRow.slot),
280  fpga,
281  &(aRow.dcc),
282  &(aRow.spigot),&(aRow.fiber),&(aRow.fiberchan),
283  subdet,
284  &(aRow.ieta), &(aRow.iphi), &(aRow.idepth) );
285  if ( _read >= 12 ){
286  lines . count();
287 
288  aRow . subdet .append( subdet );
289  aRow . topbottom .append( fpga );
290 
291  map . push_back( aRow );
292  //std::cout << "DEBUG: " << _row << std::endl;
293  //std::cout << "DEBUG: " << aRow.ieta << std::endl;
294  }
295  }
296  inFile.close();
297  edm::LogInfo("EMap") << lines . getCount() << " lines read";
298 
299  return 0;
300 }
301 
302 
303 
304 std::vector<EMap::EMapRow> & EMap::get_map( void )
305 {
306  return map;
307 }
308 
309 
310 bool EMap::EMapRow::operator<( const EMap::EMapRow & other) const{
311  return rawId < other.rawId;
312 }
313 
314 
315 
316 
317 // ===> test procedures for the EMap class
319 {
320  EMap map( filename );
321  return 0;
322 }
323 
324 // ===> test procedures for the LMap class
325 LMap_test::LMap_test() :_lmap(new LMap){ }
326 
328 {
329  _lmap -> read(accessor,type);
330  return 0;
331 }
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:258
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: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:327
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:310
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:325
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:49
tuple filename
Definition: lut2db_cfg.py:20
int rctcar
Definition: LMap.h:51
int test_read_map(std::string filename)
Definition: LMap.cc:318
std::vector< EMap::EMapRow > & get_map(void)
Definition: LMap.cc:304
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
std::vector< LMapRow > _table
Definition: LMap.cc:39
int rm
Definition: LMap.h:45