MissingProductFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Very simple module to filter events without all of the expected
4 // products in the event.
5 //
6 // Leigh Whitehead - leigh.howard.whitehead@cern.ch
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 // Framework includes
16 #include "art_root_io/TFileService.h"
20 #include "fhiclcpp/ParameterSet.h"
22 
28 
29 namespace mpf{
31 }
32 
34 public:
35 
36  explicit MissingProductFilter(fhicl::ParameterSet const& pset);
37  virtual ~MissingProductFilter();
38 
39  void beginJob() override;
40  bool filter(art::Event& evt) override;
41  void endJob() override;
42 
43 private:
44 
45  std::vector<std::string> fModules;
46 };
47 
48 //-----------------------------------------------------------------------
50  EDFilter(pset)
51 {
52  fModules = pset.get<std::vector<std::string>>("Modules");
53 }
54 
55 //-----------------------------------------------------------------------
57 
58 //-----------------------------------------------------------------------
60 
61 //-----------------------------------------------------------------------
63 
64  bool prodMissing = false;
65 
66  // Can we do it all together?
67  for(const std::string &s : fModules){
68 
69  try{
70  if(s == "reco3d"){
71  evt.getValidHandle<std::vector<recob::SpacePoint>>(s);
72  }
73  else if(s == "pandora"){
74  evt.getValidHandle<std::vector<recob::PFParticle>>(s);
75  }
76  else if(s == "pandoraTrack"){
77  evt.getValidHandle<std::vector<recob::Track>>(s);
78  }
79  else if(s == "pandoraShower"){
80  evt.getValidHandle<std::vector<recob::Shower>>(s);
81  }
82  else if(s == "opflash" || s == "opflashInternal" || s == "opflashExternal"){
83  evt.getValidHandle<std::vector<recob::OpFlash>>(s);
84  }
85  else{
86  std::cerr << "Product " << s << " is not considered by the module and will be ignored." << std::endl;
87  }
88  }
89  catch(...){
90  prodMissing = true;
91  std::cout << "Product " << s << " is missing. Event will be filtered out." << std::endl;
92  break;
93  }
94 
95  }
96 
97  if(!prodMissing){
98  std::cout << "All products present, keeping this event" << std::endl;
99  }
100  return !prodMissing;
101 
102 }
103 
105 
std::vector< std::string > fModules
std::string string
Definition: nybbler.cc:12
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
bool filter(art::Event &evt) override
Provides recob::Track data product.
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
MissingProductFilter(fhicl::ParameterSet const &pset)
TCEvent evt
Definition: DataStructs.cxx:7
static QCString * s
Definition: config.cpp:1042
QTextStream & endl(QTextStream &s)