BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
MucChain.cxx
Go to the documentation of this file.
1//------------------------------------------------------------------------------|
2// [File ]: MucChain.cxx |
3// [Brief ]: Source file of class MucChain for electronics mapping |
4// [Author]: Xie Yuguang, <[email protected]> |
5// [Date ]: Jun 7, 2006 |
6// [Log ]: See ChangLog |
7//------------------------------------------------------------------------------|
8
9#include<iostream>
10#include<vector>
11
12using namespace std;
13
15
16// Constructor
17MucChain :: MucChain( int id, std::string name, int module, int socket, int fecOrder )
18{
19 // cout << "MucChain:: Create chain : " << endl;
20 // cout << "ID: " << id << "\tModule: " << module << "\tSocket: " << socket << "\tFecOrder: " << fecOrder << endl;
21 m_ID = id;
22 m_Name = name;
23 m_Module = module;
24 m_Socket = socket;
25 m_FecOrder = fecOrder;
26
27 Mapping();
28}
29
30// Destructor
31MucChain :: ~MucChain()
32{
33 // cout << "MucChain:: Destructor()." <<endl;
34 delete []m_FirstStripID;
35 delete []m_FecLayerID;
36 delete []m_StripOrder;
37
38 m_FecVect.clear();
39}
40
41//----------------------- Set properties methods for public---------------
42void MucChain :: ReMap( string name, int module, int socket )
43{
44 m_Name = name;
45 m_Module = module;
46 m_Socket = socket;
47
48 MucChain::Mapping();
49}
50
51void MucChain :: SetFecOrder( int fecOrder )
52{
53 m_FecOrder = fecOrder;
54 MucChain::InitFecVect();
55}
56
57// All FECs
58void MucChain :: SetStripOrder( int stripOrder )
59{
60 // cout << "MucChain:: SetStripOrder( int )." << endl;
61 int order;
62 if( stripOrder == 0 ) order = DEFAULT_STRIP_ORDER;
63 else order = stripOrder;
64
65 for(int i=0; i<m_FecTotal; i++) m_StripOrder[ i ] = order;
66}
67
68void MucChain :: SetStripOrder( int fecID, int stripOrder )
69{
70 // Decode FecVect member number by fecID
71 int i = m_FecOrder * ( fecID - ((1-m_FecOrder)/2)*(m_FecTotal - 1) );
72 m_FecVect[i].SetStripOrder( stripOrder );
73}
74
75void MucChain :: ArrayInvert( int* array, int number )
76{
77 int temp;
78 for(int i=0; i<number/2; i++)
79 {
80 temp = array[i];
81 array[i] = array[number-1-i];
82 array[number-1-i] = temp;
83 }
84}
85
86//------------------------ set properties methods for private---------------
87void MucChain :: Mapping()
88{
89 InitPart();
90 InitSegment();
91 InitFecTotal();
92 InitFecPerLayer();
93 InitFecLayerID();
94 InitFirstStripID();
95 InitStripOrder();
96 InitFecVect();
97}
98
99void MucChain :: InitPart()
100{
101 // cout << "MucChain:: InitPart()." <<endl;
102 if( m_Name[0] == 'B' ) m_Part = BRID;
103 else if( m_Name[1] == 'E' ) m_Part = EEID;
104 else m_Part = WEID;
105}
106
107void MucChain :: InitSegment()
108{
109 // cout << "MucChain:: InitSegment()." <<endl;
110 if( m_Part == BRID )
111 {
112 switch( m_Name[2] )
113 {
114 case '1' : m_Segment = 2; break;
115 case '2' : m_Segment = 1; break;
116 case '3' : m_Segment = 0; break;
117 case '4' : m_Segment = 7; break;
118 case '5' : m_Segment = 6; break;
119 case '6' : m_Segment = 5; break;
120 case '7' : m_Segment = 4; break;
121 case '8' : m_Segment = 3; break;
122 default : ;
123 }
124 }
125 else if( m_Part == EEID )
126 {
127 switch( m_Name[2] )
128 {
129 case '1' : m_Segment = 0; break;
130 case '2' : m_Segment = 3; break;
131 case '3' : m_Segment = 2; break;
132 case '4' : m_Segment = 1; break;
133 }
134 }
135 else
136 {
137 switch( m_Name[2] )
138 {
139 case '1' : m_Segment = 1; break;
140 case '2' : m_Segment = 2; break;
141 case '3' : m_Segment = 3; break;
142 case '4' : m_Segment = 0; break;
143 }
144 }
145}
146
147void MucChain :: InitFecTotal()
148{
149 // cout << "MucChain:: InitFecTotal()." <<endl;
150 if( m_Part == BRID ) // Barrel
151 {
152 if( m_Name[1] == 'O' ) { // Odd layer chain
153 m_FecTotal = FEC_NUM - 1; // 15 FECs
154 }
155 else // Even layer chain
156 {
157 if( m_Segment == BRTOP && m_Name[1] == 'E' ) { // Top segment
158 m_FecTotal = FEC_NUM ; // 16 FECs
159 }
160 else { // Not top segment
161 m_FecTotal = FEC_NUM - 4; // 12 FECs
162 }
163 }
164 }
165 else { // Endcap
166 m_FecTotal = FEC_NUM; // 16 FECs
167 }
168}
169
170void MucChain :: InitFecPerLayer()
171{
172 // cout << "MucChain:: InitFecPerLayer()." <<endl;
173 if( m_FecTotal != 0 ) {
174 if( m_FecTotal == FEC_NUM ) m_FecPerLayer = 4;
175 else m_FecPerLayer = 3;
176 }
177 else
178 m_FecPerLayer = 0;
179}
180
181void MucChain :: InitFecLayerID()
182{
183 // cout << "MucChain:: InitLayer()." <<endl;
184 // Init array
185 for(int i=0; i<FEC_NUM; i++) m_FecLayerID[i] = 0;
186
187 // Set FEC layer id according to default order
188 if( m_Part == BRID ) // Barral chains
189 {
190 if( m_Name[1] == 'O' ) // Odd layer chain, layer id: 0, 2, 4, 6, 8
191 {
192 for(int i=0; i<m_FecTotal; i++) {
193 m_FecLayerID[i] = (i/m_FecPerLayer) * 2;
194 }
195 }
196 else // Even layer chain, layer id: 1, 3, 5, 7
197 {
198 for(int i=0; i<m_FecTotal; i++) {
199 m_FecLayerID[i] = (i/m_FecPerLayer) * 2 + 1;
200 }
201 }
202 }
203 else // Endcap chains
204 {
205 if( m_Name[3] == 'F' ) // First chain, layer id: 0, 1, 2, 3
206 {
207 for(int i=0; i<m_FecTotal; i++) {
208 m_FecLayerID[i] = 3 - (i/m_FecPerLayer);
209 }
210 }
211 else // Second chain, layer id: 4, 5, 6, 7
212 {
213 for(int i=0; i<m_FecTotal; i++) {
214 m_FecLayerID[i] = 7 - (i/m_FecPerLayer);
215 }
216 }
217 }
218
219 // If inverting order
220 if( m_FecOrder == -1 )
221 MucChain::ArrayInvert( &m_FecLayerID[0], m_FecTotal );
222}
223
224void MucChain :: InitFirstStripID()
225{
226 // cout << "MucChain:: InitFirstStripID()." <<endl;
227 // Init array
228 for(int i=0; i<FEC_NUM; i++)
229 m_FirstStripID[i] = 0;
230
231 // Set first strip ID according to default fecOrder
232 if( m_Part== BRID ) // Barrel chains
233 {
234 if( m_Name[1] == 'E' ) // East end, only even number layer chain, layer id: 1, 3, 5, 7
235 {
236 // Section number is defined by m_FecTotal/m_FecPerLayer
237 // Some sections of chain inverting default firstStripID sequence
238
239 if(m_Segment==BRTOP) { // BRTOP segment is exceptive, FirstStripID sequence is 64,96,80,48
240 for(int i=0; i<m_FecTotal; i++)
241 m_FirstStripID[i] = FIRST_STRID_SQC_BETOP[i%m_FecPerLayer ];
242 }
243 else switch(m_Segment)
244 {
245 case 0: ; // Segment 0, 1, 5, section 0, 2: (+), 1, 3: (-)
246 case 1: ;
247 case 5:
248 for(int i=0; i<m_FecTotal; i++)
249 m_FirstStripID[i] = FIRST_STRID_SQC_BEA[i%m_FecPerLayer ];
250 break;
251 default : // Other segments
252 for(int i=0; i<m_FecTotal; i++)
253 m_FirstStripID[i] = FIRST_STRID_SQC_BEB[i%m_FecPerLayer ];
254 }
255 }
256 else if( m_Name[1] == 'W' ) // West end, even number layer chain, layer id: 1, 3, 5, 7
257 {
258 switch(m_Segment)
259 {
260 case 0: ; // Segment 0, 1, 2, 5
261 case 1: ;
262 case 2: ;
263 case 5:
264 for(int i=0; i<m_FecTotal; i++)
265 m_FirstStripID[i] = FIRST_STRID_SQC_BWA[i%m_FecPerLayer ];
266 break;
267 default: // Other segments
268 for(int i=0; i<m_FecTotal; i++)
269 m_FirstStripID[i] = FIRST_STRID_SQC_BWB[i%m_FecPerLayer ];
270 }
271 }
272 else // West end, odd number layer chain, layer id: 0, 2, 4, 6
273 {
274 switch(m_Segment)
275 {
276 case 0: ; // Segment 0, 1, 2, 5
277 case 1: ;
278 case 2: ;
279 case 5:
280 for(int i=0; i<m_FecTotal; i++)
281 m_FirstStripID[i] = FIRST_STRID_SQC_BWB[ i%m_FecPerLayer ];
282 break;
283 default : // Other segments
284 for(int i=0; i<m_FecTotal; i++)
285 m_FirstStripID[i] = FIRST_STRID_SQC_BWA[ i%m_FecPerLayer ];
286 }
287 }
288
289 // for all chains in Barrel, section 0, 2, 4: (+), 1, 3: (-), inverting 1, 3;
290 for(int j=1; j<m_FecTotal/m_FecPerLayer; j+=2)
291 MucChain::ArrayInvert( &m_FirstStripID[j*m_FecPerLayer], m_FecPerLayer );
292 } // End barrel chains
293 else { // Endcap chains
294 // Set default firstStripID order(+), no inverting
295 for(int i=0; i<m_FecTotal; i++) m_FirstStripID[i] = FIRST_STRID_SQC_EC[ i%m_FecPerLayer ];
296 }
297
298 // If fecOrder inverting
299 if( m_FecOrder == -1 ) MucChain::ArrayInvert( m_FirstStripID, m_FecTotal );
300
301}
302
303unsigned int MucChain :: EncodeVmeRecord( int module, int socket, int fecID, unsigned short data)
304{
305 // cout << "MucChain:: EncodeVmeRecord()." <<endl;
306 unsigned int record = ((module << MODULE_BIT) | (socket << SOCKET_BIT) | fecID);
307 return ( (record << LENGTH) | data );
308}
309
310// All FECs
311void MucChain :: InitStripOrder()
312{
313 // cout << "MucChain:: InitStripOrder()." << endl;
314 for(int i=0; i<m_FecTotal; i++)
315 {
316 if( m_Part == BRID ) // Barrel
317 {
318 m_StripOrder[i] = -1;
319 /*
320 if( m_Name[1] == 'E' ) // East end, only even number layer chain, layer id: 1, 3, 5, 7
321 {
322 // Section number is defined by m_FecTotal/m_FecPerLayer
323 // Some sections of chain inverting default strip order
324
325 if(m_Segment==BRTOP) { //Strip order is +1, -1, +1, -1
326 for(int i=0; i<m_FecTotal; i++)
327 m_StripOrder[i] = STRORDER_BETOP[i%m_FecPerLayer ];
328 }
329 else switch(m_Segment)
330 {
331 case 0: ; // Segment 0, 1, 5, section 0, 2: (--+), 1, 3: (+--)
332 case 1: ;
333 case 5:
334 for(int i=0; i<m_FecTotal; i++)
335 m_StripOrder[i] = STRORDER_BEA[i%m_FecPerLayer ];
336 break;
337 default: // Other segments
338 for(int i=0; i<m_FecTotal; i++)
339 m_StripOrder[i] = STRORDER_BEB[i%m_FecPerLayer ];
340 }
341 }
342 else if( m_Name[1] == 'W' ) // West end, even number layer chain, layer id: 1, 3, 5, 7
343 {
344 switch(m_Segment)
345 {
346 case 0: ; // Segment 0, 1, 2, 5, --+
347 case 1: ;
348 case 2: ;
349 case 5:
350 for(int i=0; i<m_FecTotal; i++)
351 m_StripOrder[i] = STRORDER_BEA[i%m_FecPerLayer ];
352 break;
353 default : // Other segments, +--
354 for(int i=0; i<m_FecTotal; i++)
355 m_StripOrder[i] = STRORDER_BEB[i%m_FecPerLayer ];
356 }
357 }
358 else { // West end, odd number layer chain, layer id: 0, 2, 4, 6
359 for(int i=0; i<m_FecTotal; i++)
360 m_StripOrder[i] = STRORDER_BWO[ i%m_FecPerLayer ];
361 }
362
363 // for all chains in Barrel, section 0, 2, 4: (+), 1, 3: (-), inverting 1, 3;
364 for(int j=1; j<m_FecTotal/m_FecPerLayer; j+=2)
365 MucChain::ArrayInvert( &m_StripOrder[j*m_FecPerLayer], m_FecPerLayer );
366 */
367 } // End Barrel
368 else if( (m_Part==EEID && (m_Segment==0 || m_Segment==2)) ||
369 (m_Part==WEID && (m_Segment==1 || m_Segment==3)) )
370 m_StripOrder[ i ] = STRORDER_ECA[ m_FecLayerID[i] ];
371 else
372 m_StripOrder[ i ] = STRORDER_ECB[ m_FecLayerID[i] ];
373
374 } // End FecTotal
375
376}
377
378void MucChain :: InitFecVect()
379{
380 // cout << "MucChain:: InitFecVect()." << endl;
381
382 unsigned short data = 0;
383 int part = m_Part;
384 int segment = m_Segment;
385
386 int id;
387 int layer;
388 int firstStripID;
389 int stripOrder;
390 string chainName;
391 unsigned int vmeRecord;
392
393 for(int i=0; i<m_FecTotal; i++)
394 {
395 // Encode FEC id by FecVect member number
396 id = ( (1 - m_FecOrder)/2 ) * ( m_FecTotal - 1 ) + (m_FecOrder * i);
397
398 layer = m_FecLayerID[ id ];
399 firstStripID = m_FirstStripID[ id ];
400 stripOrder = m_StripOrder[ id ];
401 chainName = MucChain::m_Name;
402 vmeRecord = EncodeVmeRecord( m_Module, m_Socket, id , data);
403 // cout << "FEC:\t" << id << "\t" << (vmeRecord>>LENGTH) << endl;
404
405 MucFec aFec( id, stripOrder, part, segment, layer, firstStripID, vmeRecord, chainName );
406 m_FecVect.push_back( aFec );
407 }
408}
409
410// END
411
412
413
TTree * data
const int STRORDER_ECA[E_LAY_NUM]
Definition MucChain.h:33
const int STRORDER_ECB[E_LAY_NUM]
Definition MucChain.h:35
const int FIRST_STRID_SQC_BEA[3]
Definition MucChain.h:27
const int FIRST_STRID_SQC_BEB[3]
Definition MucChain.h:28
const int FIRST_STRID_SQC_BWA[3]
Definition MucChain.h:29
const int FIRST_STRID_SQC_BWB[3]
Definition MucChain.h:31
const int FIRST_STRID_SQC_EC[4]
Definition MucChain.h:25
const int FIRST_STRID_SQC_BETOP[4]
Definition MucChain.h:26
void ArrayInvert(int *array, int number)
Definition MucChain.cxx:75