CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
StripSrv.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/calibUtil/src/StripSrv.cxx,v 1.1.1.1 2005/10/17 06:12:26 maqm Exp $
2/// Module provides methods for clients to get strip services.
3
4#include "xmlBase/XmlParser.h"
5#include "xmlBase/Dom.h"
6#include <xercesc/dom/DOMElement.hpp>
7#include <xercesc/dom/DOMNodeList.hpp>
8#include <xercesc/dom/DOMTreeWalker.hpp>
9
10#include <string>
11#include <iostream>
12#include <vector>
13#include <cstdlib>
14#include <memory>
15
17#include "calibUtil/StripSrv.h"
19
20namespace calibUtil {
21
22 using XERCES_CPP_NAMESPACE_QUALIFIER DOMElement;
23
25 : m_badType(badType), m_state(BUILDING) {
26 m_genSrv = new GenericSrv(gen);
27 }
28
29 // Initialize the data structures by parsing the XML file
30 StripSrv::StripSrv(std::string xmlFileName) : m_badType(UNKNOWN_BADTYPE),
31 m_state(FROM_PERS),
32 m_genSrv(0)
33 {
34 using xmlBase::Dom;
35 using XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument;
36
38 DOMDocument* doc = parser->parse(xmlFileName.c_str());
39
40 if (doc == 0) {
41 std::cerr << "Error parsing document" << xmlFileName << std::endl;
42 return;
43 }
44
45 DOMElement* docElt = doc->getDocumentElement();
46 m_genSrv = new GenericSrv(docElt);
47
48 std::vector<DOMElement *> towers;
49
50 Dom::getDescendantsByTagName(docElt, "tower", towers);
51 unsigned nTower = towers.size();
52
53 m_towers.reserve(nTower);
54
55 std::string bString = Dom::getAttribute(docElt,"badType");
56 if (!bString.compare("hot")) m_badType = HOT;
57 else if (!bString.compare("dead")) m_badType = DEAD;
58 else m_badType = UNKNOWN_BADTYPE;
59
60
61 for (unsigned int iTower = 0; iTower < nTower; iTower++) {
62 Tower tower;
63 tower.m_uniplanes.clear();
64 try {
65 tower.m_row = Dom::getIntAttribute(towers[iTower], "row");
66 tower.m_col = Dom::getIntAttribute(towers[iTower], "col");
67 }
68 catch (xmlBase::DomException ex) {
69 std::cerr << "From calibUtil::StripSrv::StripSrv" << std::endl
70 << ex.getMsg() << std::endl;
71 throw ex;
72 }
73
74 tower.m_howBad = 0;
75 tower.m_allBad = 0;
76
77 std::string attValue = Dom::getAttribute(towers[iTower], "nOnbdCalib");
78 if (attValue.compare("true") == 0) {
79 tower.m_howBad |= vCALIBUTIL_nOnbdCalib;
80 }
81 attValue = Dom::getAttribute(towers[iTower], "nOnbdTrig");
82 if (attValue.compare("true") == 0) {
83 tower.m_howBad |= vCALIBUTIL_nOnbdTrig;
84 }
85 attValue = Dom::getAttribute(towers[iTower], "nOnbdData");
86 if (attValue.compare("true") == 0) {
87 tower.m_howBad |= vCALIBUTIL_nOnbdData;
88 }
89 if (tower.m_howBad) {
90 tower.m_allBad = 1;
91 goto NEXT;
92 } // otherwise have to process individual uniplane elements
93
94 {
95 DOMElement* uniElt = Dom::getFirstChildElement(towers[iTower]);
96
97 while (uniElt != 0) {
98 Uniplane uni;
99 uni.m_howBad = 0;
100 fillUni(uniElt, &uni);
101 // if bad status, complain and return
102
103 tower.m_uniplanes.push_back(uni);
104 uniElt = Dom::getSiblingElement(uniElt);
105 }
106 }
107 NEXT:
108 m_towers.push_back(tower);
109 // towerElt = Dom::getSiblingElement(towerElt);
110 }
111 }
112
113 /// destructor used to deallocate memory
115 delete m_genSrv;
116 }
117
118 /// returns the status (Hot or Dead) of the strips
120 return m_badType;
121 }
122
123 /// Lists all towers with bad strips
124 void StripSrv::getBadTowers(std::vector<StripSrv::towerRC>& towerRCs) const
125 {
126 std::vector<Tower>::const_iterator it = m_towers.begin();
127 while(it != m_towers.end() ) {
128
129 towerRC trc;
130 towerRCs.reserve(m_towers.size());
131 trc.row = it->m_row;
132 trc.col = it->m_col;
133 towerRCs.push_back(trc);
134 it++;
135 }
136 }
137
138 /// methods giving access to generic data
139
140 /// Get instrument name
141 std::string StripSrv::getInst() const {
142 return m_genSrv->getInst();
143 }
144
145 /// Get timestamp
146 std::string StripSrv::getTimestamp() const {
147 return m_genSrv->getTimestamp();
148 }
149
150 /// Get calibration type
151 std::string StripSrv::getCalType() const {
152 return m_genSrv->getCalType();
153 }
154
155 /// Get format Version
156 std::string StripSrv::getFmtVer() const {
157 return m_genSrv->getFmtVer();
158 }
159
160
161 /// call back method for client to access large data
163
164 /* NOTE: could also check for empty badLists and only
165 call back client if nonempty.
166 */
167 std::vector<Tower>::const_iterator iTower = m_towers.begin();
168
169 eVisitorRet ret = DONE;
170 while (iTower != m_towers.end() ) {
171 if (iTower->m_allBad) {
172 ret = client->badTower(iTower->m_row, iTower->m_col, iTower->m_howBad);
173 if (ret != CONT) return ret;
174 }
175 // If tower not all bad, loop over planes within towers
176 else {
177 std::vector<Uniplane>::const_iterator iUni =
178 (iTower->m_uniplanes).begin();
179 while (iUni != (iTower->m_uniplanes).end() ) {
180 ret = client->badPlane(iTower->m_row, iTower->m_col,
181 iUni->m_tray, iUni->m_top,
182 iUni->m_howBad, iUni->m_allBad,
183 (iUni->m_strips));
184 if (ret != CONT) return ret;
185 iUni++;
186 }
187 }
188 ++iTower;
189 }
190 // If got to here, traversed the entire data structure without
191 // a murmur from client
192 return DONE;
193 }
194
195 // Private utilities
196
197 void StripSrv::fillUni(const DOMElement* uniElt, Uniplane *uni) {
198 using xmlBase::Dom;
199
200 std::string attValue;
201
202 attValue = Dom::getAttribute(uniElt, "allBad");
203 uni->m_allBad = (attValue.compare("true") == 0);
204
205 attValue = Dom::getAttribute(uniElt, "nOnbdCalib");
206 if (attValue.compare("true") == 0) {
207 uni->m_howBad |= vCALIBUTIL_nOnbdCalib;
208 }
209 attValue = Dom::getAttribute(uniElt, "nOnbdTrig");
210 if (attValue.compare("true") == 0) {
211 uni->m_howBad |= vCALIBUTIL_nOnbdTrig;
212 }
213 attValue = Dom::getAttribute(uniElt, "nOnbdData");
214 if (attValue.compare("true") == 0) {
215 uni->m_howBad |= vCALIBUTIL_nOnbdData;
216 }
217
218 attValue = Dom::getAttribute(uniElt, "tray");
219 uni->m_tray = atoi(attValue.c_str());
220
221 attValue = Dom::getAttribute(uniElt, "which");
222 if (attValue.compare("top") == 0) uni->m_top = true;
223 else if (attValue.compare("bot") == 0) uni->m_top = false;
224 // if anything else happens, xml file is bad
225
226 if (!uni->m_allBad) { // process strip lists, spans
227 fillStrips(uniElt, uni->m_strips);
228 }
229 }
230
231
232 void StripSrv::fillStrips(const DOMElement* badElt, StripCol& list) {
233 using xmlBase::Dom;
234
235 DOMElement* childElt = Dom::getFirstChildElement(badElt);
236
237 while (childElt != 0 ) {
238 // must be list or span
239 if (Dom::checkTagName(childElt, "stripList")) {
240 std::string xmlList = Dom::getAttribute(childElt, "strips");
241 strToNum(xmlList, list);
242 }
243 else if (Dom::checkTagName(childElt, "stripSpan")) {
244 unsigned short first, last;
245
246 try {
247 first = Dom::getIntAttribute(childElt, "first");
248 last = Dom::getIntAttribute(childElt, "last");
249 }
250 catch (xmlBase::DomException ex) {
251 std::cerr << "From calibUtil::StripSrv::fillStrips" << std::endl
252 << ex.getMsg() << std::endl;
253 throw ex;
254 }
255
256 if (last >= first) {
257 // Might as well reserve memory all at once
258 list.reserve(list.size() + last + 1 - first);
259 for (unsigned short int i = first; i <= last; i++) {
260 list.push_back(i);
261 }
262 }
263 }
264 childElt = Dom::getSiblingElement(childElt);
265 }
266 }
267
268 void StripSrv::strToNum(std::string s, std::vector<unsigned short int> &v){
269
270 std::string::iterator it = s.begin();
271
272 // Maybe add something to be sure all we've got are digits
273 // and blanks??
274
275 // Skip over leading blanks, if any
276 while((it != s.end()) && (*it == ' ')) it++;
277
278 // save contiguous digits in tempStr
279 while ((it != s.end()) && (*it >= '0') && (*it <= '9')) {
280 std::string tempStr;
281 tempStr += *it;
282 it++;
283
284 while((it != s.end()) && (*it >= '0') && (*it <= '9')){
285 tempStr += *it;
286 it++;
287 }
288
289 // No more contiguous digits; skip over blanks
290 while((it != s.end()) && (*it == ' ')) it++;
291
292 // Save the converted integer
293 v.push_back(atoi(tempStr.c_str()));
294 }
295
296 }
297
298 StripSrv::Tower* StripSrv::findTower(towerRC& towerId) {
299 std::vector<Tower>::iterator it = m_towers.begin();
300 while(it != m_towers.end() ) {
301 if ((it->m_row == towerId.row) && (it->m_col == towerId.col)) {
302 return (&(*it));
303 }
304 ++it;
305 }
306 return 0;
307 }
308
309 const StripSrv::Tower* StripSrv::findTower(const towerRC& towerId) const {
310 std::vector<Tower>::const_iterator it = m_towers.begin();
311 while(it != m_towers.end() ) {
312 if ((it->m_row == towerId.row) && (it->m_col == towerId.col)) {
313 return (&(*it));
314 }
315 ++it;
316 }
317 return 0;
318 }
319
321 return DONE;
322 }
323
324
325}// end of namespace calibUtil
#define vCALIBUTIL_nOnbdCalib
#define vCALIBUTIL_nOnbdData
#define vCALIBUTIL_nOnbdTrig
XmlRpcServer s
Definition: HelloServer.cpp:11
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
virtual eVisitorRet badTower(unsigned int row, unsigned int col, int badness)=0
virtual eVisitorRet badPlane(unsigned int row, unsigned int col, unsigned int tray, bool top, int badness, bool allBad, const StripCol &strips)=0
std::string getFmtVer()
Get format Version.
Definition: GenericSrv.h:46
std::string getInst()
Get instrument name.
Definition: GenericSrv.h:31
std::string getCalType()
Get calibration type.
Definition: GenericSrv.h:41
std::string getTimestamp()
Get timestamp.
Definition: GenericSrv.h:36
eVisitorRet writeXml(std::ostream *out)
Definition: StripSrv.cxx:320
eBadType getBadType() const
returns the status (Hot or Dead) of the strip
Definition: StripSrv.cxx:119
StripSrv(std::string xmlFileName)
Definition: StripSrv.cxx:30
std::string getInst() const
methods giving access to generic data
Definition: StripSrv.cxx:141
std::string getCalType() const
Get calibration type.
Definition: StripSrv.cxx:151
eVisitorRet traverseInfo(ClientObject *client) const
call back method for client to access large data
Definition: StripSrv.cxx:162
std::string getTimestamp() const
Get timestamp.
Definition: StripSrv.cxx:146
~StripSrv()
destructor. Deallocates memory
Definition: StripSrv.cxx:114
void getBadTowers(std::vector< towerRC > &towerIds) const
lists all towers with bad strips
Definition: StripSrv.cxx:124
std::string getFmtVer() const
Get format Version.
Definition: StripSrv.cxx:156
Base exception class for Dom.
Definition: Dom.h:29
virtual std::string getMsg()
Definition: Dom.h:34
DOMDocument * parse(const char *const filename, const std::string &docType=std::string(""))
Parse an xml file, returning document node if successful.
Definition: XmlParser.cxx:108
Index first(Pair i)
Definition: EvtCyclic3.cc:195
Module implements methods for clients to get generic services.
std::vector< unsigned short int > StripCol
Definition: StripSrv.h:24
Clients should use as return values for readData.
Definition: StripSrv.h:67
unsigned short int col
Definition: StripSrv.h:69
unsigned short int row
Definition: StripSrv.h:68