Fireworks
Core
src
FWExpressionEvaluator.cc
Go to the documentation of this file.
1
// -*- C++ -*-
2
//
3
// Package: Core
4
// Class : FWExpressionEvaluator
5
//
6
// Implementation:
7
// <Notes on implementation>
8
//
9
// Original Author: Chris Jones
10
// Created: Fri Feb 29 13:39:56 PST 2008
11
//
12
13
// system include files
14
#include <sstream>
15
16
#include "
FWCore/Reflection/interface/ObjectWithDict.h
"
17
18
// user include files
19
#include "
Fireworks/Core/interface/FWExpressionEvaluator.h
"
20
#include "
Fireworks/Core/interface/FWExpressionException.h
"
21
#include "
CommonTools/Utils/src/Grammar.h
"
22
#include "
CommonTools/Utils/interface/Exception.h
"
23
24
#include "
Fireworks/Core/src/expressionFormatHelpers.h
"
25
26
//
27
// constants, enums and typedefs
28
//
29
30
//
31
// static data member definitions
32
//
33
34
//
35
// constructors and destructor
36
//
37
FWExpressionEvaluator::FWExpressionEvaluator
(
const
std::string
& iExpression,
const
std::string
& iClassName)
38
: m_className(iClassName), m_type(
edm
::TypeWithDict::byName(iClassName)) {
39
setExpression
(iExpression);
40
}
41
42
// FWExpressionEvaluator::FWExpressionEvaluator(const FWExpressionEvaluator& rhs)
43
// {
44
// // do actual copying here;
45
// }
46
47
FWExpressionEvaluator::~FWExpressionEvaluator
() {}
48
49
//
50
// assignment operators
51
//
52
// const FWExpressionEvaluator& FWExpressionEvaluator::operator=(const FWExpressionEvaluator& rhs)
53
// {
54
// //An exception safe implementation is
55
// FWExpressionEvaluator temp(rhs);
56
// swap(rhs);
57
//
58
// return *this;
59
// }
60
61
//
62
// member functions
63
//
64
void
FWExpressionEvaluator::setExpression
(
const
std::string
& iExpression) {
65
if
(
m_type
!=
edm::TypeWithDict
() && !iExpression.empty()) {
66
using namespace
fireworks::expression
;
67
68
//Backwards compatibility with old format
69
std::string
temp
=
oldToNewFormat
(iExpression);
70
71
//now setup the parser
72
using namespace
boost::spirit::classic
;
73
reco::parser::ExpressionPtr
tmpPtr;
74
reco::parser::Grammar
grammar(tmpPtr,
m_type
);
75
try
{
76
if
(
parse
(
temp
.c_str(), grammar.use_parser<1>() >> end_p, space_p).full) {
77
m_expr
= tmpPtr;
78
m_expression
= iExpression;
79
}
else
{
80
throw
FWExpressionException
(
"syntax error"
, -1);
81
//std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
82
}
83
}
catch
(
const
reco::parser::BaseException
&
e
) {
84
//NOTE: need to calculate actual position before doing the regex
85
throw
FWExpressionException
(
reco::parser::baseExceptionWhat
(
e
),
86
indexFromNewFormatToOldFormat
(
temp
,
e
.where -
temp
.c_str(), iExpression));
87
//std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
88
}
89
}
else
{
90
m_expression
= iExpression;
91
}
92
}
93
94
void
FWExpressionEvaluator::setClassName
(
const
std::string
& iClassName) {
95
//NOTE: How do we handle the case where the filter was created before
96
// the library for the class was loaded and therefore we don't have
97
// a dictionary for it?
98
99
m_className
= iClassName;
100
m_type
=
edm::TypeWithDict::byName
(iClassName);
101
setExpression
(
m_expression
);
102
}
103
104
//
105
// const member functions
106
//
107
const
std::string
&
FWExpressionEvaluator::expression
()
const
{
return
m_expression
; }
108
109
double
FWExpressionEvaluator::evalExpression
(
const
void
* iObject)
const
{
110
if
(
m_expression
.empty() || !
m_expr
.get()) {
111
return
0;
112
}
113
114
edm::ObjectWithDict
o
(
m_type
, const_cast<void*>(iObject));
115
return
m_expr
->value(
o
);
116
}
117
118
//
119
// static member functions
120
//
FWExpressionEvaluator::m_expr
reco::parser::ExpressionPtr m_expr
Definition:
FWExpressionEvaluator.h:59
edm::TypeWithDict::byName
static TypeWithDict byName(std::string const &name)
Definition:
TypeWithDict.cc:74
reco::parser::baseExceptionWhat
const char * baseExceptionWhat(const BaseException &e)
returns the appropriate 'what' message for the exception
Definition:
Exception.h:36
fireworks::expression::oldToNewFormat
std::string oldToNewFormat(const std::string &iExpression)
Definition:
expressionFormatHelpers.cc:25
boost::spirit::classic
Definition:
DDPartSelection.cc:10
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::ObjectWithDict
Definition:
ObjectWithDict.h:17
FWExpressionException.h
FWExpressionEvaluator::m_expression
std::string m_expression
Definition:
FWExpressionEvaluator.h:57
FWExpressionException
Definition:
FWExpressionException.h:28
groupFilesInBlocks.temp
list temp
Definition:
groupFilesInBlocks.py:142
EcalTangentSkim_cfg.o
o
Definition:
EcalTangentSkim_cfg.py:42
FWExpressionEvaluator::~FWExpressionEvaluator
virtual ~FWExpressionEvaluator()
Definition:
FWExpressionEvaluator.cc:47
FWExpressionEvaluator::setClassName
void setClassName(const std::string &)
Definition:
FWExpressionEvaluator.cc:94
ObjectWithDict.h
Exception.h
FWExpressionEvaluator::m_type
edm::TypeWithDict m_type
Definition:
FWExpressionEvaluator.h:60
expressionFormatHelpers.h
FWExpressionEvaluator::m_className
std::string m_className
Definition:
FWExpressionEvaluator.h:58
fireworks::expression
Definition:
expressionFormatHelpers.cc:24
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
FWExpressionEvaluator::evalExpression
double evalExpression(const void *) const
Definition:
FWExpressionEvaluator.cc:109
FWExpressionEvaluator.h
dumpparser.parse
def parse(path, config)
Definition:
dumpparser.py:13
edm::TypeWithDict
Definition:
TypeWithDict.h:38
reco::parser::BaseException
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition:
Exception.h:33
FWExpressionEvaluator::setExpression
void setExpression(const std::string &)
Definition:
FWExpressionEvaluator.cc:64
reco::parser::ExpressionPtr
std::shared_ptr< ExpressionBase > ExpressionPtr
Definition:
ExpressionBase.h:25
fireworks::expression::indexFromNewFormatToOldFormat
long indexFromNewFormatToOldFormat(const std::string &iNewFormat, long iNewFormatIndex, const std::string &iOldFormat)
Definition:
expressionFormatHelpers.cc:33
reco::parser::Grammar
Definition:
Grammar.h:45
FWExpressionEvaluator::expression
const std::string & expression() const
Definition:
FWExpressionEvaluator.cc:107
FWExpressionEvaluator::FWExpressionEvaluator
FWExpressionEvaluator(const std::string &iExpression, const std::string &iClassName)
Definition:
FWExpressionEvaluator.cc:37
MillePedeFileConverter_cfg.e
e
Definition:
MillePedeFileConverter_cfg.py:37
Grammar.h
Generated for CMSSW Reference Manual by
1.8.16