[Rivet] Prototype improved cuts system for Rivet

David Grellscheid david.grellscheid at durham.ac.uk
Wed Oct 24 14:15:20 BST 2012


Hi Andy,

your use case looks like an example for expression templates. I'll need 
to think it through a bit more, but the principle is that you build up 
expressions of type Classifier<T> where T can be complicated:

Classifier
<
	And
    	<
		Classifier<Energy>,
		Or
		<
			Classifier<Eta>,
			Classifier<Phi>
		>
	>
 >

Energy, Eta and Phi are stand-alone (functor) classes that have an 
inline classify() member, (or just plainly use operator()). The call to 
the outer classify() then collapses the whole thing down to just the 
minimal boolean you'd have had if you had done it by hand.

That avoids the inheritance tree and all the any_casting stuff that you 
mention in " if each Classifier is to contain other classifier(s), then 
they need to be held as pointers ". They don't because a classifier 
never holds another one. It just passes the call forwards. If all is 
inlined, the compiler abstracts everything away at the point of use, and 
you have no overhead compared to hand-writing the booleans.

I've used this approach in Softsusy for the linear algebra to avoid the 
temporary loops one gets in M = M1 + M2 + M3 when the Ms are matrices. 
Nice speedup it brought, too :-)

See you,

   David


In your example online, how does ClassifierAND get the values for its 
member 'classifiers'?



More information about the Rivet mailing list