All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TPCDecoder_tool.cc
Go to the documentation of this file.
1 /**
2  * @file TPCDecoder_tool.cc
3  *
4  * @brief This tool provides "standard" 3D hits built (by this tool) from 2D hits
5  *
6  */
7 
8 // Framework Includes
9 #include "art/Framework/Core/EDProducer.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "art/Framework/Services/Registry/ServiceHandle.h"
13 #include "art/Persistency/Common/PtrMaker.h"
14 #include "art/Utilities/ToolMacros.h"
15 #include "cetlib/cpu_timer.h"
16 #include "fhiclcpp/ParameterSet.h"
17 #include "messagefacility/MessageLogger/MessageLogger.h"
18 
19 // LArSoft includes
22 
23 #include "sbndaq-artdaq-core/Overlays/ICARUS/PhysCrateFragment.hh"
24 
26 
27 // std includes
28 #include <string>
29 #include <iostream>
30 #include <memory>
31 
32 //------------------------------------------------------------------------------------------------------------------------------------------
33 // implementation follows
34 
35 namespace daq {
36 /**
37  * @brief TPCDecoder class definiton
38  */
39 class TPCDecoder : virtual public IDecoder
40 {
41 public:
42  /**
43  * @brief Constructor
44  *
45  * @param pset
46  */
47  explicit TPCDecoder(fhicl::ParameterSet const &pset);
48 
49  /**
50  * @brief Destructor
51  */
52  ~TPCDecoder();
53 
54  /**
55  * @brief Each algorithm may have different objects it wants "produced" so use this to
56  * let the top level producer module "know" what it is outputting
57  */
58  virtual void produces(art::ProducesCollector&) override;
59 
60  /**
61  * @brief Interface for configuring the particular algorithm tool
62  *
63  * @param ParameterSet The input set of parameters for configuration
64  */
65  virtual void configure(const fhicl::ParameterSet&) override;
66 
67  /**
68  * @brief Initialize any data products the tool will output
69  *
70  */
71  virtual void initializeDataProducts() override;
72 
73  /**
74  * @brief Given a set of recob hits, run DBscan to form 3D clusters
75  *
76  * @param fragment The artdaq fragment to process
77  * @param rawDigitColllection The output RawDigits
78  */
79  virtual void process_fragment(const artdaq::Fragment &fragment) override;
80 
81  /**
82  * @brief Output the data products to the event store
83  *
84  * @param event The event store objects
85  */
86  virtual void outputDataProducts(art::Event& event) override;
87 
88 private:
89 
90  using RawDigitCollectionPtr = std::unique_ptr<std::vector<raw::RawDigit>>;
91 
92  uint32_t fFragment_id_offset; //< Allow offset for id
93 
94  RawDigitCollectionPtr fRawDigitCollection; //< The output data collection pointer
95 
96  const geo::Geometry* fGeometry; //< pointer to the Geometry service
97 };
98 
99 TPCDecoder::TPCDecoder(fhicl::ParameterSet const &pset)
100 {
101  this->configure(pset);
102 }
103 
104 //------------------------------------------------------------------------------------------------------------------------------------------
105 
107 {
108 }
109 
110 void TPCDecoder::produces(art::ProducesCollector& collector)
111 {
112  collector.produces< std::vector<raw::RawDigit>>();
113 }
114 
115 //------------------------------------------------------------------------------------------------------------------------------------------
116 void TPCDecoder::configure(fhicl::ParameterSet const &pset)
117 {
118  fFragment_id_offset = pset.get<uint32_t>("fragment_id_offset");
119 
120  fGeometry = art::ServiceHandle<geo::Geometry const>{}.get();
121 
122  return;
123 }
124 
126 {
127  fRawDigitCollection = RawDigitCollectionPtr(new std::vector<raw::RawDigit>);
128 
129  return;
130 }
131 
132 void TPCDecoder::process_fragment(const artdaq::Fragment &fragment)
133 {
134  size_t fragment_id = fragment.fragmentID() - fFragment_id_offset;
135 
136  // convert fragment to Nevis fragment
137  icarus::PhysCrateFragment physCrateFragment(fragment);
138 
139  size_t nBoardsPerFragment = physCrateFragment.nBoards();
140  size_t nChannelsPerBoard = physCrateFragment.nChannelsPerBoard();
141 
142  //int channel_count=0;
143  for(size_t board = 0; board < physCrateFragment.nBoards(); board++)
144  {
145 // size_t event_number = physCrateFragment.BoardEventNumber(i_b);
146 // size_t timestamp = physCrateFragment.BoardTimeStamp(board);
147 
148  size_t boardId = nChannelsPerBoard * (nBoardsPerFragment * fragment_id + board);
149 
150  // Get the pointer to the start of this board's block of data
151  const icarus::A2795DataBlock::data_t* dataBlock = physCrateFragment.BoardData(board);
152 
153  //A2795DataBlock const& block_data = *(crate_data.BoardDataBlock(i_b));
154  for(size_t channel = 0; channel < physCrateFragment.nChannelsPerBoard(); channel++)
155  {
156  //raw::ChannelID_t channel_num = (i_ch & 0xff ) + (i_b << 8);
157  raw::ChannelID_t channel_num = boardId + channel;
158  raw::RawDigit::ADCvector_t wvfm(physCrateFragment.nSamplesPerChannel());
159 
160  // It seems that the data is read from each channel for each tick so the
161  // loop indices below are chosen to pick out the "right" ticks for a given channel
162  for(size_t tick = 0; tick < physCrateFragment.nSamplesPerChannel(); tick++)
163  wvfm[tick] = dataBlock[channel + tick * physCrateFragment.nChannelsPerBoard()];
164 
165  fRawDigitCollection->emplace_back(channel_num,physCrateFragment.nSamplesPerChannel(),wvfm);
166  }//loop over channels
167  }//loop over boards
168 
169  return;
170 }
171 
172 void TPCDecoder::outputDataProducts(art::Event& event)
173 {
174  // Want the RawDigits to be sorted in channel order... has to be done somewhere so why not now?
175  std::sort(fRawDigitCollection->begin(),fRawDigitCollection->end(),[](const auto& left,const auto&right){return left.Channel() < right.Channel();});
176 
177  // Now transfer ownership to the event store
178  event.put(std::move(fRawDigitCollection));
179 
180  return;
181 }
182 
183 DEFINE_ART_CLASS_TOOL(TPCDecoder)
184 } // namespace lar_cluster3d
IDecoder interface class definiton.
Definition: IDecoder.h:34
virtual void outputDataProducts(art::Event &event) override
Output the data products to the event store.
This provides an art tool interface definition for tools which &quot;decode&quot; artdaq fragments into LArSoft...
walls no right
Definition: selectors.fcl:105
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
uint32_t fFragment_id_offset
Definition of basic raw digits.
RawDigitCollectionPtr fRawDigitCollection
const geo::Geometry * fGeometry
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
virtual void initializeDataProducts() override
Initialize any data products the tool will output.
virtual void produces(art::ProducesCollector &) override
Each algorithm may have different objects it wants &quot;produced&quot; so use this to let the top level produc...
walls no left
Definition: selectors.fcl:105
~TPCDecoder()
Destructor.
The geometry of one entire detector, as served by art.
Definition: Geometry.h:181
virtual void process_fragment(const artdaq::Fragment &fragment) override
Given a set of recob hits, run DBscan to form 3D clusters.
TPCDecoder class definiton.
virtual void configure(const fhicl::ParameterSet &) override
Interface for configuring the particular algorithm tool.
std::unique_ptr< std::vector< raw::RawDigit >> RawDigitCollectionPtr
TPCDecoder(fhicl::ParameterSet const &pset)
Constructor.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
art framework interface to geometry description