CommonTools
Utils
interface
StringObjectFunction.h
Go to the documentation of this file.
1
#ifndef CommonTools_Utils_StringObjectFunction_h
2
#define CommonTools_Utils_StringObjectFunction_h
3
/* \class StringCutObjectSelector
4
*
5
* \author Luca Lista, INFN
6
*
7
* $Id: StringObjectFunction.h,v 1.4 2012/06/26 21:09:37 wmtan Exp $
8
*/
9
#include "
FWCore/Utilities/interface/EDMException.h
"
10
#include "
CommonTools/Utils/src/ExpressionPtr.h
"
11
#include "
CommonTools/Utils/src/ExpressionBase.h
"
12
#include "
CommonTools/Utils/interface/expressionParser.h
"
13
#include "
FWCore/Reflection/interface/ObjectWithDict.h
"
14
15
template
<
typename
T,
bool
DefaultLazyness = false>
16
struct
StringObjectFunction
{
17
StringObjectFunction
(
const
std::string
&
expr
,
bool
lazy = DefaultLazyness) :
type_
(typeid(
T
)) {
18
if
(!reco::parser::expressionParser<T>(
expr
,
expr_
, lazy)) {
19
throw
edm::Exception
(
edm::errors::Configuration
,
"failed to parse \""
+
expr
+
"\""
);
20
}
21
}
22
StringObjectFunction
(
const
reco::parser::ExpressionPtr
&
expr
) :
expr_
(
expr
),
type_
(typeid(
T
)) {}
23
double
operator()
(
const
T
&
t
)
const
{
24
edm::ObjectWithDict
o
(
type_
, const_cast<T *>(&
t
));
25
return
expr_
->value(
o
);
26
}
27
28
private
:
29
reco::parser::ExpressionPtr
expr_
;
30
edm::TypeWithDict
type_
;
31
};
32
33
template
<
typename
Object>
34
class
sortByStringFunction
{
35
public
:
36
sortByStringFunction
(
StringObjectFunction<Object>
*
f
) :
f_
(
f
) {}
37
~sortByStringFunction
() {}
38
39
bool
operator()
(
const
Object *
o1
,
const
Object *o2) {
return
(*
f_
)(*o1) > (*f_)(*o2); }
40
41
private
:
42
StringObjectFunction<Object>
*
f_
;
43
};
44
45
#endif
StringObjectFunction::operator()
double operator()(const T &t) const
Definition:
StringObjectFunction.h:23
StringObjectFunction
Definition:
StringObjectFunction.h:16
sortByStringFunction::operator()
bool operator()(const Object *o1, const Object *o2)
Definition:
StringObjectFunction.h:39
f
double f[11][100]
Definition:
MuScleFitUtils.cc:78
edm::ObjectWithDict
Definition:
ObjectWithDict.h:17
ExpressionBase.h
EcalTangentSkim_cfg.o
o
Definition:
EcalTangentSkim_cfg.py:42
sortByStringFunction::~sortByStringFunction
~sortByStringFunction()
Definition:
StringObjectFunction.h:37
ObjectWithDict.h
EDMException.h
StringObjectFunction::type_
edm::TypeWithDict type_
Definition:
StringObjectFunction.h:30
sortByStringFunction
Definition:
StringObjectFunction.h:34
CastorDigiReco.o1
o1
Definition:
CastorDigiReco.py:84
sortByStringFunction::sortByStringFunction
sortByStringFunction(StringObjectFunction< Object > *f)
Definition:
StringObjectFunction.h:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::TypeWithDict
Definition:
TypeWithDict.h:38
StringObjectFunction::StringObjectFunction
StringObjectFunction(const reco::parser::ExpressionPtr &expr)
Definition:
StringObjectFunction.h:22
sortByStringFunction::f_
StringObjectFunction< Object > * f_
Definition:
StringObjectFunction.h:42
reco::parser::ExpressionPtr
std::shared_ptr< ExpressionBase > ExpressionPtr
Definition:
ExpressionBase.h:25
ExpressionPtr.h
jets_cff.expr
expr
Definition:
jets_cff.py:489
T
long double T
Definition:
Basic3DVectorLD.h:48
Exception
Definition:
hltDiff.cc:245
submitPVValidationJobs.t
string t
Definition:
submitPVValidationJobs.py:644
StringObjectFunction::expr_
reco::parser::ExpressionPtr expr_
Definition:
StringObjectFunction.h:29
edm::errors::Configuration
Definition:
EDMException.h:36
StringObjectFunction::StringObjectFunction
StringObjectFunction(const std::string &expr, bool lazy=DefaultLazyness)
Definition:
StringObjectFunction.h:17
expressionParser.h
Generated for CMSSW Reference Manual by
1.8.16