All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DaqDecoderICARUSPMTnotThatOld_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 // Class: DaqDecoderIcarusPMT
3 // Plugin Type: producer (art v2_09_06)
4 // File: DaqDecoderIcarusPMT.cxx
5 //
6 ////////////////////////////////////////////////////////////////////////
7 #include "art/Framework/Core/EDProducer.h"
8 #include "art/Framework/Core/ModuleMacros.h"
9 #include "art/Utilities/make_tool.h"
10 #include "art/Framework/Services/Registry/ServiceHandle.h"
11 #include "art/Framework/Principal/Event.h"
12 
13 #include "canvas/Utilities/InputTag.h"
14 #include "canvas/Utilities/Exception.h"
15 #include "fhiclcpp/ParameterSet.h"
16 #include "fhiclcpp/types/Atom.h"
17 #include "fhiclcpp/types/DelegatedParameter.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 
20 #include "artdaq-core/Data/Fragment.hh"
21 
23 
24 //some standard C++ includes
25 #include <iostream>
26 #include <stdlib.h>
27 #include <string>
28 #include <vector>
29 #include <cassert>
30 
31 namespace daq
32 {
33 
34 /*
35  * The Decoder module takes as input "NevisTPCFragments" and
36  * outputs raw::RawDigits. It also handles in and all issues
37  * with the passed in header and fragments (or at least it will).
38 */
39 class DaqDecoderICARUSPMT: public art::EDProducer
40 {
41 public:
42 
43  /// FHiCL configuration of the module.
44  struct Config {
45 
46  using Name = fhicl::Name;
47  using Comment = fhicl::Comment;
48 
49  fhicl::Atom<art::InputTag> FragmentsLabel {
50  Name("FragmentsLabel"),
51  Comment("data product with the PMT fragments from DAQ"),
52  "daq:CAEN1730" // default
53  };
54 
55  fhicl::Atom<bool> SurviveExceptions {
56  Name("SurviveExceptions"),
57  Comment
58  ("when the decoding tool throws an exception, print a message and move on"),
59  true // default
60  };
61 
62  fhicl::DelegatedParameter DecoderTool {
63  Name("DecoderTool"),
64  Comment
65  ("configuration of decoding tool (daq::IDecoder) to be loaded and used")
66  };
67 
68  }; // struct Config
69 
70  using Parameters = art::EDProducer::Table<Config>;
71 
72 
73  explicit DaqDecoderICARUSPMT(Parameters const & params);
74  // The compiler-generated destructor is fine for non-base
75  // classes without bare pointers or other resource use.
76  // Plugins should not be copied or assigned.
77  DaqDecoderICARUSPMT(DaqDecoderICARUSPMT const &) = delete;
79 
81 
83 
84  /// Initiates PMT configuration reading at run transition.
85  void beginRun(art::Run& run) override;
86 
87  // Required functions.
88  void produce(art::Event & e) override;
89 
90 private:
91 
92  // Tools for decoding fragments depending on type
93  std::unique_ptr<IDecoder> fDecoderTool; ///< Decoder tools
94 
95 
96  art::InputTag const fInputTag;
97 
98  bool const fSurviveExceptions;
99 
100 };
101 
102 DEFINE_ART_MODULE(DaqDecoderICARUSPMT)
103 
105  : art::EDProducer{params}
106  , fInputTag{ params().FragmentsLabel() }
107  , fSurviveExceptions{ params().SurviveExceptions() }
108 {
109  fDecoderTool = art::make_tool<IDecoder>
110  (params().DecoderTool.get<fhicl::ParameterSet>());
111  // Recover the PMT decoder tool
112 
113  consumes<artdaq::Fragments>(fInputTag);
114 
115  // Announce what the tool will do
116  fDecoderTool->consumes(consumesCollector());
117  fDecoderTool->produces(producesCollector());
118 
119  return;
120 }
121 
122 void DaqDecoderICARUSPMT::beginRun(art::Run& run) {
123  assert(fDecoderTool);
124  fDecoderTool->setupRun(run);
125 }
126 
127 void DaqDecoderICARUSPMT::produce(art::Event & event)
128 {
129  assert(fDecoderTool);
130  fDecoderTool->setupEvent(event);
131 
132  // storage for waveform
133  fDecoderTool->initializeDataProducts();
134 
135  // Protect for runs with no PMT info
136  try
137  {
138  // Recover the data fragments for the PMT
139  auto const& fragments = event.getProduct<artdaq::Fragments>(fInputTag);
140 
141  // Make sure data available
142  if (!fragments.empty())
143  {
144  for (auto const &rawFrag: fragments) fDecoderTool->process_fragment(rawFrag);
145  }
146  }
147  catch(cet::exception const& e) {
148  if (!fSurviveExceptions) throw;
149  std::cout << "DaqDecoderICARUSPMT: Did not find daq data products to decode:"
150  << "\n" << e.what() << std::endl;
151  }
152  catch(...)
153  {
154  if (!fSurviveExceptions) throw;
155  std::cout << "DaqDecoderICARUSPMT: Did not find daq data products to decode" << std::endl;
156  }
157 
158  fDecoderTool->outputDataProducts(event);
159 
160  return;
161 }
162 
163 
164 } // end namespace
165 
This provides an art tool interface definition for tools which &quot;decode&quot; artdaq fragments into LArSoft...
void beginRun(art::Run &run) override
Initiates PMT configuration reading at run transition.
DaqDecoderICARUSPMT & operator=(DaqDecoderICARUSPMT const &)=delete
BEGIN_PROLOG vertical distance to the surface Name
std::unique_ptr< IDecoder > fDecoderTool
Decoder tools.
do i e
art::EDProducer::Table< Config > Parameters
BEGIN_PROLOG could also be cout
fDetProps &fDetProps fDetProps &fDetProps consumesCollector())