ATLAS Offline Software
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 
13 namespace 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
TrigConf::LogicExpression::markPlaceHolder
void markPlaceHolder()
Definition: LogicExpression.cxx:169
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TrigConf::LogicExpression::setState
void setState(char s)
Definition: LogicExpression.h:54
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigConf::LogicExpression::logicRep
virtual std::string logicRep() const
Definition: LogicExpression.cxx:176
TrigConf::LogicExpression::parse
virtual int parse(const std::string &expr, bool enclosed=false)
Definition: LogicExpression.cxx:51
TrigConf::LogicExpression::m_SubLogics
LogicV_t m_SubLogics
Definition: LogicExpression.h:84
TrigConf::LogicExpression::subLogics
const LogicV_t & subLogics() const
Definition: LogicExpression.h:62
TrigConf::LogicV_t
std::vector< std::shared_ptr< LogicExpression > > LogicV_t
Definition: LogicExpression.h:24
TrigConf::LogicExpression::setElement
void setElement(const std::string &e)
Definition: LogicExpression.h:55
ReweightUtils.message
message
Definition: ReweightUtils.py:15
TrigConf::LogicExpression
Definition: LogicExpression.h:27
TrigConf::LogicExpression::~LogicExpression
virtual ~LogicExpression()=default
destructor
TrigConf::LogicExpression::m_State
char m_State
Definition: LogicExpression.h:82
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition: Config.h:22
geometry_dat_to_json.indent
indent
Definition: geometry_dat_to_json.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigConf::LogicExpression::isPlaceHolder
bool isPlaceHolder() const
Definition: LogicExpression.h:64
TrigConf::LogicExpression::addSubLogic
void addSubLogic(const LogicExpression &sub)
Definition: LogicExpression.h:56
TrigConf::LogicExpression::normalize
void normalize()
Definition: LogicExpression.cxx:204
TrigConf::LogicExpression::clear
void clear()
Definition: LogicExpression.cxx:293
TrigConf::LogicExpression::m_Element
std::string m_Element
Definition: LogicExpression.h:85
TrigConf::LogicExpression::LogicExpression
LogicExpression(std::ostream &o=std::cout)
constructor
Definition: LogicExpression.cxx:14
TrigConf::LogicExpression::kNOT
static const char kNOT
NOT of a sub-logic. (only one sub-logic)
Definition: LogicExpression.h:34
TrigConf::LogicExpression::kELEMENT
static const char kELEMENT
simple element.
Definition: LogicExpression.h:35
TrigConf::LogicExpression::extractElementName
static std::string extractElementName(const std::string &expr)
Definition: LogicExpression.cxx:40
TrigConf::LogicExpression::kOR
static const char kOR
OR of sub-logics.
Definition: LogicExpression.h:33
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::LogicExpression::state
char state() const
Definition: LogicExpression.h:60
TrigConf::LogicExpression::kCLOSE
static const char kCLOSE
')' is a valid symbol, but not allowed as a state.
Definition: LogicExpression.h:37
TrigConf::LogicExpression::subLogic
const std::shared_ptr< LogicExpression > subLogic(int i) const
Definition: LogicExpression.h:63
TrigConf::LogicExpression::element
const std::string & element() const
Definition: LogicExpression.h:61
TrigConf::LogicExpression::printCurrentState
void printCurrentState()
Definition: LogicExpression.cxx:259
TrigConf::LogicExpression::kAND
static const char kAND
AND of sub-logics.
Definition: LogicExpression.h:32
TrigConf::LogicExpression::totalNumberOfElements
int totalNumberOfElements() const
Definition: LogicExpression.cxx:224
TrigConf::LogicExpression::printError
void printError(const std::string &message, int i)
Definition: LogicExpression.cxx:246
python.compressB64.c
def c
Definition: compressB64.py:93
TrigConf::LogicExpression::m_ostream
std::ostream & m_ostream
output stream for all messages
Definition: LogicExpression.h:87
TrigConf::LogicExpression::isValidElementChar
static bool isValidElementChar(char c)
Definition: LogicExpression.cxx:29
TrigConf::LogicExpression::kOPEN
static const char kOPEN
empty logic but may have sub-logics.
Definition: LogicExpression.h:36
TrigConf::LogicExpression::print
void print(const std::string &indent="")
Definition: LogicExpression.cxx:268
TrigConf::LogicExpression::m_LogicRep
std::string m_LogicRep
Definition: LogicExpression.h:80