SSPDump_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: SSPDump
3 // Module Type: analyzer
4 // File: SSPDump_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/SSPFragment.hh"
16 #include "lbne-raw-data/Overlays/anlTypes.hh"
17 #include "artdaq-core/Data/Fragment.hh"
18 
19 #include "TH1.h"
20 #include "TFile.h"
21 #include <algorithm>
22 #include <cassert>
23 #include <cmath>
24 #include <fstream>
25 #include <iomanip>
26 #include <vector>
27 #include <iostream>
28 #include <limits>
29 
30 namespace lbne {
31  class SSPDump;
32 }
33 
35 public:
36  explicit SSPDump(fhicl::ParameterSet const & pset);
37  virtual ~SSPDump();
38 
39  virtual void analyze(art::Event const & evt) override;
40 
41 private:
42  void beginJob() override;
43  void endJob () override;
44  void beginEvent(art::EventNumber_t eventNumber);
45  void endEvent (art::EventNumber_t eventNumber);
46 
49 
50  //sets the verbosity of std::cout printing
51  //std::vector<int> verb_microslice_ids_;
52  //std::vector<int> verb_nanoslice_ids_;
54  bool verb_meta_;
55 
56  //histograms, counters, etc
57  TH1D * adc_values_;
58  uint32_t n_adc_counter_; //counter of total number of ALL adc values in an event
59  uint64_t adc_cumulative_; //cumulative total of ALL adc values in an event
60 };
61 
62 
64  : EDAnalyzer(pset),
65  raw_data_label_(pset.get<std::string>("raw_data_label")),
66  frag_type_(pset.get<std::string>("frag_type")),
67  //verb_microslice_ids_(pset.get<std::vector<int>>("verbose_microslice_ids", std::vector<int>(1,0))),
68  //verb_nanoslice_ids_ (pset.get<std::vector<int>>("verbose_nanoslice_ids", std::vector<int>(1,0))),
69  verb_adcs_(pset.get<uint32_t> ("verbose_adcs", 10000)),
70  verb_meta_(pset.get<bool> ("verbose_metadata", true)),
71  adc_values_(nullptr),
72  n_adc_counter_(0),
74 {
75 }
76 
78 {
80  adc_values_ = tfs->make<TH1D>("adc_values","adc_values",4096,-0.5,4095.5);
81 }
82 
84 {
85  //reset ADC histogram
86  adc_values_->Reset();
87  //reset counters
88  n_adc_counter_ = 0;
89  adc_cumulative_ = 0;
90 }
91 
93 {
94  //write the ADC histogram for the given event
95  if(n_adc_counter_)
96  adc_values_->Write(Form("adc_values:event_%d", eventNumber));
97 }
98 
100 {
101  delete adc_values_;
102 }
103 
105 {
106 }
107 
109 {
110  art::EventNumber_t eventNumber = evt.event();
111  beginEvent(eventNumber);
112 
113  // TFile f("hists.root","RECREATE");
114  // ***********************
115  // *** SSP Fragments ***
116  // ***********************
117 
118  // look for raw SSP data
119 
122 
123  if (raw.isValid()) {
124  std::cout << "######################################################################" << std::endl;
125  std::cout << std::endl;
126  std::cout << "Run " << evt.run() << ", subrun " << evt.subRun()
127  << ", event " << eventNumber << " has " << raw->size()
128  << " fragment(s) of type " << frag_type_ << std::endl;
129 
130  for (size_t idx = 0; idx < raw->size(); ++idx) {
131  const auto& frag((*raw)[idx]);
132 
133  SSPFragment sspf(frag);
134 
135  std::cout << std::endl;
136  std::cout << "SSP fragment " << frag.fragmentID()
137  << " has total size: " << sspf.hdr_event_size()
138  << " and run number: " << sspf.hdr_run_number()
139  << " with " << sspf.total_adc_values() << " total ADC values"
140  << std::endl;
141  std::cout << std::endl;
142 
143  const SSPDAQ::MillisliceHeader* meta=0;
144  //get the information from the header
145  if(frag.hasMetadata())
146  {
147  meta = &(frag.metadata<SSPFragment::Metadata>()->sliceHeader);
148 
149  std::cout
150  <<"===Slice metadata:"<<std::endl
151  <<"Start time "<<meta->startTime<<std::endl
152  <<"End time "<<meta->endTime<<std::endl
153  <<"Packet length "<<meta->length<<std::endl
154  <<"Number of triggers "<<meta->nTriggers<<std::endl<<std::endl;
155  }
156  else
157  {
158  std::cout << "SSP fragment has no metadata associated with it." << std::endl;
159  }
160 
161  const unsigned int* dataPointer = sspf.dataBegin();
162 
163  unsigned int triggersProcessed=0;
164  while((meta==0||triggersProcessed<meta->nTriggers)&&dataPointer<sspf.dataEnd()){
165  const SSPDAQ::EventHeader* daqHeader=reinterpret_cast<const SSPDAQ::EventHeader*>(dataPointer);
166 
167  uint32_t peaksum = ((daqHeader->group3 & 0x00FF) >> 16) + daqHeader->peakSumLow;
168  if(peaksum & 0x00800000) {
169  peaksum |= 0xFF000000;
170  }
171  if(verb_meta_) {
172  std::cout
173  << "Header: " << daqHeader->header << std::endl
174  << "Length: " << daqHeader->length << std::endl
175  << "Trigger type: " << ((daqHeader->group1 & 0xFF00) >> 8) << std::endl
176  << "Status flags: " << ((daqHeader->group1 & 0x00F0) >> 4) << std::endl
177  << "Header type: " << ((daqHeader->group1 & 0x000F) >> 0) << std::endl
178  << "Trigger ID: " << daqHeader->triggerID << std::endl
179  << "Module ID: " << ((daqHeader->group2 & 0xFFF0) >> 4) << std::endl
180  << "Channel ID: " << ((daqHeader->group2 & 0x000F) >> 0) << std::endl
181  << "External timestamp (FP mode): " << std::endl
182  << " Sync delay: " << ((unsigned int)(daqHeader->timestamp[1]) << 16) + (unsigned int)(daqHeader->timestamp[0]) << std::endl
183  << " Sync count: " << ((unsigned int)(daqHeader->timestamp[3]) << 16) + (unsigned int)(daqHeader->timestamp[2]) << std::endl
184  << "External timestamp (NOvA mode): " << (unsigned long)daqHeader->timestamp[3] << 48 + (unsigned long)daqHeader->timestamp[2] << 32
185  + (unsigned long)daqHeader->timestamp[1] << 16 + (unsigned long)daqHeader->timestamp[0] <<std::endl
186  << "Peak sum: " << peaksum << std::endl
187  << "Peak time: " << ((daqHeader->group3 & 0xFF00) >> 8) << std::endl
188  << "Prerise: " << ((daqHeader->group4 & 0x00FF) << 16) + daqHeader->preriseLow << std::endl
189  << "Integrated sum: " << ((unsigned int)(daqHeader->intSumHigh) << 8) + (((unsigned int)(daqHeader->group4) & 0xFF00) >> 8) << std::endl
190  << "Baseline: " << daqHeader->baseline << std::endl
191  << "CFD Timestamp interpolation points: " << daqHeader->cfdPoint[0] << " " << daqHeader->cfdPoint[1] << " " << daqHeader->cfdPoint[2] << " " << daqHeader->cfdPoint[3] << std::endl
192  << "Internal interpolation point: " << daqHeader->intTimestamp[0] << std::endl
193  << "Internal timestamp: " << ((uint64_t)((uint64_t)daqHeader->intTimestamp[3] << 32)) + ((uint64_t)((uint64_t)daqHeader->intTimestamp[2]) << 16) + ((uint64_t)((uint64_t)daqHeader->intTimestamp[1])) << std::endl
194  << std::endl;
195  }
196  dataPointer+=sizeof(SSPDAQ::EventHeader)/sizeof(unsigned int);
197 
198 
199  //get the information from the data
200  bool verb_values = true;
201  unsigned int nADC=(daqHeader->length-sizeof(SSPDAQ::EventHeader)/sizeof(unsigned int))*2;
202  const unsigned short* adcPointer=reinterpret_cast<const unsigned short*>(dataPointer);
203  char histName[100];
204  sprintf(histName,"event%d",triggersProcessed);
205  //TH1F* hist=new TH1F(histName,histName,nADC,0,nADC*1./150.);
206  // hist->SetDirectory(&f);
207  for(size_t idata = 0; idata < nADC; idata++) {
208  if(idata >= verb_adcs_)
209  verb_values = false;
210  else if(idata == 0&&verb_adcs_>0)
211  std::cout << "Data values: ";
212 
213  const unsigned short* adc = adcPointer + idata;
214  adc_values_->Fill(*adc);
215  n_adc_counter_++;
216  adc_cumulative_ += (uint64_t)(*adc);
217  // hist->SetBinContent(idata+1,*adc);
218 
219  if(verb_values)
220  std::cout << *adc << " ";
221  }
222  dataPointer+=nADC/2;
223  ++triggersProcessed;
224  std::cout<<std::endl<<"Triggers processed: "<<triggersProcessed<<std::endl<<std::endl;
225  }
226  }
227  std::cout << std::endl
228  << "Event ADC average is (from counter): " << (double)adc_cumulative_/(double)n_adc_counter_
229  << std::endl
230  << "Event ADC average is (from histogram): " << adc_values_->GetMean()
231  << std::endl;
232  }//raw.IsValid()?
233  else {
234  std::cout << "Run " << evt.run() << ", subrun " << evt.subRun()
235  << ", event " << eventNumber << " has zero"
236  << " SSP fragments." << std::endl;
237  }
238  std::cout << std::endl;
239  // f.Write();
240  beginEvent(eventNumber);
241 }
242 
EventNumber_t event() const
Definition: DataViewImpl.cc:96
std::string string
Definition: nybbler.cc:12
uint64_t adc_cumulative_
STL namespace.
Raw data description.
void endJob() override
SSPDump(fhicl::ParameterSet const &pset)
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
uint32_t verb_adcs_
void beginJob() override
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
unsigned int uint32_t
Definition: stdint.h:126
std::string raw_data_label_
void endEvent(art::EventNumber_t eventNumber)
void beginEvent(art::EventNumber_t eventNumber)
virtual void analyze(art::Event const &evt) override
uint32_t n_adc_counter_
unsigned __int64 uint64_t
Definition: stdint.h:136
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:89
RunNumber_t run() const
Definition: DataViewImpl.cc:82
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
virtual ~SSPDump()
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
std::string frag_type_
int bool
Definition: qglobal.h:345
QTextStream & endl(QTextStream &s)