BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcBuilder.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include "Identifier/MdcID.h"
5using namespace std;
6
8 :Builder()
9{
10 // set vector size (2^14) and initialize to -1
11 m_re2te = new uint32_t[16384]; // we have 2^14 different REID
12 memset((void*)m_re2te, 0xFF, 16384*sizeof(uint32_t));
13
15}
16
18{
19 delete m_re2te;
20}
21
22void MdcBuilder::unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TEData,
23 uint32_t &overFlow, uint32_t &TorQ)
24{
25 REId = (reDigi&m_idMask)>>m_idIndex;
26 //cout << "MdcBuilder::unPack reDigi: 0x" << hex << reDigi << " reid: 0x" << reid << dec << endl;
27 TEData = reDigi&m_dataMask;
28 overFlow = (reDigi&m_overflowMask)>>m_overflowIndex;
29 TorQ = (reDigi&m_TQMask)>>m_TQIndex;
30 //cout << "reid" << hex << reid << endl;
31 //cout << "teid" << hex << TEId << endl;
32 return;
33}
34
35StatusCode MdcBuilder::pack(MdcDigiCol* digiCol, WriteRawEvent*& re)
36{
37 if (digiCol == 0 ) {
38 cerr << "MdcBuilder::pack can't get digiCol" << endl;
39 return StatusCode::FAILURE;
40 }
41
42 uint32_t size = 0;
43 uint32_t teid = 0, tetdc = 0, teadc = 0, reid = 0, redigi = 0, overflow = 0;
44
45 MdcDigiCol::const_iterator pMdcDigi = digiCol->begin();
46 for (pMdcDigi; pMdcDigi!= digiCol->end(); pMdcDigi++) {
47 //zoujh+++++++++++, be consistent with DAQ raw data
48 Identifier id = (*pMdcDigi)->identify();
49 int layer = MdcID::layer(id), wire = MdcID::wire(id);
50 if ( layer == 20 && wire < 8 ) {
51 layer = 42;
52 }
53 else if ( layer == 42 && wire < 8 ) {
54 layer = 20;
55 }
56 else if ( layer == 40 ) {
57 if ( wire >= 200 && wire < 208 ) {
58 wire += 8;
59 }
60 else if ( wire >= 208 && wire < 216 ) {
61 wire -= 8;
62 }
63 }
64 //teid = (*pMdcDigi)->getIntId();
65 teid = MdcID::getIntID(layer, wire);
66 //zoujh-----------
67 reid = getREID(teid);
68 tetdc = (*pMdcDigi)->getTimeChannel();
69 teadc = (*pMdcDigi)->getChargeChannel();
70 // overflow
71 uint32_t overflow_tmp = (*pMdcDigi)->getOverflow();
72 // set tdc
73 if(tetdc!=0x7FFFFFFF){
74 overflow = ((tetdc > m_dataMask) ? 1 : 0) | (overflow_tmp&1);
75 redigi = (tetdc&m_dataMask)|
76 ((reid<<m_idIndex)&m_idMask)|
77 ((overflow<<m_overflowIndex)&m_overflowMask)|
78 ((0<<m_TQIndex)&m_TQMask);
79 m_buf[size++] = redigi;
80 }
81 // set adc
82 if(teadc!=0x7FFFFFFF){
83 overflow = ((teadc > m_dataMask) ? 1 : 0) | ((overflow_tmp>>1)&1);
84 redigi = (teadc&m_dataMask)|
85 ((reid<<m_idIndex)&m_idMask)|
86 ((overflow<<m_overflowIndex)&m_overflowMask)|
87 ((1<<m_TQIndex)&m_TQMask);
88 m_buf[size++] = redigi;
89 }
90 }
91
92 append2event(re, 0xa10000, size);
93
94 return StatusCode::SUCCESS;
95}
96
97// initialize re2te tables
98
99StatusCode MdcBuilder::initialize(string& initFile)
100{
101 ifstream f;
102
103 uint32_t NRELAYERPOS, NREWIREPOS, NREEAWEPOS;
104 uint32_t NRELAYERMASK, NREWIREMASK, NREEAWEMASK;
105
106
107 //-----------------------------------------------------------
108 // read initFile
109 f.open( initFile.c_str());
110
111 if( f.bad() ) {
112 cerr << "Error: could not open file " << initFile << endl;
113 return false;
114 }
115
116 if (!Builder::find( f, "##MdcDigiConf", initFile)) {
117 cerr << "Error: could not find '##MdcDigiConf' in file " << initFile << endl;
118 return StatusCode::FAILURE;
119 }
120
121 if( !Builder::expect( f, "#Index,mask", initFile) ||
122 !Builder::expectInt( f, "id", initFile, m_idIndex, m_idMask) ||
123 !Builder::expectInt( f, "data", initFile, m_dataIndex, m_dataMask) ||
124 !Builder::expectInt( f, "Overflow", initFile, m_overflowIndex, m_overflowMask) ||
125 !Builder::expectInt( f, "T/Q", initFile, m_TQIndex, m_TQMask) ||
126 !Builder::expectInt( f, "Wire", initFile, NREWIREPOS, NREWIREMASK) ||
127 !Builder::expectInt( f, "Layer", initFile, NRELAYERPOS, NRELAYERMASK) )
128 return false;
129
130 f.close();
131 //-----------------------------------------------------------
132 //Build re2te table
133 uint32_t nRELayerPos, nREWirePos, nREEaWePos;
134 uint32_t nRELayerMask, nREWireMask, nREEaWeMask;
135
136
137 uint32_t TELayerMax = MdcID::getAXIAL_LAYER_MAX()+MdcID::getSTEREO_LAYER_MAX()+1;
138 uint32_t TEWireMax = MdcID::getAXIAL_WIRE_MAX();
139
140 int i = 0;
141
142 uint32_t layer, wire;
143
144 nRELayerPos = NRELAYERPOS;
145 nREWirePos = NREWIREPOS;
146 nRELayerMask = NRELAYERMASK;
147 nREWireMask = NREWIREMASK;
148
149 for(uint32_t TELayer = 0; TELayer <= TELayerMax; TELayer++ )
150 {
151 layer = TELayer + 1;
152 // After Layer 32, there are changes in positions of Layers and wires
153 if(layer >= 0x20) {
154 layer = layer + i ;
155 i++;
156 nRELayerMask = nRELayerMask&0xFFFFFBFF;
157 nREWireMask = nREWireMask|0x00000400;
158 TEWireMax = MdcID::getAXIAL_WIRE_MAX();
159 }
160 else {
161 //When Layer is less than 32, the number of wire is less than 240 to prevent overflow;
162 TEWireMax = 240;
163 }
164
165 for(uint32_t TEWire = 0; TEWire <= TEWireMax; TEWire++ )
166 {
167 wire = TEWire + 1;
168 uint32_t reid = (((layer<<nRELayerPos)&nRELayerMask)|
169 ((wire<<nREWirePos)&nREWireMask))>>2;
170 //cout << "TELayer" << hex << TELayer;
171 //cout << " TEWire" << hex << TEWire;
172 //cout << " layer" << hex << layer;
173 //cout << " wire" << hex << wire;
174
175 uint32_t teid = MdcID::getIntID(TELayer, TEWire);
176
177 if( reid >= 16384 )
178 {
179 cerr << "Error: REID overflow !" << reid << endl;
180 exit(8);
181 }
182 //cout << " reid" << hex << reid;
183 //cout << " teid" << hex << teid << endl;
184 m_re2te[reid] = teid;
185 m_te2reMap.insert(TE2REMAP::value_type(teid, reid)) ;
186 }
187 }
188
189 // return successful initialization
190 return StatusCode::SUCCESS;
191}
192
193
194uint32_t MdcBuilder::getREID(uint32_t teid)
195{
196 TE2REMAP::iterator itr = m_te2reMap.find(teid);
197
198 if (itr == m_te2reMap.end()) {
199 cout << "wrong teid in mdc " << teid << endl;
200 exit(8);
201 }
202
203 return itr->second;
204}
205
ObjectVector< MdcDigi > MdcDigiCol
Definition: MdcDigi.h:39
void append2event(WriteRawEvent *&re, uint32_t source_id, uint32_t size)
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
virtual uint32_t getREID(uint32_t teid)
Definition: MdcBuilder.cxx:194
virtual ~MdcBuilder()
Definition: MdcBuilder.cxx:17
virtual StatusCode pack(MdcDigiCol *digiCol, WriteRawEvent *&re)
Definition: MdcBuilder.cxx:35
virtual StatusCode initialize(string &initFile)
Definition: MdcBuilder.cxx:99
virtual void unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TEData, uint32_t &overFlow, uint32_t &TorQ)
Definition: MdcBuilder.cxx:22
static value_type getAXIAL_LAYER_MAX()
Definition: MdcID.cxx:138
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static value_type getAXIAL_WIRE_MAX()
Definition: MdcID.cxx:146
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
static value_type getIntID(unsigned int wireType, unsigned int layer, unsigned int wire)
Definition: MdcID.cxx:124
static value_type getSTEREO_LAYER_MAX()
Definition: MdcID.cxx:142