BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcConverter.cxx
Go to the documentation of this file.
1#include "Identifier/MdcID.h"
4
5MdcConverter* MdcConverter::s_instance = 0;
6
8{
9 if ( s_instance == 0 ) {
10 s_instance = new MdcConverter(runMode);
11 }
12
13 return s_instance;
14}
15
17{
18 if ( s_instance != 0 ) {
19 delete s_instance;
20 s_instance = 0;
21 }
22}
23
24void MdcConverter::init(const SniperJSON& config)
25{
26 for ( SniperJSON::vec_iterator it = config.vec_begin(); it != config.vec_end(); ++it )
27 {
28 IdFixRule rule;
29 rule.run_from = (*it)["RunFrom"].get<int>();
30 rule.run_to = (*it)["RunTo"].get<int>();
31 rule.mask = (*it)["Mask"].get<uint32_t>();
32 rule.reverse_mask = ~rule.mask;
33 rule.value1 = (*it)["Value1"].get<uint32_t>();
34 rule.value2 = (*it)["Value2"].get<uint32_t>();
35 m_idFixRules.push_back(rule);
36 }
37
38 memset((void*)m_mdcTag, 0, 16384*4*4);
39}
40
41StatusCode MdcConverter::convert(const BufferHolder& src, MdcDigiCol* des)
42{
43 //int digiId = 0;
44 uint32_t TEId, REId, TEData, TEOverflow, TETorQ;
45
46 typedef pair<uint32_t, uint32_t> PairII;
47 vector<uint32_t> vHits;
48 vector<PairII> vmTDC;
49
50 uint32_t* curTag;
51 ////////////////////////////////////
52
53 uint32_t nbuf = src.nBuf();
54
55 for (uint32_t i = 0; i < nbuf; ++i)
56 {
57 uint32_t* buf = src(i);
58 uint32_t* bufend= buf + src.bufSize(i);
59 for ( ; buf < bufend; ++buf /*, ++digiId*/)
60 {
61 uint32_t digi = *buf;
62 if (((digi>>18) & 0x3FFF) == 0) {
63 //digiId--;
64 continue;
65 }
66
67 m_builder.unPack(digi, REId, TEData, TEOverflow, TETorQ);
68
69 TEId = m_builder.getTEID( REId );
70 if ( TEId == 0xFFFFFFFF ) continue;
71
72 curTag = m_mdcTag[REId];
73
74 if ( curTag[0] == 0 ) { //1st signal from detector-unit-REId
75 curTag[1] = 0x7FFFFFFF;
76 curTag[2] = 0x7FFFFFFF;
77 curTag[3] = 0;
78
79 //uint32_t oTEId = TEId;
80
81 for ( std::vector<IdFixRule>::iterator it = m_idFixRules.begin(); it != m_idFixRules.end(); ++it ) {
82 IdFixRule& rule = (*it);
83 if ( m_runId >= rule.run_from && m_runId <= rule.run_to ) {
84 if ((TEId&rule.mask) == rule.value1) {
85 TEId = (TEId&rule.reverse_mask) | rule.value2;
86 curTag[3] |= 0x10;
87 }
88 else if ((TEId&rule.mask) == rule.value2) {
89 TEId = (TEId&rule.reverse_mask) | rule.value1;
90 curTag[3] |= 0x10;
91 }
92 }
93 }
94
95 //if ( curTag[3] != 0 ) {
96 // std::cout << " From TEId 0x" << std::hex << oTEId << std::dec
97 // << " : " << MdcID::layer(Identifier(oTEId)) << " " << MdcID::wire(Identifier(oTEId))
98 // << std::endl;
99 // std::cout << " To TEId 0x" << std::hex << TEId << std::dec
100 // << " : " << MdcID::layer(Identifier(TEId)) << " " << MdcID::wire(Identifier(TEId))
101 // << std::endl;
102 //}
103
104 curTag[0] = (TEId << 2);
105
106 vHits.push_back( REId );
107 }
108
109 if ( TETorQ == 0 ) { //T
110 if ( (curTag[0]&1) == 0 ) { //1st-found-T
111 curTag[0] |= 1;
112 curTag[1] = TEData;
113 curTag[3] |= TEOverflow; //0 or 1
114 }
115 else { //multi-T
116 curTag[3] |= 0xC; //12, set the multi-T and 1st-T bits
117 if ( TEData >= curTag[1] ) {
118 if ( TEOverflow ) TEData |= (1<<31); //LastBit
119 vmTDC.push_back( make_pair(REId, TEData) );
120 }
121 else {
122 if ( curTag[3] & 1 ) curTag[1] |= (1<<31);
123 vmTDC.push_back( make_pair(REId, curTag[1]) );
124 curTag[1] = TEData;
125 curTag[3] &= (0xFFFFFFFF-1);
126 curTag[3] |= TEOverflow;
127 }
128 }
129 }
130 else { //Q
131 curTag[0] |= 2;
132 curTag[2] = TEData;
133 if ( TEOverflow ) curTag[3] |= 2;
134 }
135 }
136 }
137
138 MdcDigi* mdcDigi;
139 if ( m_runMode == 1 ) { //OnlineMode, discard the hits that only have T or Q
140 for ( vector<PairII>::iterator it = vmTDC.begin(); it != vmTDC.end(); ++it ) {
141 curTag = m_mdcTag[it->first];
142 if ( (curTag[0]&3) == 3 ) {
143 uint32_t data = it->second;
144 if(data>>31) continue;
145 mdcDigi = new MdcDigi(Identifier(curTag[0]>>2), (data&0x7FFFFFFF), curTag[2]);
146 mdcDigi->setOverflow( (curTag[3] & 0x16) | (data>>31) );
147 des->push_back(mdcDigi);
148 }
149 }
150
151 for ( vector<uint32_t>::iterator it = vHits.begin(); it != vHits.end(); ++it) {
152 curTag = m_mdcTag[*it];
153 if ( (curTag[0]&3) == 3 ) {
154 if( ((curTag[3]&3)>0) || (((curTag[3]&12)!=12) && ((curTag[3]&12)!=0)) ) {
155 curTag[0] = 0;
156 continue;
157 }
158 mdcDigi = new MdcDigi(Identifier(curTag[0]>>2), curTag[1], curTag[2]);
159 mdcDigi->setOverflow(curTag[3]);
160 des->push_back(mdcDigi);
161 }
162 curTag[0] = 0;
163 }
164 }
165 else { //Not OnlineMode, keep all the hits found
166 for ( vector<PairII>::iterator it = vmTDC.begin(); it != vmTDC.end(); ++it ) {
167 curTag = m_mdcTag[it->first];
168 uint32_t data = it->second;
169 mdcDigi = new MdcDigi(Identifier(curTag[0]>>2), (data&0x7FFFFFFF), curTag[2]);
170 mdcDigi->setOverflow( (curTag[3] & 0x16) | (data>>31) );
171 des->push_back(mdcDigi);
172 }
173
174 for ( vector<uint32_t>::iterator it = vHits.begin(); it != vHits.end(); ++it) {
175 curTag = m_mdcTag[*it];
176 mdcDigi = new MdcDigi(Identifier(curTag[0]>>2), curTag[1], curTag[2]);
177 mdcDigi->setOverflow(curTag[3]);
178 des->push_back(mdcDigi);
179 curTag[0] = 0;
180 }
181 }
182
183 ////////////////////////////////////
184 return StatusCode::SUCCESS;
185}
186
188{
189 return m_builder.pack(src, des);
190}
191
192MdcConverter::MdcConverter(int runMode)
193 : m_runMode( runMode )
194{
195}
196
197MdcConverter::~MdcConverter()
198{
199}
TTree * data
ObjectVector< MdcDigi > MdcDigiCol
Definition MdcDigi.h:39
uint32_t nBuf() const
uint32_t bufSize(int i) const
virtual uint32_t getTEID(uint32_t reid)
Definition MdcBuilder.h:16
virtual StatusCode pack(MdcDigiCol *digiCol, WriteRawEvent *&re)
virtual void unPack(uint32_t reDigi, uint32_t &REId, uint32_t &TEData, uint32_t &overFlow, uint32_t &TorQ)
static MdcConverter * instance(int runMode=2)
static void destroy()
StatusCode convert(const BufferHolder &src, MdcDigiCol *des)
void init(const SniperJSON &config)
void setOverflow(const unsigned int overflow)
Definition MdcDigi.h:23
std::vector< SniperJSON >::const_iterator vec_iterator
Definition SniperJSON.h:11
vec_iterator vec_end() const
Definition SniperJSON.h:52
vec_iterator vec_begin() const
Definition SniperJSON.h:50