// ClusterFilter.cpp #include "ClusterFilter.h" #include "trflayer/ClusterContainerStandard.h" using trf::ClusterList; using trf::ClusterContainer; using trf::ClusterContainerStandard; using trf::MTrack; using trf::CutRecord; using trf::ClusterFilter; //********************************************************************** // Class data. //********************************************************************** // Container of clusters to return from default implementation of // filter_container(). ClusterContainerStandard _box1; ClusterContainerStandard _box2; int which_box = 1; //********************************************************************** // Free functions. //********************************************************************** namespace { ObjPtr create(const ObjData& data) { return ObjPtr(0); } } //********************************************************************** // Member functions. //********************************************************************** // constructor ClusterFilter::ClusterFilter() : _loop(false) { } //********************************************************************** // destructor ClusterFilter::~ClusterFilter() { } //********************************************************************** // Return the creator. ObjCreator ClusterFilter::get_creator() { return create; } //********************************************************************** // Filter. // Default implementation calls filter_with_record. // User should override this or filter_with_record. void ClusterFilter:: filter(const MTrack& trm, ClusterList& clus) const { if ( _loop ) { assert(false); abort(); } _loop = true; filter_with_record(trm,clus,0); _loop = false; } //********************************************************************** // Filter with record. // Default implementation calls filter. // User should override this or filter. void ClusterFilter:: filter_with_record(const MTrack& trm, ClusterList& clus, CutRecordMap* precs) const { filter(trm,clus); } //********************************************************************** // Filter the clusters inside a container. // This is the method subclasses should now override. // For backward compatibility, we provide this implementation // which call the (now obselete) filter_with(record(...). // // The list is returned in a container which is required to be // managed by the object. We have made this class data rather // than object data to avoid modifying the header. This is dangerous // and will cause problems if anyone ever tries to access the returned // container after this method is called for any other object. const ClusterContainer& ClusterFilter:: filter_container(const MTrack& trm, const ClusterContainer& box, CutRecordMap* precs) const { // Select which box to use. // We alternate between two so cluster containers can be // passed from one filter to another. ClusterContainerStandard* pnewbox = &_box1; if ( which_box == 1 ) { which_box = 2; } else { assert( which_box == 2 ); pnewbox = &_box2; which_box = 1; } // Check that the input box is not the same as the output. assert( &box != pnewbox ); const ClusterList& oldlist = box.get_clusters(); ClusterList& newlist = pnewbox->get_clusters_mutable(); pnewbox->drop_clusters(); pnewbox->add_clusters(oldlist); assert(oldlist.size() == newlist.size()); filter_with_record(trm, newlist, precs); return *pnewbox; } //**********************************************************************