BeamlineUnpack.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 /// \file BeamlineUnpack.h
3 /// \brief Methods to interface with the DAQ-formatted output file
4 /// for the beamline components of the test beam experiment.
5 /// \author Mike Wallbank (University of Cincinnati) <wallbank@fnal.gov>
6 /// \date November 2018
7 ////////////////////////////////////////////////////////////////////////////
8 
9 #ifndef DAQ2RAW_BEAMLINEUNPACK_H
10 #define DAQ2RAW_BEAMLINEUNPACK_H
11 
12 // framework
15 #include "artdaq-core/Data/ContainerFragment.hh"
16 #include "artdaq-core/Data/Fragment.hh"
17 #include "cetlib_except/exception.h"
18 #include "fhiclcpp/ParameterSet.h"
20 #include <IFDH_service.h>
21 
22 // online
23 #include "LArIATFragments/LariatFragment.h"
24 #include "LArIATFragments/TriggerFragment.h"
25 #include "LArIATFragments/V1742Fragment.h"
26 #include "LArIATFragments/TDCFragment.h"
27 #include "LArIATFragments/TDUFragment.h"
28 
29 // nova
30 #include "RawData/RawBeamline.h"
34 
35 // root
36 #include "TBranch.h"
37 
38 // stl
39 #include <algorithm>
40 #include <iostream>
41 #include <vector>
42 #include <tuple>
43 #include <string>
44 #include <ctype.h>
45 
46 // -----------------------------------------------------------------------
47 namespace daq2raw {
48 
49  // -----------------------------------------------------------------------
50  /// Retrieves branch name where object resides, using art convention
51  template <typename PROD> std::string getBranchName(const art::InputTag& tag) {
52  std::ostringstream oss;
53  oss << art::TypeID(typeid(PROD)).friendlyClassName()
54  << '_'
55  << tag.label()
56  << '_'
57  << tag.instance()
58  << '_'
59  << tag.process()
60  << ".obj";
61  return oss.str();
62  }
63 
64  // -----------------------------------------------------------------------
65  artdaq::Fragments* getFragments(TBranch* br, unsigned entry);
66 
67  // -----------------------------------------------------------------------
68  class SpillWrapper {
69 
70  public:
71 
72  SpillWrapper(std::size_t nfragments) :
73  nfragments_(nfragments),
75  size_(0)
76  {}
77 
78  void add(const art::Event& evt, const art::InputTag& tag);
79  void add(const artdaq::Fragment& frag);
80 
81  // Consider having get() throw an exception if ready() != true
82  const uint8_t* get() const {return &*buffer_.begin(); }
83 
84  std::size_t size() const {return size_; }
85 
86  bool ready() const { return (nfragments_processed_ == nfragments_) ? true : false; }
87 
88  private:
89 
90  const std::size_t nfragments_;
91  std::vector<uint8_t> buffer_;
92 
93  std::size_t nfragments_processed_;
94  std::size_t size_;
95 
96  };
97 
98  // -----------------------------------------------------------------------
99  class BeamlineEvent {
100 
101  public:
102 
103  BeamlineEvent(unsigned int eventNum);
104  ~BeamlineEvent();
105 
106  unsigned int EventNumber() const;
107 
108  bool GoodEvent() const;
109  void SetBadEvent();
110  void SetGoodEvent();
111 
112  void AddConfig(rawdata::RawBeamlineConfig config);
113  void AddTimestamp(uint64_t timestamp);
114  void AddTDUTime(uint64_t tduTime);
115  void AddTrigger(std::vector<rawdata::RawBeamlineTrigger> trigger);
116  void AddToF(std::vector<rawdata::RawBeamlineDigit> tof);
117  void AddWC(std::vector<rawdata::RawBeamlineWC> wc);
118  void AddCherenkov(std::vector<rawdata::RawBeamlineDigit> cherenkov);
119  void AddMuonStack(std::vector<rawdata::RawBeamlineDigit> muonstack);
120  void AddPaddleDigit(std::vector<rawdata::RawBeamlineDigit> paddle);
121  void AddWCDigit(std::vector<rawdata::RawBeamlineDigit> mwpc);
122  void AddOtherDigit(std::vector<rawdata::RawBeamlineDigit> other);
123 
125  uint64_t GetTimestamp() const;
126  uint64_t GetTDUTime() const;
127  std::vector<rawdata::RawBeamlineTrigger> GetTrigger() const;
128  std::vector<rawdata::RawBeamlineDigit> GetToF() const;
129  std::vector<rawdata::RawBeamlineWC> GetWC() const;
130  std::vector<rawdata::RawBeamlineDigit> GetCherenkov() const;
131  std::vector<rawdata::RawBeamlineDigit> GetMuonStack() const;
132  std::vector<rawdata::RawBeamlineDigit> GetPaddleDigit() const;
133  std::vector<rawdata::RawBeamlineDigit> GetWCDigit() const;
134  std::vector<rawdata::RawBeamlineDigit> GetOtherDigit() const;
135 
136  private:
137 
138  unsigned int fEventNumber;
139 
141 
143  uint64_t fTimestamp;
144  uint64_t fTDUTime;
145  std::vector<rawdata::RawBeamlineTrigger> fTrigger;
146  std::vector<rawdata::RawBeamlineDigit> fToF;
147  std::vector<rawdata::RawBeamlineWC> fWC;
148  std::vector<rawdata::RawBeamlineDigit> fCherenkov;
149  std::vector<rawdata::RawBeamlineDigit> fMuonStack;
150  std::vector<rawdata::RawBeamlineDigit> fPaddleDigit;
151  std::vector<rawdata::RawBeamlineDigit> fWCDigit;
152  std::vector<rawdata::RawBeamlineDigit> fOtherDigit;
153 
154  };
155 
156  // -----------------------------------------------------------------------
158 
159  public:
160 
161  BeamlineEvents();
162  BeamlineEvents(unsigned int numEvents);
163  ~BeamlineEvents();
164 
165  void AddEvent(BeamlineEvent* event);
166  void AddEvents(std::vector<BeamlineEvent*> events);
167  void FilterGoodEvents();
168  BeamlineEvent* FindEvent(unsigned int event);
169  BeamlineEvent* FindEvent(unsigned long long nova_timestamp);
170  unsigned int NumEvents() const;
171  std::vector<BeamlineEvent*> GetEvents() const;
172  BeamlineEvent* GetNextEvent();
173  bool IsNextEvent() const;
174 
175  private:
176 
177  unsigned int fEventIt;
178  std::vector<BeamlineEvent*> fEvents;
179  std::map<unsigned long long, BeamlineEvent*> fEvents_TDUIndex;
180 
181  };
182 
183  // -----------------------------------------------------------------------
185 
186  public:
187 
188  BeamlineUnpack(const fhicl::ParameterSet& pset);
189  ~BeamlineUnpack();
190 
191  // art
192  void reconfigure(const fhicl::ParameterSet& pset);
193 
194  // methods
195  void EndSpill();
196  void Unpack(const LariatFragment* spillFrag,
197  const std::vector<TDUFragment*> tduFrag,
198  unsigned int run = 0,
199  std::string filename = "");
200 
201  // interface
202  BeamlineEvents* GetBeamlineEvents() const;
203 
204  private:
205 
206  // services
210 
211  // configuration
217 
218  unsigned int fChannelsPerTDC;
219  unsigned int fTDCsPerWC;
220  unsigned int fTriggerLatency;
222 
223  // methods
224  std::vector<TriggerPattern::TriggerPattern_t>
225  CleanTriggers(const TriggerFragment& triggerFrag);
226  std::vector<TDUFragment*>
227  CleanTDU(const std::vector<TDUFragment*>& tduFrags);
228  void UnpackConfig(unsigned int run);
229  void UnpackTrigger(const std::vector<TriggerPattern::TriggerPattern_t>& beamlineTriggers,
230  const std::vector<TDUFragment*>& beamlineTDUs,
231  std::string filename = "");
232  void UnpackDigits(const std::vector<V1742Fragment>& frags);
233  void UnpackWC(const TDCFragment& frag);
234 
235  // members
237 
238  };
239 
240 } // namespace
241 
242 #endif
std::vector< rawdata::RawBeamlineDigit > fToF
std::map< unsigned long long, BeamlineEvent * > fEvents_TDUIndex
art::ServiceHandle< beamlinegeo::BeamlineGeometry > fGeometry
std::vector< rawdata::RawBeamlineDigit > fPaddleDigit
std::string friendlyClassName() const
std::size_t size() const
const std::size_t nfragments_
std::vector< uint8_t > buffer_
Definition: config.py:1
std::size_t nfragments_processed_
string filename
Definition: shutoffs.py:106
Definition of the beamline offline geometry. Also implementation of a service to obtain this informat...
std::string getBranchName(const art::InputTag &tag)
Retrieves branch name where object resides, using art convention.
std::vector< rawdata::RawBeamlineWC > fWC
artdaq::Fragments * getFragments(TBranch *br, unsigned entry)
std::vector< rawdata::RawBeamlineDigit > fOtherDigit
Utility to provide the magnetic field in the beamline for a given run number/run conditions. NB/ Currently this will use a lookup defined in a fhicl file, it should and will be replaced by an interface to a database when the field is stored in such a way.
art::ServiceHandle< beamlineutil::BeamlineChannelMap > fChannelMap
std::string const & process() const noexcept
Definition: InputTag.h:67
BeamlineEvents * fBeamlineEvents
rawdata::RawBeamlineConfig fConfig
std::vector< rawdata::RawBeamlineDigit > fWCDigit
std::string const & instance() const noexcept
Definition: InputTag.h:60
std::vector< rawdata::RawBeamlineDigit > fMuonStack
std::vector< rawdata::RawBeamlineDigit > fCherenkov
A module to produce rawdata::RawDigits from NOvADDT DAQHits.
Definition: run.py:1
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
TString GetConfig(int dbcfg)
Definition: PlotDB_Web.C:247
art::ServiceHandle< beamlineutil::BeamlineMagneticField > fMagneticField
std::vector< BeamlineEvent * > fEvents
std::vector< rawdata::RawBeamlineTrigger > fTrigger
Raw data definitions for beamline data used in NOvA test beam experiment.
void add(const art::Event &evt, const art::InputTag &tag)
def entry(str)
Definition: HTMLTools.py:26
void events(int which)
Definition: Cana.C:52
std::string const & label() const noexcept
Definition: InputTag.h:55
unsigned int fChannelsPerTDC
Channel mapping service which may be used to interpret the channels which are read out by the various...
SpillWrapper(std::size_t nfragments)
unsigned int fTriggerLatency