BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
MucFec.cxx
Go to the documentation of this file.
1//------------------------------------------------------------------------------|
2// [File ]: MucFec.cxx |
3// [Brief ]: Source file of class MucFec 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
16
17// Constructor
18MucFec :: MucFec(int id )
19{
20 //cout << "MucFec:: Create FEC : " << id << endl;
21
22 if( (id < 0) || (id > STRIP_NUM-1) )
23 {
24 cout << "Initialize failure, check id!" << endl;
25 m_ID = 0;
26 }
27 else m_ID = id;
28
29 m_Part = 0;
30 m_Segment = 0;
31 m_Layer = 0;
32 m_FirstStripID = 0;
33 m_StripOrder = DEFAULT_STRIP_ORDER;
34 m_ChainName = "NoName";
35 m_VmeRecord = 0;
36
37 MucFec::Initialize();
38}
39
40MucFec :: MucFec( int id, int stripOrder, int part, int segment, int layer, int firstStripID,
41 unsigned int vmeRecord, string chainName)
42{
43// cout << "MucFec:: Create FEC : " << endl;
44// cout << "ID: " << id << "\tPart: " << part << "\tSegment: " << segment << "\tLayer: " << layer
45// << "\tfirstStripID: " << firstStripID << "\tvmeRecord: " << vmeRecord<<endl;
46
47 // Check parameters
48 if( (id < 0) || (id > STRIP_NUM-1) )
49 {
50 m_ID = 0;
51 cout << "MucFec::Check id:\t" << id << "!" << endl;
52 }else
53 if( (stripOrder != 1) && (stripOrder != -1) )
54 {
55 m_StripOrder = 0;
56 cout << "MucFec::Check stripOrder:\t" << stripOrder << "!" << endl;
57 }else
58 if( (part < 0) || ( part > PART_MAX-1) )
59 {
60 m_Part = 0;
61 cout << "MucFec::Check part:\t" << part << "!" << endl;
62 }else
63 if( (segment < 0) || ( segment > ((part==BRID)?(B_SEG_NUM-1):(E_SEG_NUM-1)) ) )
64 {
65 m_Segment = 0;
66 cout << "MucFec::Check segment:\t" << segment << "!" << endl;
67 }else
68 if( (layer <0) || ( layer > ((part==BRID)?(B_LAY_NUM-1):(E_LAY_NUM-1)) ) )
69 {
70 m_Layer = 0;
71 cout << "MucFec::Check layer:\t" << layer << "!" << endl;
72 }else
73 if( sizeof(vmeRecord) < 4 )
74 {
75 m_VmeRecord = 0;
76 cout << "MucFec::Check record:\t" << vmeRecord << "!" << endl;
77 }else
78 {
79 m_ID = id;
80 m_StripOrder = stripOrder;
81 m_Part = part;
82 m_Segment = segment;
83 m_Layer = layer;
84 m_FirstStripID = firstStripID;
85 m_ChainName = chainName;
86 m_VmeRecord = vmeRecord;
87 }
88
89 MucFec::Initialize();
90}
91
92void MucFec :: Initialize()
93{
94 MucFec::DecodeData();
95 MucFec::DecodeVmeAddress();
96 MucFec::SetFiredStripNumber();
97 MucFec::SetFiredStripVect();
98 MucFec::EncodePowerpcRecord();
99}
100
101//----------------------------------Set methods---------------------------------------
102void MucFec :: DecodeData()
103{
104 m_Data = (unsigned short)m_VmeRecord;
105}
106
107void MucFec :: DecodeVmeAddress()
108{
109 m_VmeAddress = (unsigned short)(m_VmeRecord >> LENGTH); // high 16 bits, 10 bits used
110 m_Module = (m_VmeAddress >> MODULE_BIT) & 0xF; // 4 bits
111 m_Socket = (m_VmeAddress >> SOCKET_BIT) & 0x3; // 2 bits
112 m_FecID = m_VmeAddress & 0xF; // 4 bits
113}
114
115void MucFec :: SetFiredStripNumber()
116{
117 m_FiredStripNumber = 0;
118 for(int i=0; i<STRIP_NUM; i++)
119 {
120 if( (m_Data>>i) & 1 )
121 m_FiredStripNumber++;
122 }
123}
124
125void MucFec :: SetFiredStripVect()
126{
127 m_FiredStripVect.clear();
128 int tempID[STRIP_NUM];
129 int tempFired=0;
130
131 for(int i=0; i<STRIP_NUM; i++)
132 {
133 if( (m_Data>>i) & 1 )
134 {
135 tempID[tempFired] = i;
136 tempFired++;
137 }
138 }
139
140 int stripID = 0;
141 for(int i=0; i<tempFired; i++)
142 {
143 stripID = ((1 - m_StripOrder)/2) * (STRIP_NUM - 1) + (m_StripOrder * tempID[i]);
144 stripID += m_FirstStripID;
145 m_FiredStripVect.push_back( stripID );
146 }
147}
148
149void MucFec :: EncodePowerpcRecord()
150{
151 unsigned int address = ( (m_Part<<PART_BIT) | (m_Segment<<SEG_BIT) | (m_Layer<<LAY_BIT) | m_FirstStripID );
152 m_GeoAddress = (unsigned short)address;
153 m_PowerpcRecord = ( address << LENGTH ) | m_Data;
154}
155
156void MucFec :: SetStripOrder( int stripOrder )
157{
158 m_StripOrder = stripOrder;
159
160 MucFec::SetFiredStripVect();
161}
162
163void MucFec :: SetLocation( int part, int segment, int layer )
164{
165 m_Part = part;
166 m_Segment = segment;
167 m_Layer = layer;
168
169 MucFec::Initialize();
170}
171
172void MucFec :: SetFirstStripID( int firstStripID )
173{
174 m_FirstStripID = firstStripID;
175 MucFec :: EncodePowerpcRecord();
176 MucFec :: SetFiredStripVect();
177}
178
179void MucFec :: SetData( unsigned short data )
180{
181 m_Data = data;
182 m_VmeRecord = (m_VmeRecord | m_Data);
183 MucFec :: EncodePowerpcRecord();
184 MucFec :: SetFiredStripNumber();
185 MucFec :: SetFiredStripVect();
186}
187
188
189
190//-------------------------- Get methods --------------------------------
191int MucFec :: GetFiredStripNumber() { return m_FiredStripNumber; }
192
193unsigned int MucFec :: GetPowerpcRecord() { return m_PowerpcRecord; }
194
195vector< int >* MucFec :: GetFiredStripVect() { return &m_FiredStripVect; }
196
197string MucFec :: GetBin( unsigned int record )
198{
199 const int SIZE = sizeof( unsigned int ) * 8;
200
201 string Bin;
202 unsigned int temp = 0;
203 for(int i=0; i<SIZE; i++)
204 {
205 temp = record >> SIZE-i-1;
206 Bin += ( temp & 1 ) ? "1" : "0";
207 }
208
209 return Bin;
210}
211
212string MucFec :: GetBin( unsigned short record )
213{
214 const int SIZE = sizeof( unsigned short ) * 8;
215
216 string Bin;
217 unsigned short temp = 0;
218 for(int i=0; i<SIZE; i++)
219 {
220 temp = record >> SIZE-i-1;
221 Bin += ( temp & 1 ) ? "1" : "0";
222 }
223
224 return Bin;
225}
226
227string MucFec :: GetVmeBin()
228{
229 return MucFec::GetBin( m_VmeAddress );
230}
231
232string MucFec :: GetGeoBin()
233{
234 return MucFec::GetBin( m_GeoAddress );
235}
236
237string MucFec :: GetDataBin()
238{
239 return MucFec::GetBin( m_Data );
240}
241
242
243
244// END
TTree * data
string GetBin(unsigned int record)
Definition: MucFec.cxx:197