BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
MucBuilder.cxx
Go to the documentation of this file.
1#include "GaudiKernel/Bootstrap.h"
2#include "GaudiKernel/ISvcLocator.h"
3#include "GaudiKernel/IJobOptionsSvc.h"
4#include "Identifier/MucID.h"
6
7using namespace std;
8
10 :Builder()
11{
12 if (!m_fec2idFile.empty()) return;
13 m_propMgr.declareProperty("Fec2IdMap", m_fec2idFile);
14
15 // Get a pointer to the Job Options Service
16 IJobOptionsSvc* jobSvc;
17 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
18 jobSvc->setMyProperties("MucBuilder", &m_propMgr);
19
20 m_re2te = new uint32_t[1024];
21 strSqcVec = new uint32_t[1024];
22 memset((void*)m_re2te, 0xFF, 1024*sizeof(uint32_t));
23 memset((void*)strSqcVec, 0, 1024*sizeof(uint32_t));
24
25 initialize (m_fec2idFile);
26}
27
29{
30 delete m_re2te;
31 delete strSqcVec;
32}
33
34void MucBuilder::unPack(uint32_t reDigi, uint32_t& REId, uint32_t& FecData, uint32_t& StrSqc)
35{
36 uint32_t fecAddr = (reDigi&0xFFFF0000) >> 16;
37 uint32_t module = (fecAddr&0xF800) >> 5;
38 REId = (fecAddr&0x07FF) | module;
39 FecData = reDigi&0xFFFF;
40 StrSqc = strSqcVec[REId];
41 return;
42}
43
44StatusCode MucBuilder::pack(MucDigiCol* digiCol, WriteRawEvent*& re)
45{
46 if (digiCol == 0 ) {
47 cerr << "MdcBuilder::pack can't get digiCol" << endl;
48 return StatusCode::FAILURE;
49 }
50
51 uint32_t size = 0, index;
52 uint32_t teid, reid, channel;
53
54 MucDigiCol::const_iterator pMucDigi = digiCol->begin();
55 for (pMucDigi; pMucDigi!= digiCol->end(); pMucDigi++) {
56 teid = (*pMucDigi)->getIntId();
57 reid = getREID(teid&0xFFFFFFF0);
58 channel = (strSqcVec[reid] == 0) ? (0x8000>>(teid&0xF)) : (0x1<<(teid&0xF));
59 // set the value if the current reid has been in the buffer
60 for (index = 0; index < size; index++) {
61 if ((m_buf[index]>>16) == reid) {
62 m_buf[index] |= channel;
63 break;
64 }
65 }
66 // otherwise, append the current reid and value to the buffer
67 if (index == size) m_buf[size++] = ((reid << 16) | (channel));
68 }
69
70 append2event(re, 0xa40000, size);
71
72 return StatusCode::SUCCESS;
73}
74
75// initialize re2te tables
76StatusCode MucBuilder::initialize(string& fec2idFile)
77{
78 ifstream fs(fec2idFile.c_str());
79 if( fs.bad() ) {
80 cerr << "Error: could not open file " << fec2idFile << endl;
81 return false;
82 }
83
84 fs.ignore(256, '\n');
85
86 int fec, part, seg, layer, firstStr, strSqc;
87
88 for (int i = 0; i < 572; i++) {
89 fs >> fec >> part >> seg >> layer >> firstStr >> strSqc;
90 // reid ... teid
91 uint32_t reid = fec; // ?
92 uint32_t teid = MucID::getIntID(part, seg, layer, firstStr);
93 //if (strSqc < 0) teid |= 0x00F00000; // local teid
94
95 m_re2te[reid] = teid;
96 strSqcVec[reid] = strSqc + 1;
97 m_te2reMap.insert(TE2REMAP::value_type(teid, reid));
98 //cout << "teid " << teid << " reid " << reid << " strSqc " << strSqcVec[reid] << endl;
99 }
100
101 return StatusCode::SUCCESS;
102}
103
104uint32_t MucBuilder::getREID(uint32_t teid)
105{
106 TE2REMAP::iterator itr = m_te2reMap.find(teid);
107
108 if (itr == m_te2reMap.end()) {
109 cout << "wrong teid in muc " << teid << endl;
110 exit(8);
111 }
112
113 return itr->second;
114}
115
ObjectVector< MucDigi > MucDigiCol
Definition: MucDigi.h:29
void append2event(WriteRawEvent *&re, uint32_t source_id, uint32_t size, uint32_t shift=0)
Definition: Builder.cxx:76
virtual StatusCode pack(MucDigiCol *digiCol, WriteRawEvent *&re)
Definition: MucBuilder.cxx:44
virtual void unPack(uint32_t reDigi, uint32_t &REId, uint32_t &FecData, uint32_t &StrSqc)
Definition: MucBuilder.cxx:34
virtual StatusCode initialize(string &initFile)
Definition: MucBuilder.cxx:76
virtual ~MucBuilder()
Definition: MucBuilder.cxx:28
virtual uint32_t getREID(uint32_t teid)
Definition: MucBuilder.cxx:104
static value_type getIntID(int barrel_ec, int segment, int layer, int channel)
Definition: MucID.cxx:147