ATLAS Offline Software
Loading...
Searching...
No Matches
LogicExpression.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TrigConf_LogicExpression
6#define TrigConf_LogicExpression
7
8#include <iostream>
9#include <string>
10#include <vector>
11#include <memory>
12
13namespace TrigConf {
14
24 class LogicExpression;
25 typedef std::vector<std::shared_ptr<LogicExpression>> LogicV_t;
26
28 public:
29
30 // The following 5 symbols represent the possible states of
31 // a logic expression.
32 static const char kAND = '&';
33 static const char kOR = '|';
34 static const char kNOT = '!';
35 static const char kELEMENT = '#';
36 static const char kOPEN = '(';
37 static const char kCLOSE = ')';
38
39 static bool isValidElementChar(char c);
40 static std::string extractElementName(const std::string& expr);
41
42 public:
44 LogicExpression(std::ostream & o = std::cout);
45
47 virtual ~LogicExpression() = default;
48
49 LogicExpression(const std::string& name, std::ostream & o = std::cout);
50
51 virtual int parse(const std::string& expr, bool enclosed=false);
52 virtual std::string logicRep() const;
53
54 void setState(char s) { m_State = s; }
55 void setElement(const std::string& e) { m_Element = e; }
56 void addSubLogic(const LogicExpression& sub) {
57 m_SubLogics.emplace_back(std::make_shared<LogicExpression>(sub));
58 }
59
60 char state() const { return m_State; }
61 const std::string& element() const { return m_Element; }
62 const LogicV_t & subLogics() const { return m_SubLogics; }
63 const std::shared_ptr<LogicExpression> subLogic(int i) const { return subLogics()[i]; }
64 bool isPlaceHolder() const { return (m_State==kOPEN && m_SubLogics.size()==1); }
65
66
67 //LogicV_t& LogicExpression::subLogics() { return m_SubLogics; }
68
69 int totalNumberOfElements() const;
70
71 void markPlaceHolder();
72 void normalize();
73 void printError(const std::string& message, int i);
74 void printCurrentState();
75 void print(const std::string& indent="");
76 void clear();
77
78 protected:
79
80 std::string m_LogicRep;
81
82 char m_State;
83
85 std::string m_Element;
86
87 std::ostream & m_ostream;
88
89 };
90
91}
92
93#endif // TrigConf_LogicExpression
void printError()
LogicExpression(std::ostream &o=std::cout)
constructor
std::ostream & m_ostream
output stream for all messages
static const char kAND
AND of sub-logics.
static const char kOPEN
empty logic but may have sub-logics.
const std::string & element() const
virtual std::string logicRep() const
static const char kNOT
NOT of a sub-logic. (only one sub-logic)
void addSubLogic(const LogicExpression &sub)
static const char kCLOSE
')' is a valid symbol, but not allowed as a state.
static const char kELEMENT
simple element.
static bool isValidElementChar(char c)
const LogicV_t & subLogics() const
void setElement(const std::string &e)
virtual ~LogicExpression()=default
destructor
static const char kOR
OR of sub-logics.
const std::shared_ptr< LogicExpression > subLogic(int i) const
static std::string extractElementName(const std::string &expr)
void print(const std::string &indent="")
virtual int parse(const std::string &expr, bool enclosed=false)
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
std::vector< std::shared_ptr< LogicExpression > > LogicV_t