BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TofBuilder.cxx
Go to the documentation of this file.
1#include "RawDataCnv/EventManagement/TofBuilder.h"
2#include "Identifier/TofID.h"
3#include <fstream>
4#include <iostream>
5using namespace std;
6
8 // set vector size (2^14) and initialize to -1
9 m_re2te = new uint32_t[16384]; // we have 2^14 different REID
10 memset( (void*)m_re2te, 0xFF, 16384 * sizeof( uint32_t ) );
11
13}
14
15TofBuilder::~TofBuilder() { delete m_re2te; }
16
17void TofBuilder::unPack( uint32_t reDigi, uint32_t& REId, uint32_t& TEData, uint32_t& overFlow,
18 uint32_t& TorQ ) {
19 REId = ( reDigi & m_idMask ) >> m_idIndex;
20 // cout << "TofBuilder::unPack reDigi: 0x" << hex << reDigi
21 // << " reid: 0x" << reid << dec << endl;
22
23 TEData = ( reDigi & m_dataMask );
24 overFlow = ( reDigi & m_overflowMask ) >> m_overflowIndex;
25 TorQ = ( reDigi & m_TQMask ) >> m_TQIndex;
26 // if (TorQ) TEData &= 0x1FFF; // ADC 13 bits
27 // cout << "reid" << hex << reid << endl;
28 // cout << "teid" << hex << TEId << endl;
29 return;
30}
31
32StatusCode TofBuilder::pack( TofDigiCol* digiCol, WriteRawEvent*& re ) {
33 if ( digiCol == 0 )
34 {
35 cerr << "TofBuilder::pack can't get digiCol" << endl;
36 return StatusCode::FAILURE;
37 }
38
39 uint32_t size = 0;
40 uint32_t teid = 0, tetdc = 0, teadc = 0, reid = 0, redigi = 0, overflow = 0;
41 std::vector<TofDigi*> vEtfDigi;
42
43 // for TOF Digis
44 TofDigiCol::const_iterator pTofDigi = digiCol->begin();
45 for ( pTofDigi; pTofDigi != digiCol->end(); pTofDigi++ )
46 {
47 if ( TofID::is_mrpc( ( *pTofDigi )->identify() ) )
48 {
49 vEtfDigi.push_back( *pTofDigi );
50 continue;
51 }
52 teid = ( *pTofDigi )->getIntId();
53 if ( teid == 0xFFFFFFFF )
54 {
55 m_buf[size++] = ( *pTofDigi )->getOverflow();
56 continue;
57 }
58 // check weither it's a valid teid (for a mistake in simulation)
59 if ( ( teid & 0x4001 ) == 1 ) continue;
60 reid = getREID( teid );
61 tetdc = ( *pTofDigi )->getTimeChannel();
62 teadc = ( *pTofDigi )->getChargeChannel();
63 // overflow
64 uint32_t overflow_tmp = ( *pTofDigi )->getOverflow();
65 // set tdc
66 if ( tetdc != 0x7FFFFFFF )
67 {
68 overflow = ( ( tetdc > m_dataMask ) ? 1 : 0 ) | ( overflow_tmp & 1 );
69 redigi = ( tetdc & m_dataMask ) | ( ( reid << m_idIndex ) & m_idMask ) |
70 ( ( overflow << m_overflowIndex ) & m_overflowMask ) |
71 ( ( 0 << m_TQIndex ) & m_TQMask );
72 m_buf[size++] = redigi;
73 }
74 // set adc
75 if ( teadc != 0x7FFFFFFF )
76 {
77 overflow = ( ( teadc > m_dataMask ) ? 1 : 0 ) | ( ( overflow_tmp >> 1 ) & 1 );
78 redigi = ( teadc & m_dataMask ) | ( ( reid << m_idIndex ) & m_idMask ) |
79 ( ( overflow << m_overflowIndex ) & m_overflowMask ) |
80 ( ( 1 << m_TQIndex ) & m_TQMask );
81 m_buf[size++] = redigi;
82 }
83 }
84
85 append2event( re, 0xa20000, size );
86
87 // for ETF Digis
88 uint32_t shift = size;
89 for ( std::vector<TofDigi*>::const_iterator pEtfDigi = vEtfDigi.begin();
90 pEtfDigi != vEtfDigi.end(); ++pEtfDigi )
91 {
92 teid = ( *pEtfDigi )->getIntId();
93 if ( teid == 0xFFFFFFFF )
94 {
95 m_buf[size++] = ( *pEtfDigi )->getOverflow();
96 continue;
97 }
98 reid = getREID( teid );
99 tetdc = ( *pEtfDigi )->getTimeChannel();
100 teadc = ( *pEtfDigi )->getChargeChannel();
101 // set tdc ( the L/T for ETF )
102 if ( tetdc != 0x7FFFFFFF )
103 {
104 redigi = ( tetdc & 0x7FFFF ) |
105 // ((0<<19)&0x80000) |
106 ( ( reid << 20 ) & 0xFFF00000 );
107 m_buf[size++] = redigi;
108 }
109 // set adc ( the L/T for ETF )
110 if ( teadc != 0x7FFFFFFF )
111 {
112 redigi =
113 ( teadc & 0x7FFFF ) | ( ( 1 << 19 ) & 0x80000 ) | ( ( reid << 20 ) & 0xFFF00000 );
114 m_buf[size++] = redigi;
115 }
116 }
117
118 if ( size != shift ) append2event( re, 0xa70000, size - shift, shift );
119
120 return StatusCode::SUCCESS;
121}
122
123// initialize re2te tables
124
125StatusCode TofBuilder::initialize( string& initFile ) {
126 ifstream f;
127
128 uint32_t nRELayerPos, nRECellPos, nREEaWePos;
129 uint32_t nRELayerMask, nRECellMask, nREEaWeMask;
130
131 //-----------------------------------------------------------
132 // read initFile
133 f.open( initFile.c_str() );
134
135 if ( f.bad() )
136 {
137 cerr << "Error: could not open file " << initFile << endl;
138 return StatusCode::FAILURE;
139 }
140
141 if ( !Builder::find( f, "##TofDigiConf", initFile ) )
142 {
143 cerr << "Error: could not find '##TofDigiConf' in file " << initFile << endl;
144 return StatusCode::FAILURE;
145 }
146
147 if ( !Builder::expect( f, "#Index,mask", initFile ) ||
148 !Builder::expectInt( f, "id", initFile, m_idIndex, m_idMask ) ||
149 !Builder::expectInt( f, "data", initFile, m_dataIndex, m_dataMask ) ||
150 !Builder::expectInt( f, "Overflow", initFile, m_overflowIndex, m_overflowMask ) ||
151 !Builder::expectInt( f, "T/Q", initFile, m_TQIndex, m_TQMask ) ||
152 !Builder::expectInt( f, "Cell", initFile, nRECellPos, nRECellMask ) ||
153 !Builder::expectInt( f, "Layer", initFile, nRELayerPos, nRELayerMask ) ||
154 !Builder::expectInt( f, "EaWe", initFile, nREEaWePos, nREEaWeMask ) )
155 return StatusCode::FAILURE;
156
157 f.close();
158
159 //-----------------------------------------------------------
160 // Build re2te table
161 for ( uint32_t barrel_ec_eawe = TofID::getBARREL_EC_MIN();
162 barrel_ec_eawe <= TofID::getBARREL_EC_MAX(); barrel_ec_eawe++ )
163 {
164 uint32_t TELayerMax, TEphiMax, TEBaEaWe;
165 uint32_t eawe = 0, layer = 0, cell = 0;
166
167 if ( barrel_ec_eawe == 1 )
168 {
169 // it is BARREL
170 TELayerMax = TofID::getLAYER_BARREL_MAX();
171 TEphiMax = TofID::getPHI_BARREL_MAX();
172 }
173 else
174 {
175 // it is ease and west ENDCAP
176 TELayerMax = TofID::getLAYER_ENDCAP_MAX();
177 // zoujh: for luminosity !!! the right value should be 47
178 TEphiMax = 48; // TofID::getPHI_ENDCAP_MAX();
179 }
180
181 for ( TEBaEaWe = 0; TEBaEaWe < 2; TEBaEaWe++ )
182 {
183 if ( barrel_ec_eawe != 1 && TEBaEaWe > 0 ) break;
184 eawe = TEBaEaWe + ( barrel_ec_eawe / 2 );
185 for ( uint32_t TELayer = 0; TELayer <= TELayerMax; TELayer++ )
186 {
187 if ( barrel_ec_eawe == 1 ) { layer = TELayer + 1; }
188 else
189 {
190 // if (barrel_ec_eawe == TofID::getBARREL_EC_MIN()) layer = TELayer + 0;
191 // else layer = TELayer + 3;
192 layer = 3;
193 }
194 if ( layer <= 3 )
195 {
196 for ( uint32_t TEphi = 0; TEphi <= TEphiMax; TEphi++ )
197 {
198 cell = TEphi + 1;
199 uint32_t reid = ( ( ( eawe << nREEaWePos ) & nREEaWeMask ) |
200 ( ( layer << nRELayerPos ) & nRELayerMask ) |
201 ( ( cell << nRECellPos ) & nRECellMask ) );
202 uint32_t teid = TofID::getIntID( barrel_ec_eawe, TELayer, TEphi, TEBaEaWe );
203 // std::cout << "reid " << reid << " eawe " << eawe << " layer " << layer << " cell
204 // " << cell
205 // << " teid " << hex << teid << dec << " barrel_ec_eawe " <<
206 // barrel_ec_eawe << " TELayer "
207 // << TELayer << " TEphi " << TEphi << " TEBaEaWe " << TEBaEaWe <<
208 // std::endl;
209 m_re2te[reid] = teid;
210 m_te2reMap.insert( TE2REMAP::value_type( teid, reid ) );
211 }
212 }
213 }
214 }
215 }
216
217 //-----------------------------------------------------------
218 // Append the ETF te2re map
219 for ( uint32_t module = 0; module < 36; ++module )
220 {
221 for ( uint32_t strip = 0; strip < 12; ++strip )
222 {
223 // uint32_t ew = 0 or 1, sb = 0 or 1;
224 // uint32_t teid = TofID::getIntID(3/*barrel_ec, 3 means ETF*/, ew, module, strip, sb);
225 // uint32_t reid = teid & 0xFFF;
226 // m_te2reMap.insert(TE2REMAP::value_type(teid, reid));
227 uint32_t teid = TofID::getIntID( 3, 0, module, strip, 0 );
228 m_te2reMap.insert( TE2REMAP::value_type( teid, ( teid & 0xFFF ) ) );
229 teid = TofID::getIntID( 3, 0, module, strip, 1 );
230 m_te2reMap.insert( TE2REMAP::value_type( teid, ( teid & 0xFFF ) ) );
231 teid = TofID::getIntID( 3, 1, module, strip, 0 );
232 m_te2reMap.insert( TE2REMAP::value_type( teid, ( teid & 0xFFF ) ) );
233 teid = TofID::getIntID( 3, 1, module, strip, 1 );
234 m_te2reMap.insert( TE2REMAP::value_type( teid, ( teid & 0xFFF ) ) );
235 }
236 }
237
238 // return StatusCode::SUCCESSful initialization
239 return StatusCode::SUCCESS;
240}
241
242uint32_t TofBuilder::getREID( uint32_t teid ) {
243 TE2REMAP::iterator itr = m_te2reMap.find( teid );
244
245 if ( itr == m_te2reMap.end() )
246 {
247 cout << "wrong teid in tof" << teid << endl;
248 exit( 8 );
249 }
250
251 return itr->second;
252}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
eformat::write::FullEventFragment WriteRawEvent
void append2event(WriteRawEvent *&re, uint32_t source_id, uint32_t size, uint32_t shift=0)
Definition Builder.cxx:69
static bool find(ifstream &f, string msg, string fname)
Definition Builder.cxx:52
static bool expect(ifstream &f, string msg, string fname)
Definition Builder.cxx:25
static bool expectInt(ifstream &f, string msg, string fname, uint32_t &val1, uint32_t &val2)
Definition Builder.cxx:39
Builder()
Definition Builder.cxx:11
virtual StatusCode initialize(string &initFile)
virtual ~TofBuilder()
virtual StatusCode pack(TofDigiCol *digiCol, WriteRawEvent *&re)
virtual void unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TEData, uint32_t &overFlow, uint32_t &TorQ)
virtual uint32_t getREID(uint32_t teid)
static value_type getPHI_BARREL_MAX()
Definition TofID.cxx:167
static value_type getBARREL_EC_MIN()
Definition TofID.cxx:172
static value_type getBARREL_EC_MAX()
Definition TofID.cxx:170
static bool is_mrpc(const Identifier &id)
Definition TofID.cxx:98
static value_type getLAYER_ENDCAP_MAX()
Definition TofID.cxx:165
static value_type getIntID(int barrel_ec, int layer, int phi_module, int end)
Definition TofID.cxx:147
static value_type getLAYER_BARREL_MAX()
Definition TofID.cxx:163