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