DemoModule_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief The simplest job module possible to illustrate the essential
3 /// features of a job module
4 /// \author $Author: gsdavies $
5 ////////////////////////////////////////////////////////////////////////
6 // C/C++ includes
7 #include <cmath>
8 #include <iostream>
9 #include <string>
10 #include <vector>
11 
12 // ROOT includes
13 #include "TH1F.h"
14 
15 // Framework includes
25 
26 // NOvASoft includes
27 #include "RecoBase/CellHit.h"
28 
29 
30 ///package to illustrate how to write modules
31 namespace demo {
32  class DemoModule : public art::EDProducer {
33  public:
34  explicit DemoModule(fhicl::ParameterSet const& pset); // Required! explicit tag tells the compiler this is not a copy constructor
35  ~DemoModule();
36 
37  // Optional, read/write access to event
38  void produce(art::Event& evt);
39 
40  // Optional if you want to be able to configure from event display, for example
41  void reconfigure(const fhicl::ParameterSet& pset);
42 
43  // Optional use if you have histograms, ntuples, etc you want around for every event
44  void beginJob();
45 
46  private:
47  ///< Sample configurable module parameters
48  int fInt;
49  std::vector<int> fVecInt;
50  float fFloat;
51  double fDouble;
52  std::string fInputModuleLabel; ///> label for module that made the data products you need for this module
53  TH1F* fHisto; ///> a histogram
54 
55  };
56 }
57 
58 ////////////////////////////////////////////////////////////////////////
59 // note it is convention to NOT declare ANY "using namespace xxx" here
60 // especially "using namespace std"
61 namespace demo
62 {
63  //.......................................................................
65  {
66  //======================================================================
67  // This is the constructor "nova" will use to create your module.
68  //
69  // Modules use configurations which have the same name as the
70  // module. The variable "version" sets which version of this
71  // configuration to use. Users are required to supply a configuration
72  // called "default" but other versions ("test" eg.) are allowed.
73  //
74  // Which version to use is set at run time by the job description XML
75  // file.
76  //======================================================================
77 
78  this->reconfigure(pset);
79 
80  // tell the module what it is making as this is a EDProducer
81  produces< std::vector<int> >();
82 
83  // Be noisy to demonstrate what's happening
84  mf::LogInfo("DemoModule") << " DemoModule::DemoModule()\n";
85  }
86 
87  //......................................................................
89  {
90  //======================================================================
91  // Clean up any memory allocated by your module
92  //======================================================================
93  }
94 
95  //......................................................................
97  {
98  // Keep everything lined up for clarity (stylistic)
99  fInt = pset.get< int >("MyInt");
100  fVecInt = pset.get< std::vector<int> >("MyVectorInt");
101  fFloat = pset.get< float >("MyFloat");
102  fDouble = pset.get< double >("MyDouble");
103  fInputModuleLabel = pset.get< std::string >("MyInputModuleLabel");
104  }
105 
106  //......................................................................
108  {
109  //
110  // Book histograms, ntuples, initialize counts etc., etc., ...
111  //
113 
114  fHisto = tfs->make<TH1F>("fHisto",
115  "Histo Title;x-axis title (units);y-axis title (units)",
116  100,0.,100.);
117 
118  }
119 
120  //......................................................................
122  {
123  //======================================================================
124  // Called for every event. "Reco" implies that you are adding
125  // information to the event
126  //======================================================================
127  mf::LogInfo("DemoModule") << "DemoModule::Reco()"
128  << "\n"
129  << "New Reco Event ";
130 
131  // get rb::CellHit from the event
133  evt.getByLabel(fInputModuleLabel, digitcol);
135  for(unsigned int i = 0; i < digitcol->size(); ++i){
136  art::Ptr<rb::CellHit> dig(digitcol, i);
137  digits.push_back(dig);
138  }
139 
140  // make the collection of ints we want to store
141  std::unique_ptr< std::vector<int> > adccol(new std::vector<int>);
142 
143  // fill a histogram with the size of each MCTruth
144  for(unsigned int i = 0; i < digits.size(); ++i){
145  adccol->push_back( digits[i]->ADC() );
146  fHisto->Fill( digits[i]->ADC() );
147  }
148 
149  // put the collection of adc values into the event
150  evt.put(std::move(adccol));
151 
152  // maybe I really wanted to still keep that collection around for later
153  // use in a const fashion. Then I could have done
154  // art::OrphanHandle< std::vector<int> > adcoh = evt.put(adccol);
155 
156  return;
157  }
158 
159 } // end namespace demo
160 ////////////////////////////////////////////////////////////////////////
161 namespace demo
162 {
164 }
void reconfigure(const fhicl::ParameterSet &pset)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
DEFINE_ART_MODULE(TestTMapFile)
The simplest job module possible to illustrate the essential features of a job module.
Definition: demoSysts.C:23
void produce(art::Event &evt)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
T get(std::string const &key) const
Definition: ParameterSet.h:231
int evt
size_type size() const
Definition: PtrVector.h:308
std::vector< int > fVecInt
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
TH1F * fHisto
label for module that made the data products you need for this module
DemoModule(fhicl::ParameterSet const &pset)
std::string fInputModuleLabel
int fInt
< Sample configurable module parameters
enum BeamMode string