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