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