TpcMilliSliceDump_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TpcMilliSliceDump
3 // Module Type: analyzer
4 // File: TpcMilliSliceDump_module.cc
5 // Description: Prints out information about each event.
6 ////////////////////////////////////////////////////////////////////////
7 
12 #include "art_root_io/TFileService.h"
13 
15 #include "lbne-raw-data/Overlays/TpcMilliSliceFragment.hh"
16 #include "artdaq-core/Data/Fragment.hh"
17 
18 #include "TH1.h"
19 
20 #include <algorithm>
21 #include <cassert>
22 #include <cmath>
23 #include <fstream>
24 #include <iomanip>
25 #include <vector>
26 #include <iostream>
27 #include <limits>
28 
29 namespace lbne {
30 class TpcMilliSliceDump;
31 }
32 
34 public:
35  explicit TpcMilliSliceDump(fhicl::ParameterSet const & pset);
36  virtual ~TpcMilliSliceDump();
37 
38  virtual void analyze(art::Event const & evt);
39 
40 private:
41  void beginJob();
42 
45  std::vector<int> verb_microslice_ids_;
46  std::vector<int> verb_nanoslice_ids_;
48  TH1D * adc_values_;
49 };
50 
51 
53 : EDAnalyzer(pset),
54  raw_data_label_(pset.get<std::string>("raw_data_label")),
55  frag_type_(pset.get<std::string>("frag_type")),
56  verb_microslice_ids_(pset.get<std::vector<int>>("verbose_microslice_ids", std::vector<int>(1,0))),
57  verb_nanoslice_ids_ (pset.get<std::vector<int>>("verbose_nanoslice_ids", std::vector<int>(1,0))),
58  verb_nanoslice_adcs_(pset.get<uint32_t> ("verbose_nanoslice_adcs", 6)),
59  adc_values_(nullptr)
60 {
61 }
62 
64 {
66  adc_values_ = tfs->make<TH1D>("adc_values","adc_values",4096,-0.5,4095.5);
67 }
68 
70 {
71 }
72 
74 {
75  //counter of total number of ALL adc values in the event
76  uint32_t n_adc_counter(0);
77  //cumulative total of ALL adc values in the event
78  uint64_t adc_cumulative(0);
79 
80  art::EventNumber_t eventNumber = evt.event();
81 
82  // ***********************
83  // *** TpcMilliSlice Fragments ***
84  // ***********************
85 
86  // look for raw TpcMilliSlice data
87 
90 
91  if (raw.isValid()) {
92  std::cout << "######################################################################" << std::endl;
93  std::cout << std::endl;
94  std::cout << "Run " << evt.run() << ", subrun " << evt.subRun()
95  << ", event " << eventNumber << " has " << raw->size()
96  << " fragment(s) of type " << frag_type_ << std::endl;
97 
98  for (size_t idx = 0; idx < raw->size(); ++idx)
99  {
100  const auto& frag((*raw)[idx]);
101 
102  TpcMilliSliceFragment msf(frag);
103 
104  std::cout << std::endl;
105  std::cout << "TpcMilliSlice fragment " << frag.fragmentID() << " consists of: " << msf.size() << " bytes containing "
106  << msf.microSliceCount() << " microslices" << std::endl;
107  std::cout << std::endl;
108 
109  for (uint32_t i_ms = 0; i_ms < msf.microSliceCount(); ++i_ms)
110  {
111  bool verb_microslice = (std::find(verb_microslice_ids_.begin(), verb_microslice_ids_.end(), i_ms) != verb_microslice_ids_.end()) ? true : false;
112 
113  std::unique_ptr<const TpcMicroSlice> microslice = msf.microSlice(i_ms);
114 
115  if (!microslice) {
116  throw cet::exception("Error in TpcMilliSliceDump module: unable to find requested microslice");
117  }
118 
119  if(verb_microslice) {
120  std::cout << "TpcMilliSlice fragment " << frag.fragmentID()
121  << ", microslice " << i_ms
122  << " has sequence ID " << microslice->sequence_id()
123  << " size " << microslice->size()
124  << " and consists of: "<< microslice->nanoSliceCount() << " nanoslices" << std::endl;
125  }
126 
127  if (microslice->nanoSliceCount() == 0) continue;
128 
129  // First pass through nanoslices listed for verbose output. This is faster than iterating through many nanoslices
130  // and searching for the index in the verbose list
131 
132  for (std::vector<int>::iterator i_nano = verb_nanoslice_ids_.begin(); i_nano != verb_nanoslice_ids_.end(); i_nano++)
133  {
134  bool verb_nanoslice_header = verb_microslice;
135  if (verb_nanoslice_header && (std::find(verb_nanoslice_ids_.begin(), verb_nanoslice_ids_.end(), *i_nano) == verb_nanoslice_ids_.end()))
136  {
137  verb_nanoslice_header = false;
138  }
139 
140  std::unique_ptr<const TpcNanoSlice> nanoslice = microslice->nanoSlice(*i_nano);
141  if (! nanoslice )
142  {
143  throw cet::exception("Error in TpcMilliSliceDump module: Unable to locate requested nanoslice");
144  }
145  if (verb_nanoslice_header)
146  {
147 
148  std::cout << " NanoSlice " << *i_nano << " size " << nanoslice->size() << " bytes" << std::endl << std::endl;
149 
150  const uint64_t* nanoslice_raw = nanoslice->raw();
151 
152  std::cout << " Raw Header : 0x"
153  << std::hex << std::setw(16) << std::setfill('0') << nanoslice_raw[0] <<std::dec << std::endl;
154 
155  std::cout << " Raw Data Payload:" << std::endl << " ";
156  uint16_t num_nanoslice_words = (nanoslice->size() - sizeof(lbne::TpcNanoSlice::Header))/sizeof(uint64_t);
157  size_t word_offset = sizeof(lbne::TpcNanoSlice::Header)/sizeof(uint64_t);
158 
159  for (int i_adc_word = 0; i_adc_word < num_nanoslice_words; i_adc_word++)
160  {
161  std::cout << "0x" << std::hex << std::setfill('0') << std::setw(16) << nanoslice_raw[word_offset+i_adc_word] << std::dec << " ";
162  if ((i_adc_word % 4) == 3) std::cout << std::endl << " ";
163  }
164  std::cout << std::endl;
165 
166  //std::cout << " Decoded Header:" << std::endl;
167  std::cout << " NOvA timestamp : 0x" << std::hex << std::setw(14) << std::setfill('0')
168  << nanoslice->nova_timestamp() << std::dec << std::endl;
169 
170 
171  std::cout << " Decoded ADC Values:" << std::endl << " ";
172  for (uint32_t i_samp = 0; i_samp < nanoslice->getNChannels(); ++i_samp)
173  {
175  nanoslice->sampleValue(i_samp, val);
176  std::cout << std::setfill(' ') << std::setw(4) << i_samp << " : " << std::setw(4) << val << " ";
177  if ((i_samp % 8) == 7) std::cout << std::endl << " ";
178 
179  } // i_samp
180  std::cout << std::endl;
181  }
182  } // i_nano
183 
184  std::cout << std::endl;
185 
186  // Make a second pass through all nanoslices to build some statistics and fill histograms
187  for (uint32_t i_nano = 0; i_nano < microslice->nanoSliceCount(); i_nano++)
188  {
189  std::unique_ptr<const TpcNanoSlice> nanoslice = microslice->nanoSlice(i_nano);
190 
191  if (!nanoslice)
192  {
193  throw cet::exception("Error in TpcMilliSliceDump module: Unable to find requested nanoslice");
194  }
195 
196  for (uint32_t i_samp = 0; i_samp < nanoslice->sampleCount(); i_samp++)
197  {
199  bool success = nanoslice->sampleValue(i_samp, val);
200 
201  if (!success)
202  {
203  throw cet::exception("Error in TpcMilliSliceDump module: Unable to find the requested sample value in nanoslice");
204  }
205  n_adc_counter++;
206  adc_cumulative += (uint64_t)val;
207  adc_values_->Fill(val);
208  } // i_samp
209  } // i_nano
210  } // i_ms
211 
212  } //idx
213 
214  std::cout << std::endl
215  << "Event ADC average is (from counter): " << (double)adc_cumulative/(double)n_adc_counter
216  << std::endl
217  << "Event ADC average is (from histogram): " << adc_values_->GetMean()
218  << std::endl;
219 
220  }//raw.IsValid()?
221  else {
222  std::cout << "Run " << evt.run() << ", subrun " << evt.subRun()
223  << ", event " << eventNumber << " has zero"
224  << " TpcMilliSlice fragments." << std::endl;
225  }
226  std::cout << std::endl;
227 
228 }
229 
intermediate_table::iterator iterator
std::vector< int > verb_microslice_ids_
EventNumber_t event() const
Definition: DataViewImpl.cc:96
virtual void analyze(art::Event const &evt)
std::string string
Definition: nybbler.cc:12
STL namespace.
unsigned short uint16_t
Definition: stdint.h:125
Raw data description.
QTextStream & hex(QTextStream &s)
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
bool isValid() const
Definition: Handle.h:183
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
TpcMilliSliceDump(fhicl::ParameterSet const &pset)
unsigned int uint32_t
Definition: stdint.h:126
unsigned __int64 uint64_t
Definition: stdint.h:136
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:89
RunNumber_t run() const
Definition: DataViewImpl.cc:82
static int max(int a, int b)
QTextStream & dec(QTextStream &s)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::vector< int > verb_nanoslice_ids_
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)