BankSelection Class Reference

This class represents a (possibly wildcard-like) selection of Source IDs. It can be modified by appending SourceIDs. More...

#include <BankSelection.h>

List of all members.

Classes

struct  iter_pair

Public Types

typedef IDs::source SourceID
typedef std::vector< SourceIDSourceList_t

Public Member Functions

 BankSelection (bool match_all=true)
 The default-constructed selection matches all banks of the correct pulse type.
 BankSelection (const SourceID &sid)
 Construct matching a single Source ID (can be wild card).
 BankSelection (const SourceList_t &list)
 Construct matching the the list given.
virtual ~BankSelection ()
 Destructior. We may inherit from this class.
bool Includes (const SourceID &sid) const
 Check if the provided SourceID is in the selection, either due to wildcards or exact matches.
bool HasWildCardMatch (const SourceID &sid) const
 Check if the provided SourceID would be selected by the (channel) wildcards.
bool HasExactMatch (const SourceID &sid) const
 Check if the provided SourceID is on the list of exact (channel) matches.
BankSelectionMatchAll ()
 Reset match criteria - accept everything.
BankSelectionMatchNone ()
 Reset match criteria - reject everything.
BankSelectionMatchOnly (const SourceList_t &list)
 Set the match criteria to the provided list, overwriting the previous criteria.
BankSelectionMatchOnly (const SourceID &sid)
 Set the match criteria to the provided ID, overwriting the previous criteria.
BankSelectionAdd (const SourceList_t &list)
 Add Sources from the provided list of Source IDs.
BankSelectionAdd (const SourceID &sid)
 Add the provided Source ID Logically this looks like SELF = SELF | LIST Note however, that this will add a Source ID even if an exact equal exists. Thus (for example) myBankSelection.Add(A).Add(A); will append A twice To eliminate the duplicates, use BankSelection::Compact().
BankSelectionCompact ()
 Remove any exact duplicates from the selection. This should not change the logic, but may speed up searches if many duplicates have been added.
BankSelectionRemove (const SourceList_t &list)
 Remove Sources if they are on the provided list of Source IDs.
BankSelectionRemove (const SourceList_t &list, SourceList_t &removed)
 Remove Sources if they are on the provided list of Source IDs.
BankSelectionRemove (const SourceID &sid)
 Remove the given Source IDs. This overload of This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. BankSelection& Remove(const SourceList_t& list) has all the same caveats.

Protected Types

typedef SourceList_t::iterator iter
typedef
SourceList_t::const_iterator 
citer

Protected Member Functions

bool ListMatch (const SourceID &sid, const SourceList_t &list) const
void SortUnique (SourceList_t &list)
 Implementation function that removes duplicate SourceIDs from a list.
iter_pair ImpRemove (const SourceList_t &list)

Private Attributes

SourceList_t fWildCards
 The list of Source IDs that match several Channels.
SourceList_t fMatches
 The list of SourceIDs tha match a single Channel.

Detailed Description

This class represents a (possibly wildcard-like) selection of Source IDs. It can be modified by appending SourceIDs.

Assume that the most common reason for using wild cards (or not) is to match multiple detector channels. In contrast people asking for specific generators will likely have specific intentions in mind, and the output of particular generators will often be used for specific channels. It will be faster to check against wildcards than long lists of sources, so we store source wildcards separately.

As this class has no pointers, the default copy semantics are reasonable.

Remarks:
We don't currently allow Intersection or Inverted matching of elements. The current design does not know the set of elements matching a wildcard, so a logical "anything except xyz" would require additional lists of negated channels This may be revisited if there is a clear need.

Definition at line 25 of file BankSelection.h.


Member Typedef Documentation

typedef SourceList_t::const_iterator BankSelection::citer [protected]

Definition at line 136 of file BankSelection.h.

typedef SourceList_t::iterator BankSelection::iter [protected]

Definition at line 135 of file BankSelection.h.

Definition at line 28 of file BankSelection.h.

typedef std::vector<SourceID> BankSelection::SourceList_t

Definition at line 29 of file BankSelection.h.


Constructor & Destructor Documentation

BankSelection::BankSelection ( bool  match_all = true  ) 

The default-constructed selection matches all banks of the correct pulse type.

Parameters:
match_all [in] if optionally passed false or 0 it will match none.

Definition at line 29 of file BankSelection.cpp.

00030   :  fWildCards(match_all ? 1 : 0)
00031 {}

BankSelection::BankSelection ( const SourceID sid  ) 

Construct matching a single Source ID (can be wild card).

Definition at line 41 of file BankSelection.cpp.

References MatchOnly().

00042 {
00043   this->MatchOnly(sid);
00044 }

BankSelection::BankSelection ( const SourceList_t list  ) 

Construct matching the the list given.

Definition at line 35 of file BankSelection.cpp.

References MatchOnly().

00036 {
00037   this->MatchOnly(list);
00038 }

BankSelection::~BankSelection (  )  [virtual]

Destructior. We may inherit from this class.

Definition at line 48 of file BankSelection.cpp.

00049 {}


Member Function Documentation

BankSelection & BankSelection::Add ( const SourceID sid  ) 

Add the provided Source ID Logically this looks like SELF = SELF | LIST Note however, that this will add a Source ID even if an exact equal exists. Thus (for example) myBankSelection.Add(A).Add(A); will append A twice To eliminate the duplicates, use BankSelection::Compact().

Returns:
*this

Definition at line 110 of file BankSelection.cpp.

References fMatches, and fWildCards.

00111 {
00112   if (unary_iwcc(sid)){
00113     fWildCards.push_back(sid);
00114   } else {
00115     fMatches.push_back(sid);
00116   }
00117 
00118   return *this;
00119 }

BankSelection & BankSelection::Add ( const SourceList_t list  ) 

Add Sources from the provided list of Source IDs.

Logically this looks like SELF = SELF | LIST Note however, that this will add a Source ID even if an exact equal exists. Thus (for example) myBankSelection.Add(listA).Add(listA); will append listA twice To eliminate the duplicates, use BankSelection::Compact()

Returns:
*this

Definition at line 100 of file BankSelection.cpp.

Referenced by MatchOnly().

00101 {
00102   for (citer it = list.begin(); it != list.end(); ++it){
00103     this->Add(*it);
00104   }
00105   return *this;
00106 }

BankSelection & BankSelection::Compact (  ) 

Remove any exact duplicates from the selection. This should not change the logic, but may speed up searches if many duplicates have been added.

Returns:
*this

Definition at line 132 of file BankSelection.cpp.

References fMatches, fWildCards, and SortUnique().

Referenced by ImpRemove().

00133 {
00134   SortUnique(fWildCards);
00135   SortUnique(fMatches);
00136   return *this;
00137 } 

bool BankSelection::HasExactMatch ( const SourceID sid  )  const [inline]

Check if the provided SourceID is on the list of exact (channel) matches.

Definition at line 57 of file BankSelection.h.

References fMatches, and ListMatch().

Referenced by Includes().

00058   {return ListMatch(sid, fMatches);}

bool BankSelection::HasWildCardMatch ( const SourceID sid  )  const [inline]

Check if the provided SourceID would be selected by the (channel) wildcards.

Definition at line 52 of file BankSelection.h.

References fWildCards, and ListMatch().

Referenced by Includes().

00053   {return ListMatch(sid, fWildCards);}

BankSelection::iter_pair BankSelection::ImpRemove ( const SourceList_t list  )  [protected]

Implementation function to remove a list and return the new end()s first is wildcards second is exact matchess

Warning:
Must call erase after!

Definition at line 141 of file BankSelection.cpp.

References Compact(), fMatches, fWildCards, BankSelection::iter_pair::match, and BankSelection::iter_pair::wildcard.

Referenced by Remove().

00142 {
00143   // REM. This only removes the elements, it does not erase them!
00144 
00145   this->Compact();
00146   iter_pair back;
00147   back.wildcard = fWildCards.end();
00148   back.match = fMatches.end();
00149   for (citer it = list.begin(); it != list.end() ; ++it) {
00150     if ( unary_iwcc(*it) ){
00151       back.wildcard = std::remove(fWildCards.begin(), back.wildcard, (*it));
00152     } else {
00153       back.match = std::remove(fMatches.begin(), back.match, (*it));
00154     }
00155   }    
00156   return back;
00157 }

bool BankSelection::Includes ( const SourceID sid  )  const [inline]

Check if the provided SourceID is in the selection, either due to wildcards or exact matches.

Definition at line 47 of file BankSelection.h.

References HasExactMatch(), and HasWildCardMatch().

00048   {return HasWildCardMatch(sid) || HasExactMatch(sid);}

bool BankSelection::ListMatch ( const SourceID sid,
const SourceList_t list 
) const [protected]

Implementation function that checks if a given Source ID matches any from a list

Definition at line 53 of file BankSelection.cpp.

Referenced by HasExactMatch(), and HasWildCardMatch().

00055 {
00056   functor_match match(sid);
00057   if (find_if(list.begin(), list.end(), match) != list.end()) return true;
00058   return false;
00059 }  

BankSelection & BankSelection::MatchAll (  ) 

Reset match criteria - accept everything.

Returns:
(*this)

Definition at line 63 of file BankSelection.cpp.

References fMatches, and fWildCards.

00064 {
00065   fMatches.clear();
00066   SourceList_t tmp(1);
00067   fWildCards.swap(tmp);
00068   return *this;
00069 }

BankSelection & BankSelection::MatchNone (  ) 

Reset match criteria - reject everything.

Returns:
(*this)

Definition at line 73 of file BankSelection.cpp.

References fMatches, and fWildCards.

Referenced by MatchOnly().

00074 {
00075   fMatches.clear();
00076   fWildCards.clear();
00077   return *this;
00078 }

BankSelection & BankSelection::MatchOnly ( const SourceID sid  ) 

Set the match criteria to the provided ID, overwriting the previous criteria.

Returns:
(*this)

Definition at line 94 of file BankSelection.cpp.

References Add(), and MatchNone().

00095 {
00096   return this->MatchNone().Add(sid);
00097 }

BankSelection & BankSelection::MatchOnly ( const SourceList_t list  ) 

Set the match criteria to the provided list, overwriting the previous criteria.

Returns:
(*this)

Definition at line 82 of file BankSelection.cpp.

References Add(), fMatches, fWildCards, and MatchNone().

Referenced by BankSelection().

00083 {
00084   int n_wc = std::count_if(list.begin(), list.end(), unary_iwcc);
00085   fWildCards.reserve(n_wc);
00086   fMatches.reserve(list.size() - n_wc);
00087 
00088   return this->MatchNone().Add(list);
00089 
00090 }

BankSelection & BankSelection::Remove ( const SourceID sid  ) 

Remove the given Source IDs. This overload of This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. BankSelection& Remove(const SourceList_t& list) has all the same caveats.

Definition at line 189 of file BankSelection.cpp.

References Remove().

00190 {
00191   return this->Remove(SourceList_t(1, sid));
00192 }

BankSelection & BankSelection::Remove ( const SourceList_t list,
SourceList_t removed 
)

Remove Sources if they are on the provided list of Source IDs.

Warning:
This removes IDs based on exact equality of IDs, not logical negation. Thus it cannot be used to exclude a group of channels from a wildcard match. Note: It also causes Compact() to be called, in order to eliminate duplicates
Parameters:
removed [out] is an optional parameter that lists all the IDs Removed() from the selection, If all parameters in list are unique, and all were removed then removed.size() = list.size()

Definition at line 161 of file BankSelection.cpp.

References fMatches, fWildCards, ImpRemove(), BankSelection::iter_pair::match, and BankSelection::iter_pair::wildcard.

00163 {
00164   const iter_pair back = ImpRemove(list);
00165 
00166   //use swap/temporary in case some loon passes the same object as
00167   //both arguments
00168   SourceList_t tmp; 
00169   std::copy(back.wildcard, fWildCards.end(), tmp.end()); 
00170   std::copy(back.match, fMatches.end(), tmp.end());
00171   removed.swap(tmp);
00172   
00173   fWildCards.erase(back.wildcard, fWildCards.end());
00174   fMatches.erase(back.match, fMatches.end());
00175   return *this;
00176 }

BankSelection & BankSelection::Remove ( const SourceList_t list  ) 

Remove Sources if they are on the provided list of Source IDs.

Warning:
This removes IDs based on exact equality of IDs, not logical negation. Thus it cannot be used to exclude a group of channels from a wildcard match. Note: It also causes Compact() to be called, in order to eliminate duplicates
Returns:
*this

Definition at line 180 of file BankSelection.cpp.

References fMatches, fWildCards, ImpRemove(), BankSelection::iter_pair::match, and BankSelection::iter_pair::wildcard.

Referenced by Remove().

00181 {
00182   iter_pair back = ImpRemove(list);
00183   fWildCards.erase(back.wildcard, fWildCards.end());
00184   fMatches.erase(back.match, fMatches.end());
00185   return *this;
00186 }

void BankSelection::SortUnique ( SourceList_t list  )  [protected]

Implementation function that removes duplicate SourceIDs from a list.

Definition at line 123 of file BankSelection.cpp.

Referenced by Compact().

00124 {
00125   std::sort(list.begin(), list.end());
00126   iter dupes = std::unique(list.begin(), list.end());  
00127   list.erase(dupes, list.end()); 
00128 }


Member Data Documentation

The list of SourceIDs tha match a single Channel.

Definition at line 158 of file BankSelection.h.

Referenced by Add(), Compact(), HasExactMatch(), ImpRemove(), MatchAll(), MatchNone(), MatchOnly(), and Remove().

The list of Source IDs that match several Channels.

Definition at line 155 of file BankSelection.h.

Referenced by Add(), Compact(), HasWildCardMatch(), ImpRemove(), MatchAll(), MatchNone(), MatchOnly(), and Remove().


The documentation for this class was generated from the following files:

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1