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"
13#include <xercesc/dom/DOM.hpp>
19MyFrame* MyFrame::s_FrameInstance = 0;
23 if(s_FrameInstance == 0) {
26 return s_FrameInstance;
29 if (s_FrameInstance)
delete s_FrameInstance;
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),
42 std::cout <<
" MyFrame constructed twice!"<< std::endl;
45 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];
58void MyFrame::init(
const std::string sequenceFile,
const std::string signatureFile)
65 XMLPlatformUtils::Initialize();
69 catch (
const XMLException& toCatch) {
75 XercesDOMParser* signatureParser =
new XercesDOMParser;
76 signatureParser->setValidationScheme(XercesDOMParser::Val_Always);
77 signatureParser->setDoNamespaces(
true);
80 XercesDOMParser* sequenceParser =
new XercesDOMParser;
81 sequenceParser->setValidationScheme(XercesDOMParser::Val_Always);
82 sequenceParser->setDoNamespaces(
true);
86 signatureParser->parse(signatureFile.c_str());
89 sequenceParser->parse(sequenceFile.c_str());
93 catch (
const XMLException& toCatch) {
97 catch (
const DOMException& toCatch) {
99 XMLPlatformUtils::Terminate();
104 XMLPlatformUtils::Terminate();
109 m_Sequence_DocNode = sequenceParser->getDocument();
110 m_Signature_DocNode = signatureParser->getDocument();
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();
141 buildSequenceList(m_Sequence_DocNode,
true);
152 buildSignatureList(m_Signature_DocNode,
true);
156 delete sequenceParser;
157 delete signatureParser;
162 std::cout <<
"MyFrame init() succuss" <<
"criteria num=" << m_idCriteria << std::endl;
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]));
195 XMLPlatformUtils::Terminate();
198void MyFrame::buildSequenceList(
const DOMNode* thisNode,
bool first)
208 std::string outString, inputString, seq_idString, algoString;
210#define XMLCF XMLString::compareString
211#define XMLTF XMLString::transcode
212 DOMNode *helpNode = thisNode->getFirstChild();
214 while (helpNode != 0) {
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());
227 std::cout <<
"+-Found SEQUENCE: " << seq_idString << std::endl;
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);
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());
243 std::cout <<
"| +-Found ESALGORITHM: " << algoString << std::endl;
245 m_SequenceVec.back()->makeVectors(algoString);
249 MyFrame::buildSequenceList(helpNode, first);
250 helpNode = helpNode->getNextSibling();
258void MyFrame::buildSignatureList(
const DOMNode* thisNode,
bool first)
269 std::string helpString, helpPrescale, behaviour, itemName, itemType;
271 float forcedAccept=1, itemValue=0;
273#define XMLCF XMLString::compareString
274#define XMLTF XMLString::transcode
275 DOMNode *helpNode = thisNode->getFirstChild();
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());
290 if(
XMLCF(
XMLTF(attributes->item(i)->getNodeName()),
"forced_accept")==0)
291 forcedAccept = (float)
DOMToDouble(attributes->item(i)->getNodeValue());
293 std::cout<<
"+-Found SIGNATURE: " << helpString << std::endl;
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);
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();
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";
313 if(
XMLCF(
XMLTF(attributes->item(i)->getNodeName()),
"next")==0) {
314 if (behaviour !=
"jump") {
315 std::cout <<
"Unconsistent of behaviour and next" << std::endl;
319 std::string nextID =
XMLTF(attributes->item(i)->getNodeValue());
321 for (
unsigned int i = 0; i < m_SequenceVec.size(); i++) {
323 if (m_SequenceVec[i]->getSeqID() == current_sigID) {
324 while (++i < m_SequenceVec.size()) {
326 if (m_SequenceVec[i]->getSeqID() == nextID)
break;
328 if (i == m_SequenceVec.size()) {
329 std::cout <<
"Undefined jump target: " << nextID << std::endl;
336 behaviour = behaviour +
'_'+ nextID;
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;
344 behaviour = behaviour +
'_'+
XMLTF(attributes->item(i)->getNodeValue());
347 if (behaviour.find(
'_') == string::npos) {
348 std::cout <<
"Unvalid behaviour ==> " << behaviour << std::endl;
353 m_HltCriteria->setBehaviour(behaviour);
354 std::cout <<
"| +-Found CRITERIA: behaviour as " << m_HltCriteria->getBehaviour() << std::endl;
356 m_SignatureVec.back()->makeVectors(m_HltCriteria);
358 current_HltCriteria = m_HltCriteria;
361 if(
XMLCF(
XMLTF(helpNode->getNodeName()),
"ITEM") == 0) {
362 DOMNamedNodeMap *itemAttr = helpNode->getAttributes();
363 if (itemAttr->getLength() != 3) {
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());
376 current_HltCriteria->addItem(itemName, itemValue, itemType,m_idItem);
381 MyFrame::buildSignatureList(helpNode, first);
382 helpNode = helpNode->getNextSibling();
392 return m_TableVector;
397 double returnValue(0);
398 std::string helpString(XMLString::transcode(thisDOMString));
399 std::istringstream is(helpString);
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()