CRTOnlineMonitor_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: CRTOnlineMonitor
3 // Plugin Type: analyzer (art v2_11_03)
4 // File: CRTOnlineMonitor_module.cc
5 // Brief: Runs the OnlinePlotter algorithm to make online monitoring
6 // plots for the CRT. Provides a wrapper to use OnlinePlotter
7 // within ART.
8 //
9 // Generated at Tue Aug 21 03:22:48 2018 by Andrew Olivier using cetskelgen
10 // from cetlib version v3_03_01.
11 ////////////////////////////////////////////////////////////////////////
12 
13 //Framework includes
21 #include "fhiclcpp/ParameterSet.h"
23 #include "art_root_io/TFileService.h"
24 
25 //CRT includes
28 
29 //c++ includes
30 #include <memory> //For std::unique_ptr
31 
32 class CRTOnlineMonitor;
33 
35 public:
36  explicit CRTOnlineMonitor(fhicl::ParameterSet const & p);
37  // The compiler-generated destructor is fine for non-base
38  // classes without bare pointers or other resource use.
39 
40  // Plugins should not be copied or assigned.
41  CRTOnlineMonitor(CRTOnlineMonitor const &) = delete;
43  CRTOnlineMonitor & operator = (CRTOnlineMonitor const &) = delete;
45 
46  // Required functions.
47  void analyze(art::Event const & e) override;
48 
49  // Selected optional functions.
50  void beginJob() override;
51  void beginRun(art::Run const & r) override;
52  void endRun(art::Run const & r) override;
53  void onFileClose();
54 
55 private:
56 
57  // Use the PIMPL idiom to weaken coupling between this module and the
58  // OnlinePlotter source code.
60  std::unique_ptr<CRT::OnlinePlotter<std::shared_ptr<dir_t>>> fPlotter; //Algorithm that makes online monitoring plots
61  //from CRT::Triggers
62 
63  art::InputTag fCRTLabel; //The name of the module that created the CRT::Triggers this module will read
64 };
65 
66 
68  :
69  EDAnalyzer(p), fPlotter(nullptr), fCRTLabel(p.get<art::InputTag>("CRTLabel"))
70  // More initializers here.
71 {
72  consumes<std::vector<CRT::Trigger>>(fCRTLabel);
73 
74  //Register callback to create new histograms for each file processed
76  tfs->registerFileSwitchCallback(this, &CRTOnlineMonitor::onFileClose);
77 }
78 
80 {
81  // Implementation of required member function here.
82  try
83  {
84  const auto& triggers = e.getValidHandle<std::vector<CRT::Trigger>>(fCRTLabel);
85  fPlotter->AnalyzeEvent(*triggers);
86  }
87  catch(const cet::exception& e)
88  {
89  mf::LogWarning("MissingData") << "Caught exception when trying to find CRT::Triggers from label " << fCRTLabel << ":\n"
90  << e.what() << "\n";
91  }
92 }
93 
95 {
96  // Implementation of optional member function here.
97  onFileClose();
98 }
99 
101 {
103  auto dirPtr = std::shared_ptr<dir_t>(new dir_t(tfs));
104  fPlotter.reset(new CRT::OnlinePlotter<std::shared_ptr<dir_t>>(dirPtr));
105  fPlotter->ReactBeginRun("");
106 }
107 
109 {
110  // Implementation of optional member function here.
111  fPlotter->ReactBeginRun(""); //TODO: Remove std::string from interface for OnlinePlotter and friends
112 }
113 
115 {
116  // Implementation of optional member function here.
117  fPlotter->ReactEndRun(""); //TODO: Remove std::string from interface for OnlinePlotter and friends
118 }
119 
std::unique_ptr< CRT::OnlinePlotter< std::shared_ptr< dir_t > > > fPlotter
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Definition: Run.h:17
void beginRun(art::Run const &r) override
void endRun(art::Run const &r) override
CRT::FlatDirectory< art::ServiceHandle< art::TFileService >> dir_t
CRTOnlineMonitor(fhicl::ParameterSet const &p)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
CRTOnlineMonitor & operator=(CRTOnlineMonitor const &)=delete
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
void analyze(art::Event const &e) override
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33