FancyScience_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: FancyScience
3 // Module Type: producer
4 // File: FancyScience_module.cc
5 //
6 ////////////////////////////////////////////////////////////////////////
7 
8 // Framework includes
17 #include "fhiclcpp/ParameterSet.h"
19 
20 // NOvASoft includes
21 #include "RawData/RawDigit.h"
22 
23 // ROOT includes
24 #include <TTree.h>
25 
26 
27 namespace tut {
28  namespace yn2020 {
29  class FancyScience;
30  }
31 }
32 
34 public:
35  explicit FancyScience(fhicl::ParameterSet const & p);
36 
37  FancyScience(FancyScience const &) = delete;
38  FancyScience(FancyScience &&) = delete;
39  FancyScience & operator = (FancyScience const &) = delete;
40  FancyScience & operator = (FancyScience &&) = delete;
41 
42  // Required functions.
43  void produce(art::Event& e) override;
44 
45  // Selected optional functions.
46  void beginJob() override;
47  void endJob() override;
48 
49 private:
50  unsigned int fRun; ///< Run number
51  unsigned int fSubRun; ///< Subrun number
52  unsigned int fEvent; ///< Event number
53 
54  unsigned int fRawADC; ///< Raw ADC value to be written into TTree
55 
56  std::string fRawDataLabel; ///< ART module label for Raw Data
57 
58  // This ART Service allows us to interact with TFiles on disk.
60  TTree* fRawDigitTree;
61 };
62 
63 
65  :
66  fRun(0),
67  fSubRun(0),
68  fEvent(0),
69  fRawADC(0),
70  fRawDataLabel(p.get<std::string>("RawDataLabel"))
71 {
72  produces<std::vector<int>>();
73 }
74 
76 {
77  // ART gives us access to some basic information from the event, like
78  // the run, subrun, and event numbers. Let's grab those:
79  fRun = e.run();
80  fSubRun = e.subRun();
81  fEvent = e.event();
82 
83  // Get the RawDigits from the event
85  e.getByLabel(fRawDataLabel, rawHits);
86 
87  // How many are there in this event?
88  std::cout << rawHits->size() << " RawDigits in event " << fEvent << "." << std::endl;
89 
90  // Now I have a rawdata::RawDigit vector and I can do whatever I want with it.
91  // let's loop over them all and get the ADC.
92  for (rawdata::RawDigit aDigit : *rawHits) {
93  fRawADC = aDigit.ADC();
94  fRawDigitTree->Fill();
95  }
96 
97  // Declare a unique pointer and fill our vector
98  std::unique_ptr<std::vector<int>> intProduct(new std::vector<int>);
99  for (size_t i=0; i<42; ++i) { intProduct->push_back(42); }
100 
101  // Put it into the event
102  e.put(std::move(intProduct));
103 
104 
105  return;
106 }
107 
109 {
110  std::cout << "This is the beginJob() function. Declaring TTree..." << std::endl;
111 
112  fRawDigitTree = tfs->make<TTree>("RawDigits", "Raw Digits");
113 
114  fRawDigitTree->Branch("Run", &fRun);
115  fRawDigitTree->Branch("SubRun", &fSubRun);
116  fRawDigitTree->Branch("Event", &fEvent);
117  fRawDigitTree->Branch("ADC", &fRawADC);
118 
119  return;
120 }
121 
123 {
124  // Implementation of optional member function here.
125  std::cout << "This is the endJob() function." << std::endl;
126 
127  return;
128 }
129 
130 // Here be dragons...
SubRunNumber_t subRun() const
Definition: Event.h:72
std::string fRawDataLabel
ART module label for Raw Data.
const char * p
Definition: xmltok.h:285
FancyScience & operator=(FancyScience const &)=delete
unsigned int fRun
Run number.
DEFINE_ART_MODULE(TestTMapFile)
FancyScience(fhicl::ParameterSet const &p)
void produce(art::Event &e) override
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
unsigned int fSubRun
Subrun number.
unsigned int fEvent
Event number.
TODO.
EventNumber_t event() const
Definition: Event.h:67
OStream cout
Definition: OStream.cxx:6
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
art::ServiceHandle< art::TFileService > tfs
unsigned int fRawADC
Raw ADC value to be written into TTree.
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.h:77
enum BeamMode string