BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcBuilder.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include "Identifier/EmcID.h"
5using namespace std;
6
8 :Builder()
9{
10 // set vector size (2^13) and initialize to -1
11 m_re2te = new uint32_t[8192]; // we have 2^14 different REID
12 memset((void*)m_re2te, 0xFF, 8192*sizeof(uint32_t));
13
15}
16
18{
19 delete m_re2te;
20}
21
22void EmcBuilder::unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TETDC, uint32_t &TEADC,
23 uint32_t &measure)
24{
25 REId = (reDigi&m_idMask) >> m_idIndex;
26 TETDC = (reDigi&m_tdcMask) >> m_tdcIndex;
27 TEADC = (reDigi&m_adcMask) >> m_adcIndex;
28 measure = (reDigi&m_measureMask) >> m_measureIndex;
29
30 return;
31}
32
33StatusCode EmcBuilder::pack(EmcDigiCol* digiCol, WriteRawEvent*& re)
34{
35 if (digiCol == 0 ) {
36 cerr << "EmcBuilder::pack can't get digiCol" << endl;
37 return StatusCode::FAILURE;
38 }
39
40 uint32_t size = 0;
41 uint32_t teid = 0, tetdc = 0, teadc = 0, reid = 0, redigi = 0, measure = 0;
42
43 EmcDigiCol::const_iterator pEmcDigi = digiCol->begin();
44 for (pEmcDigi; pEmcDigi!= digiCol->end(); pEmcDigi++) {
45 teid = (*pEmcDigi)->getIntId();
46 reid = getREID(teid);
47 tetdc = (*pEmcDigi)->getTimeChannel();
48 teadc = (*pEmcDigi)->getChargeChannel();
49 measure = (*pEmcDigi)->getMeasure();
50
51 // if negative energy, don't record
52 if(teadc&0x80000000) continue;
53 // set ...
54 redigi = ((reid<<m_idIndex)&m_idMask)|
55 ((tetdc<<m_tdcIndex)&m_tdcMask)|
56 ((teadc<<m_adcIndex)&m_adcMask)|
57 ((measure<<m_measureIndex)&m_measureMask);
58 m_buf[size++] = redigi;
59 }
60
61 append2event(re, 0xa30000, size);
62
63 return StatusCode::SUCCESS;
64}
65
66// initialize re2te tables
67
68StatusCode EmcBuilder::initialize(string& initFile)
69{
70 ifstream f;
71
72 uint32_t nREThetaPos, nREPhiPos, nREEaWePos;
73 uint32_t nREThetaMask, nREPhiMask, nREEaWeMask;
74
75 //-----------------------------------------------------------
76 // read initFile
77 f.open( initFile.c_str());
78
79 if( f.bad() )
80 {
81 cerr << "Error: could not open file " << initFile << endl;
82 return false;
83 }
84
85 if (!Builder::find( f, "##EmcDigiConf", initFile)) {
86 cerr << "Error: could not find '##EmcDigiConf' in file " << initFile << endl;
87 return StatusCode::FAILURE;
88 }
89
90 if( !Builder::expect( f, "#Index,mask", initFile) ||
91 !Builder::expectInt( f, "id", initFile, m_idIndex, m_idMask) ||
92 !Builder::expectInt( f, "tdc", initFile, m_tdcIndex, m_tdcMask) ||
93 !Builder::expectInt( f, "measure", initFile, m_measureIndex, m_measureMask) ||
94 !Builder::expectInt( f, "adc", initFile, m_adcIndex, m_adcMask) ||
95 !Builder::expectInt( f, "Phi", initFile, nREPhiPos, nREPhiMask) ||
96 !Builder::expectInt( f, "Theta", initFile, nREThetaPos, nREThetaMask) ||
97 !Builder::expectInt( f, "EaWe", initFile, nREEaWePos, nREEaWeMask))
98 return false;
99
100
101 f.close();
102
103 //-----------------------------------------------------------
104 //Build re2te table
105 for(uint32_t barrel_ec_eawe = EmcID::getBARREL_EC_MIN();
106 barrel_ec_eawe <= EmcID::getBARREL_EC_MAX(); barrel_ec_eawe++)
107 {
108 uint32_t TEthetaMax, TEphiMax;
109 uint32_t TEthetaMin, TEphiMin;
110 uint32_t eawe, theta, phi;
111 if(barrel_ec_eawe == EmcID::getBARREL())
112 {
113 //it is BARREL
114 TEthetaMax = EmcID::getTHETA_BARREL_MAX();//43
115 TEthetaMin = EmcID::getTHETA_BARREL_MIN();//0
116 } else
117 {
118 //it is ease and west ENDCAP
119 TEthetaMax = EmcID::getTHETA_ENDCAP_MAX();//5
120 TEthetaMin = EmcID::getTHETA_ENDCAP_MIN();//0
121 if (barrel_ec_eawe == EmcID::getBARREL_EC_MIN())
122 eawe = 0;//east
123 else
124 eawe = 1;//west
125 }
126 for(uint32_t TEtheta = TEthetaMin; TEtheta <= TEthetaMax; TEtheta++ )
127 {
128 if(barrel_ec_eawe == EmcID::getBARREL())
129 {
130 //it is BARREL
131 if (TEtheta <= EmcID::getTHETA_BARREL_MAX()/2)
132 {
133 eawe = 0; //east
134 theta = EmcID::getTHETA_BARREL_MAX()/2 +1 - TEtheta; //0-21=>22-1
135 }
136 else {
137 eawe = 1; //west
138 theta = TEtheta - EmcID::getTHETA_BARREL_MAX()/2; //22-43=>1-22
139 }
140 TEphiMax = EmcID::getPHI_BARREL_MAX();//119
141 TEphiMin = EmcID::getPHI_BARREL_MIN();//0
142
143 } else
144 {
145 //it is ease and west ENDCAP
146 theta = TEtheta + EmcID::getTHETA_BARREL_MAX()/2 + 2;
147 TEphiMax = EmcID::getPHI_ENDCAP_MAX(TEtheta);//64,80,96
148 TEphiMin = EmcID::getPHI_ENDCAP_MIN();
149
150 }
151
152 for(uint32_t TEphi = TEphiMin; TEphi <= TEphiMax; TEphi++ )
153 {
154 phi = TEphi + 1;
155 //cout << "eawe" << hex << eawe <<endl;
156 //cout << "__FILE__ theta " << theta << "phi " << phi << endl;
157 uint32_t reid = ((eawe<<nREEaWePos)&nREEaWeMask)|
158 ((theta<<nREThetaPos)&nREThetaMask)|
159 ((phi<<nREPhiPos)&nREPhiMask);
160 uint32_t teid = EmcID::getIntID(barrel_ec_eawe, TEtheta, TEphi);
161 //cout << "barrel_ec_eawe" << barrel_ec_eawe <<endl;
162 //cout << "TEtheta" << hex << TEtheta << endl;
163 //cout << "TEphi" << hex << TEphi <<endl;
164
165 if( reid >= 8192 )
166 {
167 cerr << "Error: REID overflow !" << reid << endl;
168 exit(8);
169 }
170 //cout << "reid" << hex << reid << endl;
171 //cout << "teid" << hex << teid << endl;
172 m_re2te[reid] = teid;
173 m_te2reMap.insert(TE2REMAP::value_type(teid, reid)) ;
174 }
175 }
176 }
177 // return successful initialization
178 return StatusCode::SUCCESS;
179}
180
181
182uint32_t EmcBuilder::getREID(uint32_t teid)
183{
184 TE2REMAP::iterator itr = m_te2reMap.find(teid);
185
186 if (itr == m_te2reMap.end()) {
187 cout<<"wrong teid in emc "<<teid<<endl;
188 exit(8);
189 }
190
191 return itr->second;
192}
193
ObjectVector< EmcDigi > EmcDigiCol
Definition: EmcDigi.h:43
void append2event(WriteRawEvent *&re, uint32_t source_id, uint32_t size, uint32_t shift=0)
Definition: Builder.cxx:76
static bool find(ifstream &f, string msg, string fname)
Definition: Builder.cxx:60
static bool expect(ifstream &f, string msg, string fname)
Definition: Builder.cxx:28
static bool expectInt(ifstream &f, string msg, string fname, uint32_t &val1, uint32_t &val2)
Definition: Builder.cxx:44
StatusCode initialize(string &initFile)
Definition: EmcBuilder.cxx:68
StatusCode pack(EmcDigiCol *digiCol, WriteRawEvent *&re)
Definition: EmcBuilder.cxx:33
virtual ~EmcBuilder()
Definition: EmcBuilder.cxx:17
void unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TETDC, uint32_t &TEADC, uint32_t &measure)
Definition: EmcBuilder.cxx:22
uint32_t getREID(uint32_t teid)
Definition: EmcBuilder.cxx:182
static unsigned int getPHI_BARREL_MAX()
Definition: EmcID.cxx:107
static unsigned int getBARREL_EC_MIN()
Definition: EmcID.cxx:136
static unsigned int getBARREL_EC_MAX()
Definition: EmcID.cxx:132
static unsigned int getTHETA_ENDCAP_MIN()
Definition: EmcID.cxx:103
static unsigned int getTHETA_ENDCAP_MAX()
Definition: EmcID.cxx:99
static unsigned int getBARREL()
Definition: EmcID.cxx:146
static unsigned int getTHETA_BARREL_MIN()
Definition: EmcID.cxx:95
static unsigned int getIntID(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
Definition: EmcID.cxx:81
static unsigned int getTHETA_BARREL_MAX()
Definition: EmcID.cxx:91
static unsigned int getPHI_ENDCAP_MAX(const unsigned int theta)
Definition: EmcID.cxx:115
static unsigned int getPHI_ENDCAP_MIN()
Definition: EmcID.cxx:128
static unsigned int getPHI_BARREL_MIN()
Definition: EmcID.cxx:111
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")