FilterList.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file FilterList.h
3 // \brief A simple list of "filtered out" products
4 // \author Christopher Backhouse - bckhouse@caltech.edu
5 ////////////////////////////////////////////////////////////////////////
6 #ifndef RBFILTERLIST_H
7 #define RBFILTERLIST_H
8 
9 #ifndef __GCCXML__
11 #endif
13 
14 namespace rb
15 {
16 #ifndef __GCCXML__
17  /// \brief Is this Ptr marked "filtered out"?
18  ///
19  /// \param evt The current event
20  /// \param x Check if this Ptr is marked "filtered"
21  /// \param labels Only check FilterLists under these labels. If empty check
22  /// all labels.
23  template<class T> bool IsFiltered(const art::Event& evt,
24  art::Ptr<T> x,
25  const std::vector<std::string>& labels);
26 
27  /// Check a single label. If \a label is blank, check all
28  template<class T> bool IsFiltered(const art::Event& evt,
29  art::Ptr<T> x,
30  const std::string& label)
31  {
32  if(label.empty())
33  return IsFiltered(evt, x, std::vector<std::string>());
34  else
35  return IsFiltered(evt, x, std::vector<std::string>(1, label));
36  }
37 
38  /// Check all labels
39  template<class T> bool IsFiltered(const art::Event& evt,
40  art::Ptr<T> x)
41  {
42  return IsFiltered(evt, x, "");
43  }
44 
45  /// Express Ptr as a Handle and offset
46  template<class T> bool IsFiltered(const art::Event& evt,
47  art::Handle<std::vector<T> > h,
48  int idx,
49  const std::vector<std::string>& labels)
50  {
51  return IsFiltered(evt, art::Ptr<T>(h, idx), labels);
52  }
53 
54  /// Express Ptr as a Handle and offset, check a single label
55  template<class T> bool IsFiltered(const art::Event& evt,
56  art::Handle<std::vector<T> > h,
57  int idx,
58  const std::string& label)
59  {
60  return IsFiltered(evt, art::Ptr<T>(h, idx), label);
61  }
62 
63  /// Express Ptr as a Handle and offset, check all labels
64  template<class T> bool IsFiltered(const art::Event& evt,
65  art::Handle<std::vector<T> > h,
66  int idx)
67  {
68  return IsFiltered(evt, art::Ptr<T>(h, idx));
69  }
70 
71 #endif
72 
73  /// A simple list of products that have been marked "filtered out"
74  template<class T> class FilterList
75  {
76  public:
77 #ifndef __GCCXML__
78  friend bool IsFiltered<>(const art::Event&,
80  const std::vector<std::string>&);
81 
82  void Add(art::Ptr<T> prod)
83  {
84  fFiltered.push_back(prod);
85  }
86  void Add(art::Handle<std::vector<T> > h, int idx)
87  {
88  fFiltered.push_back(art::Ptr<T>(h, idx));
89  }
90 #endif
91  protected:
93  };
94 
95 #ifndef __GCCXML__
96  template<class T> bool IsFiltered(const art::Event& evt,
97  art::Ptr<T> x,
98  const std::vector<std::string>& labels)
99  {
100  std::vector<art::Handle<rb::FilterList<T> > > filts;
101  if(labels.empty()){
102  evt.getManyByType(filts);
103  }
104  else{
105  for(const std::string& label: labels){
106  filts.emplace_back();
107  evt.getByLabel(label, filts.back());
108  if(filts.back().failedToGet()){
109  // mf::LogWarning("FilterList")
110  // << "FilterList not found with label: "
111  // << label;
112  filts.pop_back();
113  }
114  }
115  }
116 
117  for(const art::Handle<rb::FilterList<T>>& filt: filts){
118  for(const art::Ptr<T>& ptr: filt->fFiltered){
119  if(x == ptr) return true;
120  }
121  }
122 
123  return false;
124  }
125 #endif
126 }
127 
128 #endif // RBFILTERLIST_H
129 ////////////////////////////////////////////////////////////////////////
A simple list of products that have been marked "filtered out".
Definition: FilterList.h:74
void Add(art::Handle< std::vector< T > > h, int idx)
Definition: FilterList.h:86
art::PtrVector< T > fFiltered
Definition: FilterList.h:92
friend bool IsFiltered(const art::Event &, art::Ptr< T >, const std::vector< std::string > &)
Is this Ptr marked "filtered out"?
Definition: FilterList.h:96
const char * label
int evt
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
bool IsFiltered(const art::Event &evt, art::Ptr< T > x, const std::vector< std::string > &labels)
Is this Ptr marked "filtered out"?
Definition: FilterList.h:96
Perform a "2 point" Hough transform on a collection of hits.
T prod(const std::vector< T > &v)
Definition: prod.hpp:17
void Add(art::Ptr< T > prod)
Definition: FilterList.h:82
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
TString filt[ntarg]
Definition: Style.C:28
Definition: fwd.h:28
enum BeamMode string