CD Special Projects

Rules for Designing Selectors

Purpose of Selectors

Recall that selectors are used in creating keys, and are the objects that control the selection of chunks within an event. The basics of the mechanism are described in an earlier section, "Accessing Chunks in the Event"

Two types of Selectors

The EDM contains two types of selectors. The important function (match( )) of these selectors is used to test chunks, to see if they meet the requirements of the selector. If one is implementing a selector which needs only to use the interface provided by the base class AbsChunk, then one should develop a selector which inherits from AbsSelector. If the selector needs to make use of the specific interface of a concrete subclass of AbsChunk, then one should develop a selector which inherits from AbsTSelector<T>, where T is the concrete subclass of AbsChunk in question. In order to assure that selectors in keys can be copied correctly, one must also implement the member function clone( ), which returns a pointer to a copy of the selector on which it is called. It must not return a pointer to the original.

Requirements of the AbsSelector Interface

The match function AbsSelector can use only the AbsChunk interface. It returns true if the chunk it is passed satisfies the selection criteria of the chunk.

bool match(const AbsChunk& c) const;
AbsSelector* clone() const;

One concrete subclass of AbsSelector is already provided in the package edm; this is the class IDSelector, which implements matching of RCPIDs or EnvIDs (or both) in the queried chunk.

Requirements of the AbsTSelector<T> Interface

bool match(const T& t) const;
AbsTSelector<T>* cloneT() const;

Example of AbsTSelector

Suppose we want users to be able to choose a ToyClusterColl based only upon the cluster radius, and ignoring any other features of the chunk. We could define the class ToyClusterSel, which inherits from AbsTSelector<ToyClusterColl>, as follows:

class ToyClusterSel : public AbsTSelector<ToyClusterColl> {
public: 
   ToyClusterSel(float radius);
   ToyClusterSel(RCP r);
   bool match(const ToyClusterColl& tcc) const;
   AbsTSelector<ToyClusterColl>* cloneT() const;
private:
   float _radius;
};


ToyClusterSel::ToyClusterSel(float radius) :
   _radius(radius)
   {};

ToyClusterSel::ToyClusterSel(RCP r) :
   _radius(r.getFloat("radius"))
   {};

bool ToyClusterSel::match(const ToyClusterColl& tcc) {
   return tcc.radius() == _radius;
};

AbsTSelector<ToyClusterColl>* ToyClusterSel::cloneT() const {
   return new ToyClusterSel(*this);
};

Note that we have implemented a constructor that takes an RCP object, so that we can easily refer to this specific ToyClusterSel by the RCPID of the RCP object used in its instantiation. In cases where the selector requires many data members to be set, it will be convenient to use this RCPID (rather than the whole set of parameters in the RCP object) to encode the values of the member data of the selector.

It will often be useful to produce more than one selector for a given chunk class. For example, we might also want to produce a more "selective" selector,  that considers not only the cone radius, but also some energy thresholds. This is not only allowable in the EDM, but it is encouraged.

Note also that in real code, one should be more careful about floating-point arithmetic than we are in this example's match( ) function!


Back to the EDM tutorial home page
Next: Reconstructor Design
Previous: Chunk Design

This page last updated January 16, 2001 08:54 AM


This page last updated: January 16, 2001 08:54 AM
Send comments or questions to Marc Paterno and Jim Kowalkowski