BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
MyFrame.cxx
Go to the documentation of this file.
1#include "HltConfig/MyFrame.h"
5
6#include "xercesc/framework/XMLFormatter.hpp"
7#include "xercesc/util/PlatformUtils.hpp"
8#include "xercesc/util/XMLString.hpp"
9#include "xercesc/util/XMLUniDefs.hpp"
10#include "xercesc/util/TranscodingException.hpp"
11#include "xercesc/parsers/XercesDOMParser.hpp"
12
13#include <xercesc/dom/DOM.hpp>
14
15namespace HltProcessor
16{
17
18// Necessary for singleton pattern for MyFrame
19MyFrame* MyFrame::s_FrameInstance = 0;
20
21// Necessary for singleton pattern for MyFrame: The instance method.
23 if(s_FrameInstance == 0) {
24 s_FrameInstance = new MyFrame;
25 }
26 return s_FrameInstance;
27}
29 if (s_FrameInstance) delete s_FrameInstance;
30}
31
32// Constructor
34 m_FrameNumSequenceTables(0),m_FrameNumTables(0),
35 m_FrameAbsolutMaxStep(0),
36 m_Signature_DocNode(NULL), m_Sequence_DocNode(NULL),
37 m_SignatureVec(0),m_SequenceVec(0),m_TableVector(0),
38 m_idSequence(0),m_idSignature(0),m_idCriteria(0),m_idItem(0),
39 m_first(true)
40{
41 if(s_FrameInstance){
42 std::cout << " MyFrame constructed twice!"<< std::endl;
43 }
44 s_FrameInstance=this;
45 m_thisName = "HltConfig";
46 m_msgSvcProvider = MessageSvcProvider::instance();
47}
48
49// Destructor
51{
52 for (unsigned int i = 0; i < m_SignatureVec.size(); i++) delete m_SignatureVec[i];
53 for (unsigned int j = 0; j < m_SequenceVec.size(); j++) delete m_SequenceVec[j];
54 //destruct();
55}
56
57// Initialisation, execution and finalization routines.
58void MyFrame::init(const std::string sequenceFile, const std::string signatureFile)
59{
60 //if(m_msgSvcProvider==0)m_msgSvcProvider = MessageSvcProvider::instance();
61 //MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
62 //MsgStream log(messageService(),name());
63 //std::cout<<"@@@@@@@@@@@@@@@@@@@1"<<std::endl;
64 try {
65 XMLPlatformUtils::Initialize();
66 //log << MSG::INFO << "MyFrame : Initialized XML!" << endreq;
67 }
68
69 catch (const XMLException& toCatch) {
70 //log << MSG::ERROR << "MyFrame : Init failed!" << endreq;
71 exit(1);
72 }
73 //std::cout<<"@@@@@@@@@@@@@@@@@@@2"<<std::endl;
74 // Instantiate DOM parser for signature XML file.
75 XercesDOMParser* signatureParser = new XercesDOMParser;
76 signatureParser->setValidationScheme(XercesDOMParser::Val_Always); // optional.
77 signatureParser->setDoNamespaces(true); // optional
78
79 // Instantiate DOM parser for sequence XML file.
80 XercesDOMParser* sequenceParser = new XercesDOMParser;
81 sequenceParser->setValidationScheme(XercesDOMParser::Val_Always); // optional.
82 sequenceParser->setDoNamespaces(true); // optional
83
84 // Now try to parse.
85 try {
86 signatureParser->parse(signatureFile.c_str());
87 //zoujh:log << MSG::INFO << "Parsing " << signatureFile.c_str() << endreq;
88
89 sequenceParser->parse(sequenceFile.c_str());
90 //zoujh:log << MSG::INFO << "Parsing " << sequenceFile.c_str() << endreq;
91 }
92
93 catch (const XMLException& toCatch) {
94 //log << MSG::ERROR << "Error 1" << endreq;
95 exit(1);
96 }
97 catch (const DOMException& toCatch) {
98 //log << MSG::ERROR << "Error 4" << endreq;
99 XMLPlatformUtils::Terminate();
100 exit(1);
101 }
102 catch (...) {
103 //log << MSG::ERROR << "Error 5" << endreq;
104 XMLPlatformUtils::Terminate();
105 exit(1);
106 }
107 //std::cout<<"@@@@@@@@@@@@@@@@@@@3"<<std::endl;
108 // Get document handle.
109 m_Sequence_DocNode = sequenceParser->getDocument();
110 m_Signature_DocNode = signatureParser->getDocument();
111 //std::cout<<"1@@@@@@@@@@@@@@@@@@@"<<m_SequenceVec.size()<<std::endl;
112 //std::cout<<"2@@@@@@@@@@@@@@@@@@@"<<m_SignatureVec.size()<<std::endl;
113 //std::cout<<"3@@@@@@@@@@@@@@@@@@@"<<m_TableVector.size()<<std::endl;
114 if(m_first){
115 m_first=false;
116 }
117 else{
118 for (unsigned int i = 0; i < m_SignatureVec.size(); i++) delete m_SignatureVec[i];
119 for (unsigned int j = 0; j < m_SequenceVec.size(); j++) delete m_SequenceVec[j];
120 m_SignatureVec.clear();
121 m_SequenceVec.clear();
122 m_TableVector.clear();
123 m_idCriteria=0;
124 m_idSignature=0;
125 m_idSequence=0;
126 }
127 //std::cout<<"1@@@@@@@@@@@@@@@@@@@"<<m_SequenceVec.size()<<std::endl;
128 //std::cout<<"2@@@@@@@@@@@@@@@@@@@"<<m_SignatureVec.size()<<std::endl;
129 //std::cout<<"3@@@@@@@@@@@@@@@@@@@"<<m_TableVector.size()<<std::endl;
130 //std::vector<Sequence*> tmp1(0);
131 //m_SequenceVec=tmp1;
132 //std::cout<<"1@@@@@@@@@@@@@@@@@@@"<<m_SequenceVec.size()<<std::endl;
133 //std::vector<Signature*> tmp2(0);
134 //m_SignatureVec=tmp2;
135 //std::cout<<"2@@@@@@@@@@@@@@@@@@@"<<m_SignatureVec.size()<<std::endl;
136 //std::vector<std::pair<Signature*,Sequence*> > tmp3(0);
137 //m_TableVector=tmp3;
138 //std::cout<<"3@@@@@@@@@@@@@@@@@@@"<<m_TableVector.size()<<std::endl;
139 // Build global sequence list (and print it).
140 buildSequenceList(m_Sequence_DocNode, true);
141 //std::cout<<"1@@@@@@@@@@@@@@@@@@@"<<m_SequenceVec.size()<<std::endl;
142 //std::vector<Sequence*>::iterator iter=m_SequenceVec.begin();
143 //for(;iter!=m_SequenceVec.end();iter++){
144 // std::cout<< "@@@@@@@@"<<((*iter)->getSeqID())<<std::endl;
145 //}
146 //for (unsigned int i = 0; i < m_SequenceVec.size(); i++) {
147 // std::string seqId = m_SequenceVec[i]->getSeqID();
148 // std::cout<< "@@@@@@@@"<<seqId<<std::endl;
149 //}
150 // Build global signature list (and print it).
151 buildSignatureList(m_Signature_DocNode, true);
152 //std::cout<<"2@@@@@@@@@@@@@@@@@@@"<<m_SignatureVec.size()<<std::endl;
153 //m_Signature_DocNode->release();
154 //m_Sequence_DocNode->release();
155 delete sequenceParser;
156 delete signatureParser;
157 //std::cout<<"@@@@@@@@@@@@@@@@@@@6"<<std::endl;
159 //std::cout<<"3@@@@@@@@@@@@@@@@@@@"<<m_TableVector.size()<<std::endl;
160 m_first=false;
161 std::cout << "MyFrame init() succuss" << "criteria num=" << m_idCriteria << std::endl;
162}
163
165{
166 //MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
167
168 for (unsigned int i = 0; i < m_SequenceVec.size(); i++) {
169 std::string seqId = m_SequenceVec[i]->getSeqID();
170 bool matched = false;
171 for (unsigned int j = 0; j < m_SignatureVec.size(); j++) {
172 if (m_SignatureVec[j]->label() == m_SequenceVec[i]->getSeqID()) {
173 m_TableVector.push_back(std::make_pair(m_SignatureVec[j], m_SequenceVec[i]));
174 matched = true;
175 break;
176 }
177 }
178 if (!matched) {
179 //log << MSG::ERROR << "No matched Signature to Sequence(" << seqId << ")" << endreq;
180 exit(1);
181 }
182 }
183}
184
186{
187 /*zoujh:MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
188 log << MSG::INFO << endreq;
189 log << MSG::INFO << "***" << endreq;
190 log << MSG::INFO << "Finalizing XML." << endreq;
191 log << MSG::INFO << "***" << endreq;*/
192 //m_msgSvcProvider=0;
193 // Call the XML termination method
194 XMLPlatformUtils::Terminate();
195}
196
197void MyFrame::buildSequenceList(const DOMNode* thisNode, bool first)
198{
199 //MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
200 if ( first ) {
201 first=false;
202 //log << MSG::INFO << endreq;
203 //log << MSG::INFO << "--------------------------------------" << endreq;
204 //log << MSG::INFO << " Building global sequence list! " << endreq;
205 //log << MSG::INFO << "--------------------------------------" << endreq;
206 }
207 std::string outString, inputString, seq_idString, algoString;
208
209#define XMLCF XMLString::compareString
210#define XMLTF XMLString::transcode
211 DOMNode *helpNode = thisNode->getFirstChild();
212 // loop through the tree
213 while (helpNode != 0) {
214
215 if(XMLCF(XMLTF(helpNode->getNodeName()),"SEQUENCE")==0) {
216 DOMNamedNodeMap *attributes = helpNode->getAttributes();
217 int attributesCount = attributes->getLength();
218 for(int i = 0; i < attributesCount; i++) {
219 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"sequence_id")==0)
220 seq_idString = XMLTF(attributes->item(i)->getNodeValue());
221 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"input")==0)
222 inputString = XMLTF(attributes->item(i)->getNodeValue());
223 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"output")==0)
224 outString = XMLTF(attributes->item(i)->getNodeValue());
225 }
226 std::cout <<"+-Found SEQUENCE: " << seq_idString << std::endl;
227 //log << MSG::INFO <<"+-Found SEQUENCE: " << seq_idString << endreq;
228 Sequence* m_helpSequence = new Sequence();
229 m_helpSequence->setSeqID(seq_idString);
230 m_helpSequence->setInputID(inputString);
231 m_helpSequence->setOutputID(outString);
232 m_SequenceVec.push_back(m_helpSequence);
233 }
234
235 if (XMLCF(XMLTF(helpNode->getNodeName()),"ESALGORITHM") == 0) {
236 DOMNamedNodeMap *attributes = helpNode->getAttributes();
237 int attributesCount = attributes->getLength();
238 for (int i = 0; i < attributesCount; i++) {
239 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"algorithm")==0)
240 algoString = XMLTF(attributes->item(i)->getNodeValue());
241 }
242 std::cout << "| +-Found ESALGORITHM: " << algoString << std::endl;
243 //log << MSG::INFO << "| +-Found ESALGORITHM: " << algoString << endreq;
244 m_SequenceVec.back()->makeVectors(algoString);
245 }
246
247 // and crowl on ...
248 MyFrame::buildSequenceList(helpNode, first);
249 helpNode = helpNode->getNextSibling();
250 }
251#undef XMLCF
252#undef XMLTF
253}
254
255// build the global signature list.
256void MyFrame::buildSignatureList(const DOMNode* thisNode, bool first)
257{
258 //MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
259
260 if ( first ) {
261 first = false;
262 //log << MSG::INFO << endreq;
263 //log << MSG::INFO << "--------------------------------------" << endreq;
264 //log << MSG::INFO << " Building global signature list! " << endreq;
265 //log << MSG::INFO << "--------------------------------------" << endreq;
266 }
267 std::string helpString, helpPrescale, behaviour, itemName, itemType;
268 int prescale=1;
269 float forcedAccept=1, itemValue=0;
270
271#define XMLCF XMLString::compareString
272#define XMLTF XMLString::transcode
273 DOMNode *helpNode = thisNode->getFirstChild();
274 // loop through the tree
275 while (helpNode != 0) {
276 static std::string current_sigID = "";
277 if(XMLCF(XMLTF(helpNode->getNodeName()),"SIGNATURE")==0) {
278 DOMNamedNodeMap *attributes = helpNode->getAttributes();
279 unsigned int attributesCount = attributes->getLength();
280 for(unsigned int i = 0; i < attributesCount; i++) {
281 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"signature_id")==0)
282 helpString = XMLTF(attributes->item(i)->getNodeValue());
283 current_sigID = helpString;
284 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"prescale")==0) {
285 helpPrescale = XMLTF(attributes->item(i)->getNodeValue());
286 prescale = atoi(helpPrescale.c_str());
287 }
288 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"forced_accept")==0)
289 forcedAccept = (float)DOMToDouble(attributes->item(i)->getNodeValue());
290 }
291 std::cout<< "+-Found SIGNATURE: " << helpString << std::endl;
292 //log << MSG::INFO << "+-Found SIGNATURE: " << helpString << endreq;
293 Signature* m_helpSignature = new Signature();
294 m_helpSignature->setSigLabel(helpString);
295 m_helpSignature->setPrescale(prescale);
296 m_helpSignature->setForcedAccept(forcedAccept);
297 m_SignatureVec.push_back(m_helpSignature);
298 }
299 //std::cout<<"***************************2"<<std::endl;
300 static HltCriteria* current_HltCriteria = NULL;
301 if(XMLCF(XMLTF(helpNode->getNodeName()),"CRITERIA")==0) {
302 HltCriteria *m_HltCriteria = new HltCriteria(m_idCriteria);
303 DOMNamedNodeMap *attributes = helpNode->getAttributes();
304 unsigned int attributesCount = attributes->getLength();
305 //std::cout <<"---------------------------1"<<current_sigID<<std::endl;
306 for(unsigned int i = 0; i < attributesCount; i++) {
307 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"behaviour")==0) {
308 behaviour = XMLTF(attributes->item(i)->getNodeValue());
309 if (behaviour == "reject") behaviour += "_reject";
310 }
311 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"next")==0) {
312 if (behaviour != "jump") {
313 std::cout << "Unconsistent of behaviour and next" << std::endl;
314 //log << MSG::ERROR << "Unconsistent of behaviour and next" << endreq;
315 exit(1);
316 }
317 std::string nextID = XMLTF(attributes->item(i)->getNodeValue());
318 //std::cout <<"---------------------------2"<<nextID<<std::endl;
319 for (unsigned int i = 0; i < m_SequenceVec.size(); i++) {
320 //std::cout << "======="<<m_SequenceVec[i]->getSeqID()<<std::endl;
321 if (m_SequenceVec[i]->getSeqID() == current_sigID) {
322 while (++i < m_SequenceVec.size()) {
323 //std::cout << "======="<<m_SequenceVec[i]->getSeqID()<<std::endl;
324 if (m_SequenceVec[i]->getSeqID() == nextID) break;
325 }
326 if (i == m_SequenceVec.size()) {
327 std::cout << "Undefined jump target: " << nextID << std::endl;
328 //log << MSG::ERROR << "Undefined jump target: " << nextID << endreq;
329 exit(1);
330 }
331 break;
332 }
333 }
334 behaviour = behaviour +'_'+ nextID;
335 }
336 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"mark")==0) {
337 if ((behaviour!= "accept")&&(behaviour!= "continue")) {
338 std::cout << "Unconsistent of behaviour and mark" << std::endl;
339 //log << MSG::ERROR << "Unconsistent of behaviour and mark" << endreq;
340 exit(1);
341 }
342 behaviour = behaviour +'_'+ XMLTF(attributes->item(i)->getNodeValue());
343 }
344 }
345 if (behaviour.find('_') == string::npos) {
346 std::cout << "Unvalid behaviour ==> " << behaviour << std::endl;
347 //log << MSG::ERROR << "Unvalid behaviour ==> " << behaviour << endreq;
348 exit(1);
349 }
350 //std::cout << "-----------------" << behaviour << std::endl;
351 m_HltCriteria->setBehaviour(behaviour);
352 std::cout << "| +-Found CRITERIA: behaviour as " << m_HltCriteria->getBehaviour() << std::endl;
353 //log << MSG::INFO << "| +-Found CRITERIA: behaviour as " << behaviour << endreq;
354 m_SignatureVec.back()->makeVectors(m_HltCriteria);
355 m_idCriteria++;
356 current_HltCriteria = m_HltCriteria;
357 }
358 //std::cout<<"***************************3"<<std::endl;
359 if(XMLCF(XMLTF(helpNode->getNodeName()),"ITEM") == 0) {
360 DOMNamedNodeMap *itemAttr = helpNode->getAttributes();
361 if (itemAttr->getLength() != 3) {
362 //log << MSG::ERROR << "Unvalid CriteriaItem" << endreq;
363 exit(1);
364 }
365 for (int i = 0; i < 3; i++) {
366 if(XMLCF(XMLTF(itemAttr->item(i)->getNodeName()), "name") == 0)
367 itemName = XMLTF(itemAttr->item(i)->getNodeValue());
368 if(XMLCF(XMLTF(itemAttr->item(i)->getNodeName()), "value") == 0)
369 itemValue = (float)DOMToDouble(itemAttr->item(i)->getNodeValue());
370 if(XMLCF(XMLTF(itemAttr->item(i)->getNodeName()), "type") == 0)
371 itemType = XMLTF(itemAttr->item(i)->getNodeValue());
372 }
373 //log << MSG::INFO << "| | +-Found CRITERIA_ITEM (" << itemName
374 //<< ", " << itemValue << ", " << itemType << ")" << endreq;
375 current_HltCriteria->addItem(itemName, itemValue, itemType,m_idItem);
376 m_idItem++;
377 }
378 //std::cout<<"***************************4"<<std::endl;
379 // and crowl on ...
380 MyFrame::buildSignatureList(helpNode, first);
381 helpNode = helpNode->getNextSibling();
382 }
383 //if(helpNode==0)std::cout<<"MyFrame::buildSignatureList() finished"<<std::endl;
384#undef XMLCF
385#undef XMLTF
386}
387
388// Get the final vector.
389const std::vector<std::pair<Signature*, Sequence*> >& MyFrame::getTablesVector() const
390{
391 return m_TableVector;
392}
393
394const double MyFrame::DOMToDouble(const XMLCh * thisDOMString) const
395{
396 double returnValue(0);
397 std::string helpString(XMLString::transcode(thisDOMString));
398 std::istringstream is(helpString);
399 is >> returnValue;
400 return returnValue;
401}
402
403} // End of namespace bracket
#define XMLCF
#define XMLTF
static void destruct()
Definition: MyFrame.cxx:28
const double DOMToDouble(const XMLCh *thisDOMString) const
Definition: MyFrame.cxx:394
static MyFrame * instance()
Definition: MyFrame.cxx:22
const std::vector< std::pair< Signature *, Sequence * > > & getTablesVector() const
Definition: MyFrame.cxx:389
void init(const std::string, const std::string)
Definition: MyFrame.cxx:58
static MessageSvcProvider * instance()
Index first(Pair i)
Definition: EvtCyclic3.cc:195