CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
MyFrame.cxx
Go to the documentation of this file.
1#include "HltConfig/MyFrame.h"
2#include "HltSteerData/Sequence.h"
3#include "HltSteerData/Signature.h"
4#include "HltSteerData/HltCriteria.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 m_idItem=0;
127 }
128 //std::cout<<"1@@@@@@@@@@@@@@@@@@@"<<m_SequenceVec.size()<<std::endl;
129 //std::cout<<"2@@@@@@@@@@@@@@@@@@@"<<m_SignatureVec.size()<<std::endl;
130 //std::cout<<"3@@@@@@@@@@@@@@@@@@@"<<m_TableVector.size()<<std::endl;
131 //std::vector<Sequence*> tmp1(0);
132 //m_SequenceVec=tmp1;
133 //std::cout<<"1@@@@@@@@@@@@@@@@@@@"<<m_SequenceVec.size()<<std::endl;
134 //std::vector<Signature*> tmp2(0);
135 //m_SignatureVec=tmp2;
136 //std::cout<<"2@@@@@@@@@@@@@@@@@@@"<<m_SignatureVec.size()<<std::endl;
137 //std::vector<std::pair<Signature*,Sequence*> > tmp3(0);
138 //m_TableVector=tmp3;
139 //std::cout<<"3@@@@@@@@@@@@@@@@@@@"<<m_TableVector.size()<<std::endl;
140 // Build global sequence list (and print it).
141 buildSequenceList(m_Sequence_DocNode, true);
142 //std::cout<<"1@@@@@@@@@@@@@@@@@@@"<<m_SequenceVec.size()<<std::endl;
143 //std::vector<Sequence*>::iterator iter=m_SequenceVec.begin();
144 //for(;iter!=m_SequenceVec.end();iter++){
145 // std::cout<< "@@@@@@@@"<<((*iter)->getSeqID())<<std::endl;
146 //}
147 //for (unsigned int i = 0; i < m_SequenceVec.size(); i++) {
148 // std::string seqId = m_SequenceVec[i]->getSeqID();
149 // std::cout<< "@@@@@@@@"<<seqId<<std::endl;
150 //}
151 // Build global signature list (and print it).
152 buildSignatureList(m_Signature_DocNode, true);
153 //std::cout<<"2@@@@@@@@@@@@@@@@@@@"<<m_SignatureVec.size()<<std::endl;
154 //m_Signature_DocNode->release();
155 //m_Sequence_DocNode->release();
156 delete sequenceParser;
157 delete signatureParser;
158 //std::cout<<"@@@@@@@@@@@@@@@@@@@6"<<std::endl;
160 //std::cout<<"3@@@@@@@@@@@@@@@@@@@"<<m_TableVector.size()<<std::endl;
161 m_first=false;
162 std::cout << "MyFrame init() succuss" << "criteria num=" << m_idCriteria << std::endl;
163}
164
166{
167 //MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
168
169 for (unsigned int i = 0; i < m_SequenceVec.size(); i++) {
170 std::string seqId = m_SequenceVec[i]->getSeqID();
171 bool matched = false;
172 for (unsigned int j = 0; j < m_SignatureVec.size(); j++) {
173 if (m_SignatureVec[j]->label() == m_SequenceVec[i]->getSeqID()) {
174 m_TableVector.push_back(std::make_pair(m_SignatureVec[j], m_SequenceVec[i]));
175 matched = true;
176 break;
177 }
178 }
179 if (!matched) {
180 //log << MSG::ERROR << "No matched Signature to Sequence(" << seqId << ")" << endreq;
181 exit(1);
182 }
183 }
184}
185
187{
188 /*zoujh:MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
189 log << MSG::INFO << endreq;
190 log << MSG::INFO << "***" << endreq;
191 log << MSG::INFO << "Finalizing XML." << endreq;
192 log << MSG::INFO << "***" << endreq;*/
193 //m_msgSvcProvider=0;
194 // Call the XML termination method
195 XMLPlatformUtils::Terminate();
196}
197
198void MyFrame::buildSequenceList(const DOMNode* thisNode, bool first)
199{
200 //MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
201 if ( first ) {
202 first=false;
203 //log << MSG::INFO << endreq;
204 //log << MSG::INFO << "--------------------------------------" << endreq;
205 //log << MSG::INFO << " Building global sequence list! " << endreq;
206 //log << MSG::INFO << "--------------------------------------" << endreq;
207 }
208 std::string outString, inputString, seq_idString, algoString;
209
210#define XMLCF XMLString::compareString
211#define XMLTF XMLString::transcode
212 DOMNode *helpNode = thisNode->getFirstChild();
213 // loop through the tree
214 while (helpNode != 0) {
215
216 if(XMLCF(XMLTF(helpNode->getNodeName()),"SEQUENCE")==0) {
217 DOMNamedNodeMap *attributes = helpNode->getAttributes();
218 int attributesCount = attributes->getLength();
219 for(int i = 0; i < attributesCount; i++) {
220 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"sequence_id")==0)
221 seq_idString = XMLTF(attributes->item(i)->getNodeValue());
222 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"input")==0)
223 inputString = XMLTF(attributes->item(i)->getNodeValue());
224 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"output")==0)
225 outString = XMLTF(attributes->item(i)->getNodeValue());
226 }
227 std::cout <<"+-Found SEQUENCE: " << seq_idString << std::endl;
228 //log << MSG::INFO <<"+-Found SEQUENCE: " << seq_idString << endreq;
229 Sequence* m_helpSequence = new Sequence();
230 m_helpSequence->setSeqID(seq_idString);
231 m_helpSequence->setInputID(inputString);
232 m_helpSequence->setOutputID(outString);
233 m_SequenceVec.push_back(m_helpSequence);
234 }
235
236 if (XMLCF(XMLTF(helpNode->getNodeName()),"ESALGORITHM") == 0) {
237 DOMNamedNodeMap *attributes = helpNode->getAttributes();
238 int attributesCount = attributes->getLength();
239 for (int i = 0; i < attributesCount; i++) {
240 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"algorithm")==0)
241 algoString = XMLTF(attributes->item(i)->getNodeValue());
242 }
243 std::cout << "| +-Found ESALGORITHM: " << algoString << std::endl;
244 //log << MSG::INFO << "| +-Found ESALGORITHM: " << algoString << endreq;
245 m_SequenceVec.back()->makeVectors(algoString);
246 }
247
248 // and crowl on ...
249 MyFrame::buildSequenceList(helpNode, first);
250 helpNode = helpNode->getNextSibling();
251 }
252#undef XMLCF
253#undef XMLTF
254 //std::cout << m_SequenceVec.size() << " sequences have been built. " << std::endl;
255}
256
257// build the global signature list.
258void MyFrame::buildSignatureList(const DOMNode* thisNode, bool first)
259{
260 //MsgStream log(m_msgSvcProvider->msgSvc(), m_thisName);
261
262 if ( first ) {
263 first = false;
264 //log << MSG::INFO << endreq;
265 //log << MSG::INFO << "--------------------------------------" << endreq;
266 //log << MSG::INFO << " Building global signature list! " << endreq;
267 //log << MSG::INFO << "--------------------------------------" << endreq;
268 }
269 std::string helpString, helpPrescale, behaviour, itemName, itemType;
270 int prescale=1;
271 float forcedAccept=1, itemValue=0;
272
273#define XMLCF XMLString::compareString
274#define XMLTF XMLString::transcode
275 DOMNode *helpNode = thisNode->getFirstChild();
276 // loop through the tree
277 while (helpNode != 0) {
278 static std::string current_sigID = "";
279 if(XMLCF(XMLTF(helpNode->getNodeName()),"SIGNATURE")==0) {
280 DOMNamedNodeMap *attributes = helpNode->getAttributes();
281 unsigned int attributesCount = attributes->getLength();
282 for(unsigned int i = 0; i < attributesCount; i++) {
283 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"signature_id")==0)
284 helpString = XMLTF(attributes->item(i)->getNodeValue());
285 current_sigID = helpString;
286 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"prescale")==0) {
287 helpPrescale = XMLTF(attributes->item(i)->getNodeValue());
288 prescale = atoi(helpPrescale.c_str());
289 }
290 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"forced_accept")==0)
291 forcedAccept = (float)DOMToDouble(attributes->item(i)->getNodeValue());
292 }
293 std::cout<< "+-Found SIGNATURE: " << helpString << std::endl;
294 //log << MSG::INFO << "+-Found SIGNATURE: " << helpString << endreq;
295 Signature* m_helpSignature = new Signature();
296 m_helpSignature->setSigLabel(helpString);
297 m_helpSignature->setPrescale(prescale);
298 m_helpSignature->setForcedAccept(forcedAccept);
299 m_SignatureVec.push_back(m_helpSignature);
300 }
301 //std::cout<<"***************************2"<<std::endl;
302 static HltCriteria* current_HltCriteria = NULL;
303 if(XMLCF(XMLTF(helpNode->getNodeName()),"CRITERIA")==0) {
304 HltCriteria *m_HltCriteria = new HltCriteria(m_idCriteria);
305 DOMNamedNodeMap *attributes = helpNode->getAttributes();
306 unsigned int attributesCount = attributes->getLength();
307 //std::cout <<"---------------------------1"<<current_sigID<<std::endl;
308 for(unsigned int i = 0; i < attributesCount; i++) {
309 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"behaviour")==0) {
310 behaviour = XMLTF(attributes->item(i)->getNodeValue());
311 if (behaviour == "reject") behaviour += "_reject";
312 }
313 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"next")==0) {
314 if (behaviour != "jump") {
315 std::cout << "Unconsistent of behaviour and next" << std::endl;
316 //log << MSG::ERROR << "Unconsistent of behaviour and next" << endreq;
317 exit(1);
318 }
319 std::string nextID = XMLTF(attributes->item(i)->getNodeValue());
320 //std::cout <<"---------------------------2"<<nextID<<" " << m_SequenceVec.size()<<std::endl;
321 for (unsigned int i = 0; i < m_SequenceVec.size(); i++) {
322 //std::cout << "======="<<m_SequenceVec[i]->getSeqID()<<std::endl;
323 if (m_SequenceVec[i]->getSeqID() == current_sigID) {
324 while (++i < m_SequenceVec.size()) {
325 //std::cout << "======="<<m_SequenceVec[i]->getSeqID()<<std::endl;
326 if (m_SequenceVec[i]->getSeqID() == nextID) break;
327 }
328 if (i == m_SequenceVec.size()) {
329 std::cout << "Undefined jump target: " << nextID << std::endl;
330 //log << MSG::ERROR << "Undefined jump target: " << nextID << endreq;
331 exit(1);
332 }
333 break;
334 }
335 }
336 behaviour = behaviour +'_'+ nextID;
337 }
338 if(XMLCF(XMLTF(attributes->item(i)->getNodeName()),"mark")==0) {
339 if ((behaviour!= "accept")&&(behaviour!= "continue")) {
340 std::cout << "Unconsistent of behaviour and mark" << std::endl;
341 //log << MSG::ERROR << "Unconsistent of behaviour and mark" << endreq;
342 exit(1);
343 }
344 behaviour = behaviour +'_'+ XMLTF(attributes->item(i)->getNodeValue());
345 }
346 }
347 if (behaviour.find('_') == string::npos) {
348 std::cout << "Unvalid behaviour ==> " << behaviour << std::endl;
349 //log << MSG::ERROR << "Unvalid behaviour ==> " << behaviour << endreq;
350 exit(1);
351 }
352 //std::cout << "-----------------" << behaviour << std::endl;
353 m_HltCriteria->setBehaviour(behaviour);
354 std::cout << "| +-Found CRITERIA: behaviour as " << m_HltCriteria->getBehaviour() << std::endl;
355 //log << MSG::INFO << "| +-Found CRITERIA: behaviour as " << behaviour << endreq;
356 m_SignatureVec.back()->makeVectors(m_HltCriteria);
357 m_idCriteria++;
358 current_HltCriteria = m_HltCriteria;
359 }
360 //std::cout<<"***************************3"<<std::endl;
361 if(XMLCF(XMLTF(helpNode->getNodeName()),"ITEM") == 0) {
362 DOMNamedNodeMap *itemAttr = helpNode->getAttributes();
363 if (itemAttr->getLength() != 3) {
364 //log << MSG::ERROR << "Unvalid CriteriaItem" << endreq;
365 exit(1);
366 }
367 for (int i = 0; i < 3; i++) {
368 if(XMLCF(XMLTF(itemAttr->item(i)->getNodeName()), "name") == 0)
369 itemName = XMLTF(itemAttr->item(i)->getNodeValue());
370 if(XMLCF(XMLTF(itemAttr->item(i)->getNodeName()), "value") == 0)
371 itemValue = (float)DOMToDouble(itemAttr->item(i)->getNodeValue());
372 if(XMLCF(XMLTF(itemAttr->item(i)->getNodeName()), "type") == 0)
373 itemType = XMLTF(itemAttr->item(i)->getNodeValue());
374 }
375 //std::cout << "| | +-Found CRITERIA_ITEM (" << itemName << ", " << itemValue << ", " << itemType << ")" << std::endl;
376 current_HltCriteria->addItem(itemName, itemValue, itemType,m_idItem);
377 m_idItem++;
378 }
379 //std::cout<<"***************************4"<<std::endl;
380 // and crowl on ...
381 MyFrame::buildSignatureList(helpNode, first);
382 helpNode = helpNode->getNextSibling();
383 }
384 //if(helpNode==0)std::cout<<"MyFrame::buildSignatureList() finished"<<std::endl;
385#undef XMLCF
386#undef XMLTF
387}
388
389// Get the final vector.
390const std::vector<std::pair<Signature*, Sequence*> >& MyFrame::getTablesVector() const
391{
392 return m_TableVector;
393}
394
395const double MyFrame::DOMToDouble(const XMLCh * thisDOMString) const
396{
397 double returnValue(0);
398 std::string helpString(XMLString::transcode(thisDOMString));
399 std::istringstream is(helpString);
400 is >> returnValue;
401 return returnValue;
402}
403
404} // 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:395
static MyFrame * instance()
Definition: MyFrame.cxx:22
const std::vector< std::pair< Signature *, Sequence * > > & getTablesVector() const
Definition: MyFrame.cxx:390
void init(const std::string, const std::string)
Definition: MyFrame.cxx:58
static MessageSvcProvider * instance()
Index first(Pair i)
Definition: EvtCyclic3.cc:195