CGEM BOSS 6.6.5.h
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 float a=val;
76 float *f=(float*)&m_efVec[pos];
77 *f = a;
78 return true;
79}
80
81bool EFResult::addToEFVec(uint32_t val, uint32_t pos)
82{
83 if(pos>=54) return false;
84 if(m_efVec.size()!=0&&m_efVec.size()<54){
85 std::cout << "EFResult::addToEFVec-->size error!" <<std::endl;
86 }
87 if(m_efVec.size()==0) m_efVec.resize(54,0);
88
89 m_efVec[pos] +=val;
90
91 return true;
92}
93
94bool EFResult::setVecBit(uint32_t val, uint32_t vecpos,uint32_t bbegin,uint32_t bend)
95{
96 if(vecpos>=54) return false;
97 if(bend>=32||bbegin>bend) return false;
98 if(m_efVec.size()==0) m_efVec.resize(54,0);
99 uint32_t bits=0xFFFFFFFF>>(31-bend+bbegin);
100 m_efVec[vecpos]&= (~((bits)<<bbegin));
101 m_efVec[vecpos]|= (val&bits)<<bbegin;
102 return true;
103}
104
105bool EFResult::setVecBit(bool val,uint32_t vecpos,uint32_t bitpos)
106{
107 if(vecpos>=54) return false;
108 if(bitpos>=32) return false;
109 if(m_efVec.size()==0) m_efVec.resize(54,0);
110 if(val) m_efVec[vecpos]|=(1<<bitpos);
111 else m_efVec[vecpos]&=(~(1<<bitpos));
112 return true;
113}
114
115void EFResult::setAnswer(std::string &answer)
116{
117 int iCount = 0;
118
119 std::vector<std::string>::iterator itVs = m_answerVector.begin();
120 std::vector<std::string>::iterator endVs = m_answerVector.end();
121 for (;itVs != endVs && m_answerIndex == -1; ++itVs) {
122 if (*itVs == answer) {
123 m_answerIndex = iCount;
124
125 // Store the answer index in the first data member field
126 // zoujh: memory leak ... what's the use of m_efVec ?
127 //m_efVec.push_back(m_answerIndex);
128 }
129 iCount++;
130 }
131}
132
133void EFResult::setMidAnswer(std::string &answer)
134{
135 int iCount = 0;
136 //cout << "EFResult::setMidAnswer "<<answer<<" ("<<m_answerVector.size()<<")"<<endl;
137 std::vector<std::string>::iterator itVs = m_answerVector.begin();
138 std::vector<std::string>::iterator endVs = m_answerVector.end();
139 for (;itVs != endVs && m_answerIndex == -1; ++itVs) {
140 if (*itVs == answer) {
141 m_midanswerIndex = iCount;
142
143 // Store the answer index in the first data member field
144 // zoujh: memory leak ... what's the use of m_efVec ?
145 //m_efVec.push_back(m_answerIndex);
146 }
147 //cout<<(*itVs)<<endl;
148 iCount++;
149 }
150 //cout<<m_midanswerIndex<<endl;
151}
152
154{
155 m_answerIndex = -1;
156 m_midanswerIndex = -1;
157 if(m_efVec.size()>=54){
158 m_efVec.resize(54,0);
159 for(unsigned int i=0;i<m_efVec.size();++i) m_efVec[i]=0;
160 }
161 else if(m_efVec.size()!=0){
162 std::cout <<"EFResult::reset(): m_efVec size check error!"<<std::endl;
163 }
164}
165
166const std::string EFResult::getAnswer() const { return m_answerVector[m_answerIndex]; }
167
168const int EFResult::getAnswerIndex() const { return m_answerIndex; }
169
170const std::string EFResult::getMidAnswer() const { return m_answerVector[m_midanswerIndex]; }
171
172const int EFResult::getMidAnswerIndex() const { return m_midanswerIndex; }
Defines the EFResult RDO structure.
bool addToEFVec(uint32_t val, uint32_t pos)
Definition EFResult.cxx:81
const std::string getAnswer() const
Definition EFResult.cxx:166
const int getMidAnswerIndex() const
Definition EFResult.cxx:172
static const CLID & classID()
Definition EFResult.cxx:41
void setAnswer(std::string &answer)
Definition EFResult.cxx:115
bool appToEFVec(double val, uint32_t pos)
Definition EFResult.cxx:68
const int getAnswerIndex() const
Definition EFResult.cxx:168
void setMidAnswer(std::string &answer)
Definition EFResult.cxx:133
virtual ~EFResult()
Definition EFResult.cxx:39
const std::string getMidAnswer() const
Definition EFResult.cxx:170
virtual const CLID & clID() const
Definition EFResult.cxx:46
void reset()
Definition EFResult.cxx:153
bool setVecBit(uint32_t val, uint32_t vecpos, uint32_t bbegin, uint32_t bend)
Definition EFResult.cxx:94
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