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"
13#include <xercesc/dom/DOM.hpp>
18 MyFrame* MyFrame::s_FrameInstance = 0;
22 if ( s_FrameInstance == 0 ) { s_FrameInstance =
new MyFrame; }
23 return s_FrameInstance;
26 if ( s_FrameInstance )
delete s_FrameInstance;
31 : m_FrameNumSequenceTables( 0 )
32 , m_FrameNumTables( 0 )
33 , m_FrameAbsolutMaxStep( 0 )
34 , m_Signature_DocNode( NULL )
35 , m_Sequence_DocNode( NULL )
44 if ( s_FrameInstance ) { std::cout <<
" MyFrame constructed twice!" << std::endl; }
45 s_FrameInstance =
this;
46 m_thisName =
"HltConfig";
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];
58 void MyFrame::init(
const std::string sequenceFile,
const std::string signatureFile ) {
65 XMLPlatformUtils::Initialize();
69 catch (
const XMLException& toCatch )
76 XercesDOMParser* signatureParser =
new XercesDOMParser;
77 signatureParser->setValidationScheme( XercesDOMParser::Val_Always );
78 signatureParser->setDoNamespaces(
true );
81 XercesDOMParser* sequenceParser =
new XercesDOMParser;
82 sequenceParser->setValidationScheme( XercesDOMParser::Val_Always );
83 sequenceParser->setDoNamespaces(
true );
88 signatureParser->parse( signatureFile.c_str() );
91 sequenceParser->parse( sequenceFile.c_str() );
95 catch (
const XMLException& toCatch )
99 }
catch (
const DOMException& toCatch )
102 XMLPlatformUtils::Terminate();
107 XMLPlatformUtils::Terminate();
112 m_Sequence_DocNode = sequenceParser->getDocument();
113 m_Signature_DocNode = signatureParser->getDocument();
117 if ( m_first ) { m_first =
false; }
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();
143 buildSequenceList( m_Sequence_DocNode,
true );
154 buildSignatureList( m_Signature_DocNode,
true );
158 delete sequenceParser;
159 delete signatureParser;
164 std::cout <<
"MyFrame init() succuss"
165 <<
"criteria num=" << m_idCriteria << std::endl;
171 for (
unsigned int i = 0; i < m_SequenceVec.size(); i++ )
173 std::string seqId = m_SequenceVec[i]->getSeqID();
174 bool matched =
false;
175 for (
unsigned int j = 0; j < m_SignatureVec.size(); j++ )
177 if ( m_SignatureVec[j]->label() == m_SequenceVec[i]->getSeqID() )
179 m_TableVector.push_back( std::make_pair( m_SignatureVec[j], m_SequenceVec[i] ) );
200 XMLPlatformUtils::Terminate();
203 void MyFrame::buildSequenceList(
const DOMNode* thisNode,
bool first ) {
213 std::string outString, inputString, seq_idString, algoString;
215#define XMLCF XMLString::compareString
216#define XMLTF XMLString::transcode
217 DOMNode* helpNode = thisNode->getFirstChild();
219 while ( helpNode != 0 )
222 if (
XMLCF(
XMLTF( helpNode->getNodeName() ),
"SEQUENCE" ) == 0 )
224 DOMNamedNodeMap* attributes = helpNode->getAttributes();
225 int attributesCount = attributes->getLength();
226 for (
int i = 0; i < attributesCount; i++ )
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() );
235 std::cout <<
"+-Found SEQUENCE: " << seq_idString << std::endl;
237 Sequence* m_helpSequence =
new Sequence();
238 m_helpSequence->
setSeqID( seq_idString );
241 m_SequenceVec.push_back( m_helpSequence );
244 if (
XMLCF(
XMLTF( helpNode->getNodeName() ),
"ESALGORITHM" ) == 0 )
246 DOMNamedNodeMap* attributes = helpNode->getAttributes();
247 int attributesCount = attributes->getLength();
248 for (
int i = 0; i < attributesCount; i++ )
250 if (
XMLCF(
XMLTF( attributes->item( i )->getNodeName() ),
"algorithm" ) == 0 )
251 algoString =
XMLTF( attributes->item( i )->getNodeValue() );
253 std::cout <<
"| +-Found ESALGORITHM: " << algoString << std::endl;
255 m_SequenceVec.back()->makeVectors( algoString );
259 MyFrame::buildSequenceList( helpNode, first );
260 helpNode = helpNode->getNextSibling();
268 void MyFrame::buildSignatureList(
const DOMNode* thisNode,
bool first ) {
279 std::string helpString, helpPrescale, behaviour, itemName, itemType;
281 float forcedAccept = 1, itemValue = 0;
283#define XMLCF XMLString::compareString
284#define XMLTF XMLString::transcode
285 DOMNode* helpNode = thisNode->getFirstChild();
287 while ( helpNode != 0 )
289 static std::string current_sigID =
"";
290 if (
XMLCF(
XMLTF( helpNode->getNodeName() ),
"SIGNATURE" ) == 0 )
292 DOMNamedNodeMap* attributes = helpNode->getAttributes();
293 unsigned int attributesCount = attributes->getLength();
294 for (
unsigned int i = 0; i < attributesCount; i++ )
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 )
301 helpPrescale =
XMLTF( attributes->item( i )->getNodeValue() );
302 prescale = atoi( helpPrescale.c_str() );
304 if (
XMLCF(
XMLTF( attributes->item( i )->getNodeName() ),
"forced_accept" ) == 0 )
305 forcedAccept = (float)
DOMToDouble( attributes->item( i )->getNodeValue() );
307 std::cout <<
"+-Found SIGNATURE: " << helpString << std::endl;
309 Signature* m_helpSignature =
new Signature();
313 m_SignatureVec.push_back( m_helpSignature );
316 static HltCriteria* current_HltCriteria = NULL;
317 if (
XMLCF(
XMLTF( helpNode->getNodeName() ),
"CRITERIA" ) == 0 )
319 HltCriteria* m_HltCriteria =
new HltCriteria( m_idCriteria );
320 DOMNamedNodeMap* attributes = helpNode->getAttributes();
321 unsigned int attributesCount = attributes->getLength();
323 for (
unsigned int i = 0; i < attributesCount; i++ )
325 if (
XMLCF(
XMLTF( attributes->item( i )->getNodeName() ),
"behaviour" ) == 0 )
327 behaviour =
XMLTF( attributes->item( i )->getNodeValue() );
328 if ( behaviour ==
"reject" ) behaviour +=
"_reject";
330 if (
XMLCF(
XMLTF( attributes->item( i )->getNodeName() ),
"next" ) == 0 )
332 if ( behaviour !=
"jump" )
334 std::cout <<
"Unconsistent of behaviour and next" << std::endl;
338 std::string nextID =
XMLTF( attributes->item( i )->getNodeValue() );
341 for (
unsigned int i = 0; i < m_SequenceVec.size(); i++ )
344 if ( m_SequenceVec[i]->getSeqID() == current_sigID )
346 while ( ++i < m_SequenceVec.size() )
349 if ( m_SequenceVec[i]->getSeqID() == nextID )
break;
351 if ( i == m_SequenceVec.size() )
353 std::cout <<
"Undefined jump target: " << nextID << std::endl;
360 behaviour = behaviour +
'_' + nextID;
362 if (
XMLCF(
XMLTF( attributes->item( i )->getNodeName() ),
"mark" ) == 0 )
364 if ( ( behaviour !=
"accept" ) && ( behaviour !=
"continue" ) )
366 std::cout <<
"Unconsistent of behaviour and mark" << std::endl;
370 behaviour = behaviour +
'_' +
XMLTF( attributes->item( i )->getNodeValue() );
373 if ( behaviour.find(
'_' ) == string::npos )
375 std::cout <<
"Unvalid behaviour ==> " << behaviour << std::endl;
381 std::cout <<
"| +-Found CRITERIA: behaviour as " << m_HltCriteria->
getBehaviour()
384 m_SignatureVec.back()->makeVectors( m_HltCriteria );
386 current_HltCriteria = m_HltCriteria;
389 if (
XMLCF(
XMLTF( helpNode->getNodeName() ),
"ITEM" ) == 0 )
391 DOMNamedNodeMap* itemAttr = helpNode->getAttributes();
392 if ( itemAttr->getLength() != 3 )
397 for (
int i = 0; i < 3; i++ )
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() );
408 current_HltCriteria->
addItem( itemName, itemValue, itemType, m_idItem );
413 MyFrame::buildSignatureList( helpNode, first );
414 helpNode = helpNode->getNextSibling();
423 return m_TableVector;
427 double returnValue( 0 );
428 std::string helpString( XMLString::transcode( thisDOMString ) );
429 std::istringstream is( helpString );
void addItem(const std::string &name, float value, const std::string &type, int id)
const std::string & getBehaviour() const
void setBehaviour(const std::string &behaviour)
const double DOMToDouble(const XMLCh *thisDOMString) const
static MyFrame * instance()
const std::vector< std::pair< Signature *, Sequence * > > & getTablesVector() const
void init(const std::string, const std::string)
static MessageSvcProvider * instance()
void setInputID(std::string inputID)
void setSeqID(std::string seqID)
void setOutputID(std::string outputID)
void setForcedAccept(float)
Set the forced accept rate. //.
void setSigLabel(std::string label)
void setPrescale(int)
Set prescale. //.