StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StETofHardwareMap.cxx
1 /***************************************************************************
2  *
3  * $Id: StETofHardwareMap.cxx,v 1.5 2021/05/12 16:30:45 weidenkaff Exp $
4  *
5  * Author: Pengfei Lyu, April 2018
6  ***************************************************************************
7  *
8  * Description: This class provides a mapping from the hardware address of
9  * the electroinc channels to the eTOF geometry, e.g. sector, z-plane,
10  * counter, strip, side
11  *
12  ***************************************************************************
13  *
14  * $Log: StETofHardwareMap.cxx,v $
15  * Revision 1.5 2021/05/12 16:30:45 weidenkaff
16  * adjusted mapping to fit with pattern mapping in digimaker
17  *
18  * Revision 1.4 2021/05/10 21:18:48 perev
19  * Fix add std::
20  *
21  * Revision 1.3 2019/02/19 20:15:21 fseck
22  * update to allow initialization from database
23  *
24  * Revision 1.2 2018/07/27 14:01:57 fseck
25  * small change to fix compiler warning
26  *
27  * Revision 1.1 2018/07/25 14:34:40 jeromel
28  * First version, reviewed Raghav+Jerome
29  *
30  *
31  **************************************************************************/
32 #include <fstream>
33 
34 #include "StETofHardwareMap.h"
35 #include "StMessMgr.h"
36 
37 #include "tables/St_etofElectronicsMap_Table.h"
38 
39 
40 StETofHardwareMap::StETofHardwareMap( St_etofElectronicsMap* etofElectronicsMap, unsigned int year )
41 {
42  mYear = year;
43 
44  mOrderedPlanes.push_back( 2 );
45  mOrderedPlanes.push_back( 1 );
46  mOrderedPlanes.push_back( 3 );
47 
48  init( etofElectronicsMap );
49 }
50 
51 StETofHardwareMap::StETofHardwareMap( std::string fileName, unsigned int year )
52 {
53  mYear = year;
54 
55  mOrderedPlanes.push_back( 2 );
56  mOrderedPlanes.push_back( 1 );
57  mOrderedPlanes.push_back( 3 );
58 
59  init( fileName );
60 }
61 
62 
63 StETofHardwareMap::~StETofHardwareMap()
64 {
65  /* no op */
66 }
67 
68 void
69 StETofHardwareMap::init( St_etofElectronicsMap* etofElectronicsMap )
70 {
71  LOG_INFO << "StETofHardwareMap -- initializing eTOF electronics to hardware mapping via database" << endm;
72 
73  // get database table
74  if( !etofElectronicsMap ) {
75  LOG_ERROR << "StETofHardwareMap -- unable to get the electronics map from the database" << endm;
76  return;
77  }
78 
79  etofElectronicsMap_st* table = etofElectronicsMap->GetTable();
80 
81  // log for debugging
82  LOG_DEBUG << "nAfcks: " << ( int ) table->nAfcks << endm;
83  LOG_DEBUG << "nChannels: " << table->nChannels << endm;
84 
85  for( size_t i=0; i<12; i++ ) {
86  LOG_DEBUG << "AFCK address: 0x" << std::hex << table->afckAddress[ i ] << std::dec << " --> sector: " << ( int ) table->sector[ i ] << endm;
87  }
88 
89  for( size_t i=0; i<576; i++ ) {
90  LOG_DEBUG << "channelNumber: " << table->channelNumber[ i ] << " --> geometryId: " << table->geometryId[ i ] << endm;
91  }
92 
93 
94  //fill the member variables with data
95  for( size_t i=0; i<12; i++ ) {
96  if( table->sector[ i ] != 0 ) {
97  mAfckToSector.push_back( table->sector[ i ] );
98  mAfckAddressMap[ table->afckAddress[ i ] ] = i;
99  }
100  }
101 
102  for( size_t i=0; i<576; i++ ) {
103  mChannelNumberMap[ table->channelNumber[ i ] ] = table->geometryId[ i ];
104  }
105 
106  LOG_INFO << "StETofHardwareMap -- initialization finished" << endm;
107 }
108 
109 
110 void
111 StETofHardwareMap::init( std::string fileName )
112 {
113  LOG_INFO << "StETofHardwareMap -- initializing eTOF electronics to hardware mapping via local parameter file" << endm;
114 
115  // get local parameter file
116  std::ifstream paramFile;
117 
118  if( fileName.empty() ) {
119  LOG_ERROR << "StETofHardwareMap -- local file name is empty" << endm;
120  return;
121  }
122  LOG_INFO << "StETofHardwareMap -- local file for electronics to hardware mapping: " << fileName << endm;
123 
124  paramFile.open( fileName.c_str() );
125 
126  if( !paramFile.is_open() ) {
127  LOG_ERROR << "StETofHardwareMap -- unable to get the parameters from local file --> file does not exist" << endm;
128  return;
129  }
130 
131  unsigned int nAfcks = 0;
132  unsigned int nChannels = 0;
133  std::vector< unsigned int > afckAddress;
134  std::vector< unsigned int > sector;
135  std::vector< unsigned int > channelNumber;
136  std::vector< unsigned int > geometryId;
137 
138 
139 
140  if( !paramFile.eof() ) {
141  paramFile >> nAfcks;
142  }
143  if( !paramFile.eof() ) {
144  paramFile >> nChannels;
145  }
146 
147  unsigned int temp;
148 
149  for( int i=0; i<12; i++ ) {
150  if( !paramFile.eof() ) {
151  paramFile >> std::hex >> temp;
152  afckAddress.push_back( temp );
153  }
154  }
155 
156  for( int i=0; i<12; i++ ) {
157  if( !paramFile.eof() ) {
158  paramFile >> std::dec >> temp;
159  sector.push_back( temp );
160  }
161  }
162  for( int i=0; i<576; i++ ) {
163  if( !paramFile.eof() ) {
164  paramFile >> std::dec >> temp;
165  channelNumber.push_back( temp );
166  }
167  }
168 
169  for( int i=0; i<576; i++ ) {
170  if( !paramFile.eof() ) {
171  paramFile >> std::dec >> temp;
172  geometryId.push_back( temp );
173  }
174  }
175 
176  paramFile.close();
177 
178  if( !paramFile.eof() || nAfcks == 0 || nChannels == 0 ||
179  afckAddress.size() != 12 || sector.size() != 12 ||
180  channelNumber.size() != 576 || geometryId.size() != 576 )
181  {
182  LOG_ERROR << "StETofHardwareMap -- parameter file has not the right amount of entries !!!!" << endm;
183  return;
184  }
185 
186 
187  // logging for debug
188  LOG_DEBUG << "nAfcks: " << nAfcks << endm;
189  LOG_DEBUG << "nChannels: " << nChannels << endm;
190 
191  for( size_t i=0; i<12; i++ ) {
192  LOG_DEBUG << "AFCK address: 0x" << std::hex << afckAddress[ i ] << std::dec << " --> sector: " << sector.at( i ) << endm;
193  }
194 
195  for( size_t i=0; i<576; i++ ) {
196  LOG_DEBUG << "channelNumber: " << channelNumber.at( i ) << " --> geometryId: " << geometryId.at( i ) << endm;
197  }
198 
199 
200  //fill the member variables with data
201  for( size_t i=0; i<12; i++ ) {
202  if( sector.at( i ) != 0 ) {
203  mAfckToSector.push_back( sector.at( i ) );
204 
205  mAfckAddressMap[ afckAddress.at( i ) ] = i;
206  }
207  }
208 
209  for( size_t i=0; i<576; i++ ) {
210  mChannelNumberMap[ channelNumber.at( i ) ] = geometryId.at( i );
211  }
212 
213  LOG_INFO << "StETofHardwareMap -- initialization finished" << endm;
214 }
215 
216 
217 void
218 StETofHardwareMap::mapToGeom( unsigned int rocId, unsigned int chipId, unsigned int chanId, std::vector< unsigned int >& geomVec )
219 {
220  // clear geomVec
221  geomVec.clear();
222 
223  if( mAfckAddressMap.count( rocId ) == 0 ) {
224  LOG_INFO << "StETofHardwareMap::Map - rocId is out of range: 0x" << std::hex << rocId << std::dec << endm;
225  return;
226  }
227 
228  unsigned int rocIndex = mAfckAddressMap.at( rocId );
229  unsigned int channel = chipId * 10 + chanId;
230 
231  if( mYear == 2018 ) {
232  channel += rocIndex * 1000;
233  }
234 
235 
236  if( mChannelNumberMap.count( channel ) == 0 ) {
237  LOG_INFO << "StETofHardwareMap::Map - channel is out of range: chipId " << chipId << " chanId " << chanId << endm;
238  return;
239  }
240 
241 
242  unsigned int sector = mAfckToSector.at( rocIndex );
243  unsigned int geometryId = mChannelNumberMap.at( channel );
244 
245  if( geometryId == 0 ) {
246  LOG_INFO << "chipId: " << chipId << " chanId: " << chanId << " -> channel: " << channel << " --> geometryId: " << geometryId << endm;
247  }
248 
249  // fill geomVec with the geometric identifiers
250  geomVec.push_back( sector );
251  geomVec.push_back( geometryId / 10000 );
252  geomVec.push_back( ( geometryId % 10000 ) / 1000 );
253  geomVec.push_back( ( geometryId % 1000 ) / 10 );
254  geomVec.push_back( geometryId % 10 );
255 
256  return;
257 }
258 
259 void
260 StETofHardwareMap::mapToSector( unsigned int rocId, unsigned int& sector )
261 {
262  sector = 0;
263 
264  if( mAfckAddressMap.count( rocId ) == 0 ) {
265  LOG_INFO << "StETofHardwareMap::Map - rocId is out of range: 0x" << std::hex << rocId << std::dec << endm;
266  return;
267  }
268 
269  unsigned int rocIndex = mAfckAddressMap.at( rocId );
270 
271  sector = mAfckToSector.at( rocIndex );
272 
273  return;
274 }
275 
276 
277 unsigned int
278 StETofHardwareMap::module( unsigned int sector, unsigned int plane )
279 {
280  return ( sector - 13 ) * 3 + mOrderedPlanes[ plane - 1 ];
281 }