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();
140 buildSequenceList(m_Sequence_DocNode,
true);
151 buildSignatureList(m_Signature_DocNode,
true);
155 delete sequenceParser;
156 delete signatureParser;
161 std::cout <<
"MyFrame init() succuss" <<
"criteria num=" << m_idCriteria << std::endl;
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]));
194 XMLPlatformUtils::Terminate();
197void MyFrame::buildSequenceList(
const DOMNode* thisNode,
bool first)
207 std::string outString, inputString, seq_idString, algoString;
209#define XMLCF XMLString::compareString
210#define XMLTF XMLString::transcode
211 DOMNode *helpNode = thisNode->getFirstChild();
213 while (helpNode != 0) {
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());
226 std::cout <<
"+-Found SEQUENCE: " << seq_idString << std::endl;
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);
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());
242 std::cout <<
"| +-Found ESALGORITHM: " << algoString << std::endl;
244 m_SequenceVec.back()->makeVectors(algoString);
248 MyFrame::buildSequenceList(helpNode, first);
249 helpNode = helpNode->getNextSibling();
256void MyFrame::buildSignatureList(
const DOMNode* thisNode,
bool first)
267 std::string helpString, helpPrescale, behaviour, itemName, itemType;
269 float forcedAccept=1, itemValue=0;
271#define XMLCF XMLString::compareString
272#define XMLTF XMLString::transcode
273 DOMNode *helpNode = thisNode->getFirstChild();
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());
288 if(
XMLCF(
XMLTF(attributes->item(i)->getNodeName()),
"forced_accept")==0)
289 forcedAccept = (float)
DOMToDouble(attributes->item(i)->getNodeValue());
291 std::cout<<
"+-Found SIGNATURE: " << helpString << std::endl;
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);
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();
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";
311 if(
XMLCF(
XMLTF(attributes->item(i)->getNodeName()),
"next")==0) {
312 if (behaviour !=
"jump") {
313 std::cout <<
"Unconsistent of behaviour and next" << std::endl;
317 std::string nextID =
XMLTF(attributes->item(i)->getNodeValue());
319 for (
unsigned int i = 0; i < m_SequenceVec.size(); i++) {
321 if (m_SequenceVec[i]->getSeqID() == current_sigID) {
322 while (++i < m_SequenceVec.size()) {
324 if (m_SequenceVec[i]->getSeqID() == nextID)
break;
326 if (i == m_SequenceVec.size()) {
327 std::cout <<
"Undefined jump target: " << nextID << std::endl;
334 behaviour = behaviour +
'_'+ nextID;
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;
342 behaviour = behaviour +
'_'+
XMLTF(attributes->item(i)->getNodeValue());
345 if (behaviour.find(
'_') == string::npos) {
346 std::cout <<
"Unvalid behaviour ==> " << behaviour << std::endl;
351 m_HltCriteria->setBehaviour(behaviour);
352 std::cout <<
"| +-Found CRITERIA: behaviour as " << m_HltCriteria->getBehaviour() << std::endl;
354 m_SignatureVec.back()->makeVectors(m_HltCriteria);
356 current_HltCriteria = m_HltCriteria;
359 if(
XMLCF(
XMLTF(helpNode->getNodeName()),
"ITEM") == 0) {
360 DOMNamedNodeMap *itemAttr = helpNode->getAttributes();
361 if (itemAttr->getLength() != 3) {
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());
375 current_HltCriteria->addItem(itemName, itemValue, itemType,m_idItem);
380 MyFrame::buildSignatureList(helpNode, first);
381 helpNode = helpNode->getNextSibling();
391 return m_TableVector;
396 double returnValue(0);
397 std::string helpString(XMLString::transcode(thisDOMString));
398 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()