BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
EFResult.cxx
Go to the documentation of this file.
1#include <iostream>
3
4EFResult::EFResult(std::vector<std::string> ans)
5 : m_answerVector(ans),
6 m_answerIndex(-1),
7 m_midanswerIndex(-1),
8 m_efVec()
9{
10}
11
12EFResult::EFResult(std::vector<uint32_t> vec, uint32_t pos) //pos start from 0
13 : m_answerVector(),
14 m_answerIndex(-1),
15 m_midanswerIndex(-1),
16 m_efVec()
17{
18 if(vec.size()+pos>54) {
19 std::cout <<"***EFResult:EFResult(): vector size error!" << std::endl;
20 m_efVec.resize(54,0);
21 }
22 else{
23 for(unsigned int i=0;i<54;++i){
24 if(i<pos||i>=vec.size()+pos) m_efVec.push_back(0);
25 else m_efVec.push_back(vec[i-pos]);
26 }
27 }
28}
29
31 m_answerVector(),
32 m_answerIndex(-1),
33 m_midanswerIndex(-1),
34 m_efVec()
35{
36
37}
38
40
41const CLID &EFResult::classID()
42{
43 return CLID_EFResult; // hxt ClassID_traits<EFResult>::ID();
44}
45
46const CLID &EFResult::clID() const
47{
48 return EFResult::classID();
49}
50
51const std::vector<uint32_t> EFResult::getEFVec() const
52{
53 return m_efVec;
54}
55const uint32_t EFResult::getEFVec(uint32_t pos) const
56{
57 if(pos>=m_efVec.size())return 0;
58 else return m_efVec[pos];
59}
60
61bool EFResult::push_back(uint32_t val){
62 if(m_efVec.size()>0&&m_efVec.size()<54) return false;
63 if(m_efVec.size()==0) m_efVec.resize(54,0);
64 m_efVec.push_back(val);
65 return true;
66}
67
68bool EFResult::appToEFVec(double val, uint32_t pos)
69{
70 if(pos>=54) return false;
71 if(m_efVec.size()!=0&&m_efVec.size()<54){
72 std::cout << "EFResult::appToEFVec-->size error!" <<std::endl;
73 }
74 if(m_efVec.size()==0) m_efVec.resize(54,0);
75 //m_efVec[pos]=val*1000000.;
76 float a=val;
77 m_efVec[pos]=*((uint32_t*)&a);
78 //double* p=m_efVec;
79 //p[pos]=val;
80 //std::cout <<"Before:"<<val<<"; "<<a<<"; After:"<<*((float*)(&(m_efVec[pos])))<<endl;
81 return true;
82}
83
84bool EFResult::addToEFVec(uint32_t val, uint32_t pos)
85{
86 if(pos>=54) return false;
87 if(m_efVec.size()!=0&&m_efVec.size()<54){
88 std::cout << "EFResult::addToEFVec-->size error!" <<std::endl;
89 }
90 if(m_efVec.size()==0) m_efVec.resize(54,0);
91
92 m_efVec[pos] +=val;
93
94 return true;
95}
96
97bool EFResult::setVecBit(uint32_t val, uint32_t vecpos,uint32_t bbegin,uint32_t bend)
98{
99 if(vecpos>=54) return false;
100 if(bend>=32||bbegin>bend) return false;
101 if(m_efVec.size()==0) m_efVec.resize(54,0);
102 uint32_t bits=0xFFFFFFFF>>(31-bend+bbegin);
103 m_efVec[vecpos]&= (~((bits)<<bbegin));
104 m_efVec[vecpos]|= (val&bits)<<bbegin;
105 return true;
106}
107
108bool EFResult::setVecBit(bool val,uint32_t vecpos,uint32_t bitpos)
109{
110 if(vecpos>=54) return false;
111 if(bitpos>=32) return false;
112 if(m_efVec.size()==0) m_efVec.resize(54,0);
113 if(val) m_efVec[vecpos]|=(1<<bitpos);
114 else m_efVec[vecpos]&=(~(1<<bitpos));
115 return true;
116}
117
118void EFResult::setAnswer(std::string &answer)
119{
120 int iCount = 0;
121
122 std::vector<std::string>::iterator itVs = m_answerVector.begin();
123 std::vector<std::string>::iterator endVs = m_answerVector.end();
124 for (;itVs != endVs && m_answerIndex == -1; ++itVs) {
125 if (*itVs == answer) {
126 m_answerIndex = iCount;
127
128 // Store the answer index in the first data member field
129 // zoujh: memory leak ... what's the use of m_efVec ?
130 //m_efVec.push_back(m_answerIndex);
131 }
132 iCount++;
133 }
134}
135
136void EFResult::setMidAnswer(std::string &answer)
137{
138 int iCount = 0;
139 //cout << "EFResult::setMidAnswer "<<answer<<" ("<<m_answerVector.size()<<")"<<endl;
140 std::vector<std::string>::iterator itVs = m_answerVector.begin();
141 std::vector<std::string>::iterator endVs = m_answerVector.end();
142 for (;itVs != endVs && m_answerIndex == -1; ++itVs) {
143 if (*itVs == answer) {
144 m_midanswerIndex = iCount;
145
146 // Store the answer index in the first data member field
147 // zoujh: memory leak ... what's the use of m_efVec ?
148 //m_efVec.push_back(m_answerIndex);
149 }
150 //cout<<(*itVs)<<endl;
151 iCount++;
152 }
153 //cout<<m_midanswerIndex<<endl;
154}
155
157{
158 m_answerIndex = -1;
159 m_midanswerIndex = -1;
160 if(m_efVec.size()>=54){
161 m_efVec.resize(54,0);
162 for(unsigned int i=0;i<m_efVec.size();++i) m_efVec[i]=0;
163 }
164 else if(m_efVec.size()!=0){
165 std::cout <<"EFResult::reset(): m_efVec size check error!"<<std::endl;
166 }
167}
168
169const std::string EFResult::getAnswer() const { return m_answerVector[m_answerIndex]; }
170
171const int EFResult::getAnswerIndex() const { return m_answerIndex; }
172
173const std::string EFResult::getMidAnswer() const { return m_answerVector[m_midanswerIndex]; }
174
175const int EFResult::getMidAnswerIndex() const { return m_midanswerIndex; }
Defines the EFResult RDO structure.
bool addToEFVec(uint32_t val, uint32_t pos)
Definition: EFResult.cxx:84
const std::string getAnswer() const
Definition: EFResult.cxx:169
const int getMidAnswerIndex() const
Definition: EFResult.cxx:175
static const CLID & classID()
Definition: EFResult.cxx:41
void setAnswer(std::string &answer)
Definition: EFResult.cxx:118
bool appToEFVec(double val, uint32_t pos)
Definition: EFResult.cxx:68
const int getAnswerIndex() const
Definition: EFResult.cxx:171
void setMidAnswer(std::string &answer)
Definition: EFResult.cxx:136
EFResult()
Definition: EFResult.cxx:30
virtual ~EFResult()
Definition: EFResult.cxx:39
const std::string getMidAnswer() const
Definition: EFResult.cxx:173
virtual const CLID & clID() const
Definition: EFResult.cxx:46
void reset()
Definition: EFResult.cxx:156
bool setVecBit(uint32_t val, uint32_t vecpos, uint32_t bbegin, uint32_t bend)
Definition: EFResult.cxx:97
const std::vector< uint32_t > getEFVec() const
Definition: EFResult.cxx:51
bool push_back(uint32_t val)
Definition: EFResult.cxx:61
dble_vec_t vec[12]
Definition: ranlxd.c:372