69 template<
typename Operator>
70 function<ScalarFunc>
ApplyOp(
const function<ScalarFunc> &f,
72 if(!static_cast<bool>(f))
return f;
73 function<ScalarType(ScalarType)> op_c(op);
74 return [f,op_c](
const Baby &b){
88 template<
typename Operator>
89 function<VectorFunc>
ApplyOp(
const function<VectorFunc> &f,
91 if(!static_cast<bool>(f))
return f;
92 function<ScalarType(ScalarType)> op_c(op);
93 return [f,op_c](
const Baby &b){
124 template<
typename Operator>
125 pair<function<ScalarFunc>, function<VectorFunc> >
ApplyOp(
const function<ScalarFunc> &sfa,
126 const function<VectorFunc> &vfa,
127 const function<ScalarFunc> &sfb,
128 const function<VectorFunc> &vfb,
130 function<ScalarType(ScalarType,ScalarType)> op_c(op);
131 function<ScalarFunc> sfo;
132 function<VectorFunc> vfo;
133 if(static_cast<bool>(sfa) && static_cast<bool>(sfb)){
134 sfo = [sfa,sfb,op_c](
const Baby &b){
135 return op_c(sfa(b), sfb(b));
137 }
else if(static_cast<bool>(sfa) && static_cast<bool>(vfb)){
138 vfo = [sfa,vfb,op_c](
const Baby &b){
142 for(
size_t i = 0; i < vo.size(); ++i){
143 vo.at(i) = op_c(sa, vb.at(i));
147 }
else if(static_cast<bool>(vfa) &&
static_cast<bool>(sfb)){
148 vfo = [vfa,sfb,op_c](
const Baby &b){
152 for(
size_t i = 0; i < vo.size(); ++i){
153 vo.at(i) = op_c(va.at(i), sb);
157 }
else if(static_cast<bool>(vfa) &&
static_cast<bool>(vfb)){
158 vfo = [vfa,vfb,op_c](
const Baby &b){
161 VectorType vo(va.size() > vb.size() ? vb.size() : va.size());
162 for(
size_t i = 0; i < vo.size(); ++i){
163 vo.at(i) = op_c(va.at(i), vb.at(i));
168 return make_pair(sfo, vfo);
188 pair<function<ScalarFunc>, function<VectorFunc> >
ApplyOp(
const function<ScalarFunc> &sfa,
189 const function<VectorFunc> &vfa,
190 const function<ScalarFunc> &sfb,
191 const function<VectorFunc> &vfb,
192 const logical_and<ScalarType> &){
193 function<ScalarFunc> sfo;
194 function<VectorFunc> vfo;
195 if(static_cast<bool>(sfa) && static_cast<bool>(sfb)){
196 sfo = [sfa,sfb](
const Baby &b){
197 return sfa(b)&&sfb(b);
199 }
else if(static_cast<bool>(sfa) && static_cast<bool>(vfb)){
200 vfo = [sfa,vfb](
const Baby &b){
208 }
else if(static_cast<bool>(vfa) && static_cast<bool>(sfb)){
209 vfo = [vfa,sfb](
const Baby &b){
212 bool evaluated =
false;
214 for(
size_t i = 0; i < vo.size(); ++i){
215 if(!evaluated && va.at(i)){
219 vo.at(i) = va.at(i)&&sb;
223 }
else if(static_cast<bool>(vfa) && static_cast<bool>(vfb)){
224 vfo = [vfa,vfb](
const Baby &b){
227 VectorType vo(va.size() > vb.size() ? vb.size() : va.size());
228 for(
size_t i = 0; i < vo.size(); ++i){
229 vo.at(i) = va.at(i)&&vb.at(i);
234 return make_pair(sfo, vfo);
254 pair<function<ScalarFunc>, function<VectorFunc> >
ApplyOp(
const function<ScalarFunc> &sfa,
255 const function<VectorFunc> &vfa,
256 const function<ScalarFunc> &sfb,
257 const function<VectorFunc> &vfb,
258 const logical_or<ScalarType> &){
259 function<ScalarFunc> sfo;
260 function<VectorFunc> vfo;
261 if(static_cast<bool>(sfa) && static_cast<bool>(sfb)){
262 sfo = [sfa,sfb](
const Baby &b){
263 return sfa(b)||sfb(b);
265 }
else if(static_cast<bool>(sfa) && static_cast<bool>(vfb)){
266 vfo = [sfa,vfb](
const Baby &b){
274 }
else if(static_cast<bool>(vfa) && static_cast<bool>(sfb)){
275 vfo = [vfa,sfb](
const Baby &b){
278 bool evaluated =
false;
280 for(
size_t i = 0; i < vo.size(); ++i){
281 if(!(evaluated || va.at(i))){
285 vo.at(i) = va.at(i)||sb;
289 }
else if(static_cast<bool>(vfa) && static_cast<bool>(vfb)){
290 vfo = [vfa,vfb](
const Baby &b){
293 VectorType vo(va.size() > vb.size() ? vb.size() : va.size());
294 for(
size_t i = 0; i < vo.size(); ++i){
295 vo.at(i) = va.at(i)||vb.at(i);
300 return make_pair(sfo, vfo);
311 const std::function<ScalarFunc> &
function):
313 scalar_func_(function),
325 const std::function<VectorFunc> &
function):
359 NamedFunc(static_cast<const char *>(function)){
400 if(!static_cast<bool>(f))
return *
this;
416 if(!static_cast<bool>(f))
return *
this;
500 minus<ScalarType>());
516 multiplies<ScalarType>());
532 divides<ScalarType>());
557 if(
IsScalar())
ERROR(
"Cannot apply indexing operator to scalar NamedFunc "+
Name());
562 return vec(b).at(index(b));
669 equal_to<ScalarType>());
687 not_equal_to<ScalarType>());
706 greater<ScalarType>());
744 greater_equal<ScalarType>());
764 less_equal<ScalarType>());
782 logical_and<ScalarType>());
800 logical_or<ScalarType>());
826 stream <<
function.Name();
831 for(
const auto &x: v){
837 bool HavePass(
const std::vector<NamedFunc::VectorType> &vv){
838 if(vv.size()==0)
return false;
840 for(
size_t ix = 0; ix < vv.at(0).size(); ++ix){
842 for(
size_t iv = 0; this_pass && iv < vv.size(); ++iv){
843 if(ix>=vv.at(iv).size() || !vv.at(iv).at(ix)) this_pass =
false;
845 if(this_pass)
return true;
NamedFunc operator<=(NamedFunc f, NamedFunc g)
Gets NamedFunc which tests if result of f is less than or equal to result of g.
NamedFunc operator/(NamedFunc f, NamedFunc g)
Divide two NamedFuncs.
std::vector< ScalarType > VectorType
NamedFunc operator%(NamedFunc f, NamedFunc g)
Get remainder form division of two NamedFuncs.
NamedFunc::VectorType VectorType
NamedFunc & operator*=(const NamedFunc &func)
Multiply *this by func.
NamedFunc operator>(NamedFunc f, NamedFunc g)
Gets NamedFunc which tests if result of f is greater than result of g.
std::string name_
String representation of the function.
const std::string & Name() const
Get the string representation of this function.
Abstract base class for access to ntuple variables.
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
ScalarType GetScalar(const Baby &b) const
Evaluate scalar function with b as argument.
NamedFunc operator&&(NamedFunc f, NamedFunc g)
Gets NamedFunc which tests if results of both f and g are true.
ScalarType(const Baby &) ScalarFunc
Combines a callable function taking a Baby and returning a scalar or vector with its string represent...
ostream & operator<<(ostream &stream, const NamedFunc &function)
Print NamedFunc to output stream.
NamedFunc operator<(NamedFunc f, NamedFunc g)
Gets NamedFunc which tests if result of f is less than result of g.
NamedFunc operator>=(NamedFunc f, NamedFunc g)
Gets NamedFunc which tests if result of f is greater than or equal to result of g.
NamedFunc operator==(NamedFunc f, NamedFunc g)
Gets NamedFunc which tests for equality of results of f and g.
pair< function< ScalarFunc >, function< VectorFunc > > ApplyOp(const function< ScalarFunc > &sfa, const function< VectorFunc > &vfa, const function< ScalarFunc > &sfb, const function< VectorFunc > &vfb, const logical_or< ScalarType > &)
Get a functor applying binary "||" to operands (sfa or vfa) and (sfb or vfb)
VectorType(const Baby &) VectorFunc
bool IsScalar() const
Check if scalar function is valid.
NamedFunc::VectorType VectorType
NamedFunc operator[](const NamedFunc &func) const
Apply indexing operator and return result as a NamedFunc.
NamedFunc::VectorFunc VectorFunc
NamedFunc operator!(NamedFunc f)
Gets NamedFunct returning logical inverse of result of f.
void CleanName()
Strip spaces from name.
NamedFunc operator!=(NamedFunc f, NamedFunc g)
Gets NamedFunc which tests for inequality of results of f and g.
VectorType GetVector(const Baby &b) const
Evaluate vector function with b as argument.
std::function< ScalarFunc > scalar_func_
NamedFunc operator||(NamedFunc f, NamedFunc g)
Gets NamedFunc which tests if result of f or g is true.
NamedFunc operator*(NamedFunc f, NamedFunc g)
Multiply two NamedFuncs.
NamedFunc operator-(NamedFunc f, NamedFunc g)
Add a NamedFunc from another.
NamedFunc & operator-=(const NamedFunc &func)
Subtract func from *this.
NamedFunc & Function(const std::function< ScalarFunc > &function)
Set function to given scalar function.
std::function< VectorFunc > vector_func_
bool IsVector() const
Check if vectorr function is valid.
NamedFunc operator+(NamedFunc f, NamedFunc g)
Add two NamedFuncs.
const std::function< VectorFunc > & VectorFunction() const
Return the (possibly invalid) vector function.
bool HavePass(const NamedFunc::VectorType &v)
NamedFunc::ScalarFunc ScalarFunc
NamedFunc & operator%=(const NamedFunc &func)
Set *this to remainder of *this divided by func.
NamedFunc & operator+=(const NamedFunc &func)
Add func to *this.
std::string ToString(const T &x)
NamedFunc & operator/=(const NamedFunc &func)
Divide *this by func.
Converts a string into a NamedFunc.
const std::function< ScalarFunc > & ScalarFunction() const
Return the (possibly invalid) scalar function.
NamedFunc::ScalarType ScalarType