All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EXTRetriever_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: EXTRetriever
3 // Plugin Type: producer
4 // File: EXTRetriever_module.cc
5 //
6 // Created by hand Thurs June 24th 2021 by J. Zennamo (FNAL)
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/types/Atom.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
23 
24 #include "artdaq-core/Data/Fragment.hh"
25 #include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerUDPFragment.hh"
26 
30 
31 #include <memory>
32 #include <optional>
33 #include <vector>
34 #include <stdio.h>
35 #include <string.h>
36 #include <time.h>
37 
38 namespace sbn {
39  class EXTRetriever;
40 }
41 
42 class sbn::EXTRetriever : public art::EDProducer {
43 public:
44 
45  struct Config {
46 
47  using Name = fhicl::Name;
48  using Comment = fhicl::Comment;
49 
50  fhicl::Atom<std::string> RawDataLabel {
51  Name{ "raw_data_label" },
52  Comment{ "art data product instance name for trigger information (product label is 'daq')" }
53  };
54 
55  }; // Config
56 
57  using Parameters = art::EDProducer::Table<Config>;
58 
59 
60  explicit EXTRetriever(Parameters const& params);
61  // The compiler-generated destructor is fine for non-base
62  // classes without bare pointers or other resource use.
63 
64  // Plugins should not be copied or assigned.
65  EXTRetriever(EXTRetriever const&) = delete;
66  EXTRetriever(EXTRetriever&&) = delete;
67  EXTRetriever& operator=(EXTRetriever const&) = delete;
68  EXTRetriever& operator=(EXTRetriever&&) = delete;
69 
70  // Required functions.
71  void produce(art::Event& e) override;
72  void beginSubRun(art::SubRun& sr) override;
73  void endSubRun(art::SubRun& sr) override;
74 
75 private:
76  std::vector< sbn::EXTCountInfo > fOutExtInfos;
77 
78  // input labels
79  std::string raw_data_label_;
81 
82 };
83 
84 
86  : EDProducer{params},
87  raw_data_label_(params().RawDataLabel())
88 {
89 
90  produces< std::vector< sbn::EXTCountInfo >, art::InSubRun >();
91  TotalEXTCounts = 0;
92 }
93 
94 void sbn::EXTRetriever::produce(art::Event& e)
95 {
96 
97  //Here we read in the artdaq Fragments and extract three pieces of information:
98  // 1. The time of the current event, t_current_event
99  // 2. the time of the previously triggered event, t_previous_event (NOTE: Events are non-sequential!)
100  // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event
101 
102  int gate_type = 0;
103  auto const & raw_data = e.getProduct< std::vector<artdaq::Fragment> >({ raw_data_label_, "ICARUSTriggerUDP" });
104 
105  unsigned int number_of_gates_since_previous_event = 0;
106 
107  for(auto raw_datum : raw_data){
108 
109  icarus::ICARUSTriggerUDPFragment frag(raw_datum);
110  std::string data = frag.GetDataString();
111  char *buffer = const_cast<char*>(data.c_str());
112  icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer);
113  gate_type = datastream_info.gate_type;
114  number_of_gates_since_previous_event = frag.getDeltaGatesBNB();
115 
116  }
117 
118  //We only want to process EXT gates, i.e. type 3
119  if(gate_type == 3)
120  {
121  // Keep track of the number of beam gates the DAQ thinks
122  // are in this file
123  TotalEXTCounts += number_of_gates_since_previous_event;
124 
125  //Store everything in our data-product
126  sbn::EXTCountInfo extInfo;
127  extInfo.gates_since_last_trigger = number_of_gates_since_previous_event;
128 
129  fOutExtInfos.push_back(extInfo);
130  // We do not write these to the art::Events because
131  // we can filter events but want to keep all the POT
132  // information, so we'll write it to the SubRun
133 
134  }//end check on gate type
135 } //end loop over events
136 
137 
138 void sbn::EXTRetriever::beginSubRun(art::SubRun& sr)
139 {
140  return;
141 }
142 
143 //____________________________________________________________________________
144 void sbn::EXTRetriever::endSubRun(art::SubRun& sr)
145 {
146  // We will add all of the EXTCountInfo data-products to the
147  // art::SubRun so it persists
148  auto p = std::make_unique< std::vector< sbn::EXTCountInfo > >(fOutExtInfos);
149 
150  sr.put(std::move(p));
151 
152  return;
153 }
154 
155 DEFINE_ART_MODULE(sbn::EXTRetriever)
fhicl::Atom< std::string > RawDataLabel
void beginSubRun(art::SubRun &sr) override
void endSubRun(art::SubRun &sr) override
EXTRetriever & operator=(EXTRetriever const &)=delete
pdgs p
Definition: selectors.fcl:22
art::EDProducer::Table< Config > Parameters
Collection of exceptions for Geometry system.
void produce(art::Event &e) override
BEGIN_PROLOG vertical distance to the surface Name
EXTRetriever(Parameters const &params)
std::vector< sbn::EXTCountInfo > fOutExtInfos
int gates_since_last_trigger
Definition: EXTCountInfo.h:16
do i e
Class defining a sparse vector (holes are zeroes)