BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
TofConverter.cxx
Go to the documentation of this file.
1#include "Identifier/TofID.h"
3
4TofConverter* TofConverter::s_instance = 0;
5
7{
8 if ( s_instance == 0 ) {
9 s_instance = new TofConverter();
10 }
11
12 return s_instance;
13}
14
16{
17 if ( s_instance != 0 ) {
18 delete s_instance;
19 s_instance = 0;
20 }
21}
22
23StatusCode TofConverter::convert(const BufferHolder& src, TofDigiCol* des, LumiDigiCol* des2)
24{
25 BufferHolder tmp;
26 return this->convert(src, tmp, des, des2);
27}
28
29StatusCode TofConverter::convert(const BufferHolder& tof,
30 const BufferHolder& etf,
31 TofDigiCol* des,
32 LumiDigiCol* des2)
33{
34 uint32_t REId, TEId, TEData, TEOverflow, TETorQ;
35 uint32_t n1buf = tof.nBuf();
36 uint32_t n2buf = etf.nBuf();
37 uint32_t nbuf = n1buf + n2buf;
38
39 TofDigi* tofDigi;
40 typedef std::multimap<uint32_t, TofDigi*>::iterator my_iter;
41 std::multimap<uint32_t, TofDigi*> mapIdData;
42 my_iter it;
43
44 for (uint32_t i = 0; i < nbuf; ++i) {
45 bool isTof = (i < n1buf);
46 const BufferHolder& rBH = isTof ? tof : etf;
47 uint32_t ii = isTof ? i : (i-n1buf);
48 uint32_t* buf = rBH(ii);
49 uint32_t bufSize = rBH.bufSize(ii);
50 for (uint32_t j = 0; j < bufSize; ++j) {
51 if ( isTof ) {
52 m_builder.unPack(buf[j], REId, TEData, TEOverflow, TETorQ);
53 TEId = m_builder.getTEID( REId);
54 }
55 else { //ETF
56 this->unPackETF(buf[j], TEId, TEData, TEOverflow, TETorQ);
57 }
58
59 if ( TEId == 0xFFFFFFFF ) {
60 uint32_t data_unit = buf[j];
61 if ( (data_unit >> 25) == 0x7F ) {
62 tofDigi = new TofDigi(Identifier(0xFFFFFFFF), 0x7FFFFFFF, 0x7FFFFFFF);
63 tofDigi->setOverflow(data_unit);
64 des->push_back(tofDigi);
65 }
66 continue;
67 }
68
69 uint32_t count = mapIdData.count(TEId);
70
71 if (count == 0) {
72 if (TETorQ) { //Q
73 tofDigi = new TofDigi(Identifier(TEId), 0x7FFFFFFF, TEData);
74 tofDigi->setOverflow(0x10 | (TEOverflow<<1));
75 }
76 else { //T
77 tofDigi = new TofDigi(Identifier(TEId), TEData, 0x7FFFFFFF);
78 tofDigi->setOverflow(0x20 | TEOverflow);
79 }
80 mapIdData.insert(make_pair(TEId, tofDigi));
81 }
82 else {
83 pair<my_iter, my_iter> range = mapIdData.equal_range(TEId);
84 it = range.first;
85 tofDigi = it->second;
86 if (TETorQ) { //Q
87 if (tofDigi->getChargeChannel() == 0x7FFFFFFF) { //matched Q and T, first Q
88 tofDigi->setChargeChannel(TEData);
89 tofDigi->setOverflow((tofDigi->getOverflow() | (TEOverflow<<1)) & 0xF);
90 while ((++it) != range.second) { //multiT
91 tofDigi = it->second;
92 tofDigi->setOverflow(tofDigi->getOverflow() & 0xF);
93 }
94 }
95 else { //multiQ
96 uint32_t flag = (tofDigi->getOverflow() & 0x3C) | 8;
97 while (it != range.second) {
98 tofDigi = (it++)->second;
99 tofDigi->setOverflow((tofDigi->getOverflow()&0x3) | flag);
100 }
101 tofDigi = new TofDigi(Identifier(TEId), 0x7FFFFFFF, TEData);
102 tofDigi->setOverflow(flag | (TEOverflow<<1));
103 mapIdData.insert(make_pair(TEId, tofDigi));
104 }
105 }
106 else { //T
107 if (tofDigi->getTimeChannel() == 0x7FFFFFFF) { //matched T and Q, firstT
108 tofDigi->setTimeChannel(TEData);
109 tofDigi->setOverflow((tofDigi->getOverflow() | TEOverflow) & 0xF);
110 while ((++it) != range.second) { //multiQ
111 tofDigi = it->second;
112 tofDigi->setOverflow(tofDigi->getOverflow() & 0xF);
113 }
114 }
115 else { //multiT
116 uint32_t flag = (tofDigi->getOverflow() & 0x3C) | 4;
117 while (it != range.second) {
118 tofDigi = (it++)->second;
119 tofDigi->setOverflow((tofDigi->getOverflow()&0x3) | flag);
120 }
121 tofDigi = new TofDigi(Identifier(TEId), TEData, 0x7FFFFFFF);
122 tofDigi->setOverflow(flag | TEOverflow);
123 mapIdData.insert(make_pair(TEId, tofDigi));
124 }
125 }
126 }
127 }
128 }
129
130 my_iter end = mapIdData.end();
131 for (it = mapIdData.begin(); it != end; ++it) {
132 TEId = it->first;
133 tofDigi = it->second;
134 if ( (TEId&0xFFFF7FFF) != 0x20000060 ) {
135 des->push_back(tofDigi);
136 }
137 //zoujh: for luminosity
138 else {
139 if (des2 != 0) {
140 des2->push_back(new LumiDigi(tofDigi));
141 }
142 delete tofDigi;
143 }
144 }
145
146 return StatusCode::SUCCESS;
147}
148
150{
151 return m_builder.pack(src, des);
152}
153
154TofConverter::TofConverter()
155{
156}
157
158TofConverter::~TofConverter()
159{
160}
161
162void TofConverter::unPackETF(uint32_t reDigi, uint32_t& TEId, uint32_t& TEData,
163 uint32_t& TEOverflow, uint32_t& TETorQ)
164{
165 if ( (reDigi>>25) == 0x7F ) { //Error data!
166 TEId = 0xFFFFFFFF;
167 return;
168 }
169 int ew = reDigi>>31;
170 int id = ((reDigi>>25)&0x3F);
171 int pad = ((reDigi>>21)&0xF);
172 int sb = ((reDigi>>20)&1);
173
174 TEId = TofID::getIntID(3/*barrel_ec, 3 means ETF*/, ew, id, pad, sb);
175 TEData = reDigi&0x7FFFF;
176 TEOverflow = 0;
177 TETorQ = ((reDigi>>19)&1);
178}
DOUBLE_PRECISION count[3]
ObjectVector< LumiDigi > LumiDigiCol
Definition: LumiDigi.h:36
ObjectVector< TofDigi > TofDigiCol
Definition: TofDigi.h:41
uint32_t nBuf() const
Definition: BufferHolder.h:15
uint32_t bufSize(int i) const
Definition: BufferHolder.h:16
void setChargeChannel(const unsigned int chargeChannel)
Definition: RawData.cxx:30
unsigned int getChargeChannel() const
Definition: RawData.cxx:45
void setTimeChannel(const unsigned int timeChannel)
Definition: RawData.cxx:25
unsigned int getTimeChannel() const
Definition: RawData.cxx:40
virtual uint32_t getTEID(uint32_t reid)
Definition: TofBuilder.h:16
virtual StatusCode pack(TofDigiCol *digiCol, WriteRawEvent *&re)
Definition: TofBuilder.cxx:38
virtual void unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TEData, uint32_t &overFlow, uint32_t &TorQ)
Definition: TofBuilder.cxx:22
static void destroy()
StatusCode convert(const BufferHolder &src, TofDigiCol *des, LumiDigiCol *des2=0)
static TofConverter * instance()
Definition: TofConverter.cxx:6
unsigned int getOverflow()
Definition: TofDigi.h:26
void setOverflow(const unsigned int overflow)
Definition: TofDigi.h:23
static value_type getIntID(int barrel_ec, int layer, int phi_module, int end)
Definition: TofID.cxx:178