RawEventUnpacker.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include "DAQDataFormats/RawEvent.h"
3 #include "DAQDataFormats/RawTrigger.h"
4 #include "DAQDataFormats/RawTriggerMask.h"
5 #include "DAQDataFormats/RawTriggerHeader.h"
6 #include "DAQDataFormats/RawDataBlock.h"
7 #include "DAQDataFormats/RawMicroBlock.h"
8 #include "DAQDataFormats/RawMicroSlice.h"
9 #include "DAQDataFormats/RawNanoSlice.h"
10 #include "DAQChannelMap/DAQChannelMap.h"
11 #include "DAQChannelMap/HardwareDisplay.h"
12 #include "NovaTimingUtilities/TimingUtilities.h"
20 
21 using namespace om;
22 
23 static const double kUSEC_PER_TDC = (1.0E6/64.0E6);
24 static const unsigned int kADC_ERROR = 0xFFFFFFFF;
25 
27 {
28  static RawEventUnpacker tupac;
29  return tupac;
30 }
31 
32 //......................................................................
33 
35  fHardwareMapping(new daqchannelmap::HardwareDisplay)
36 {
38 }
39 
40 //......................................................................
41 
44 }
45 
46 //......................................................................
47 
49 
50 //......................................................................
51 
53 {
54  fRESSubscriber.push_back(s);
55 }
56 
57 //......................................................................
58 
60 {
61  fDBSSubscriber.push_back(s);
62 }
63 
64 //......................................................................
65 
67 {
68  fMSSSubscriber.push_back(s);
69 }
70 
71 //......................................................................
72 
74 {
75  fNSSSubscriber.push_back(s);
76 }
77 
78 //......................................................................
79 
81 {
83 
84  evtsum.fRun = rawevt.getRunNumber();
85  evtsum.fSubrun = rawevt.getSubrun();
86  evtsum.fEvent = rawevt.getEventNumber();
87  evtsum.fNdatablock = rawevt.getDataBlockNumber();
88  evtsum.fEventIncomplete = rawevt.getHeader()->isEventIncomplete();
89  evtsum.fTrigger = rawevt.getTrigger()->getTriggerMask()->getTriggerMask();
90  evtsum.fMasterTrigger = rawevt.getTrigger()->getTriggerHeader()->getMasterTriggerNumber();
91  evtsum.fT0 = rawevt.getTrigger()->getTriggerStart();
92  evtsum.fRange = rawevt.getTrigger()->getTriggerRange()->getTriggerLength();
93 
94  // The upper 32 bits of T0 comes from the DCM time. To be able to compare T0
95  // to the TDC time from the nanoslices, we only want the lower 32 bits of T0.
96  const unsigned long int mask32 = 0xFFFFFFFFUL;
97  unsigned long int T0lo = evtsum.fT0 & mask32;
98  evtsum.fT0lo32Usec = T0lo*kUSEC_PER_TDC;
99 
100  uint16_t sec, min, hour, mday, mon;
101  uint32_t year;
103  sec,
104  min,
105  hour,
106  mday,
107  mon,
108  year);
109  evtsum.fHour = hour + (float)min/60.0 + (float)sec/60.0/60.0;
110 
111  if(fDebug) {
112  std::cout << "\n(r/sr/evt): "
113  << evtsum.fRun << " / "
114  << evtsum.fSubrun << " / "
115  << evtsum.fEvent << "\t"
116  << "number of datablocks: "
117  << evtsum.fNdatablock << "\n";
118  std::cout << "\tDatablocks: (N ublocks, isMissingData)\n";
119  }
120 
121  unsigned int idata;
122  for (idata=0; idata<evtsum.fNdatablock; ++idata) {
123 
124  this->UnpackDataBlock(rawevt, idata, evtsum);
125  }
126  this->PublishRawEventSummary(evtsum);
127 }
128 
129 //......................................................................
130 
132  unsigned int idata,
134 {
135  rawevt.setFloatingDataBlock(idata);
136  daqdataformats::RawDataBlock& datablock = (*rawevt.getFloatingDataBlock());
137 
138  DataBlockSummary dbsum;
139  dbsum.fNmicroblock = datablock.getNumMicroBlocks();
140  dbsum.fMissingData = datablock.getHeader()->isMissingData();
141 
142  if(fDebug) {
143  std::cout << "\t("
144  << dbsum.fNmicroblock << ", "
145  << dbsum.fMissingData << ")\n";
146  }
147 
148  if (datablock.getHeader()->getMarker() == daqdataformats::datablockheader::SummaryBlock_Marker ){
149  if(datablock.getHeader()->checkMarker()) {
150  return;
151  }
152  }
153 
154 
155  unsigned int imicro;
156  for (imicro=0; imicro<dbsum.fNmicroblock; ++imicro) {
157  this->UnpackMicroSlice(datablock, imicro, evtsum, dbsum);
158  }
159  this->PublishDataBlockSummary(evtsum,dbsum);
160 }
161 
162 //......................................................................
163 
165  unsigned int imicro,
167  DataBlockSummary& dbsum)
168 {
169  datablock.setFloatingMicroBlock(imicro);
170 
172  microblock = (*datablock.getFloatingMicroBlock());
173 
175  microslice = (*microblock.getMicroSlice());
176 
177  MicroSliceSummary microsum;
178  microsum.fNnanoslice = microslice.getNumNanoSlices();
179 
180  microsum.fDet = microblock.getHeader()->getDetId();
181  microsum.fDiblock = microblock.getHeader()->getDiblockId();
182  microsum.fDCM = microblock.getHeader()->getDCMId();
183  microsum.fDataPresent = microslice.getHeader()->getDataPresent();
184  microsum.fMCflag = microslice.getHeader()->getMonteCarloFlag();
185  microsum.fByteCount = microslice.getHeader()->getByteCount();
186 
187  evtsum.fDiblocks.insert( microsum.fDiblock);
188  evtsum.fDCMs. insert(100*microsum.fDiblock+microsum.fDCM);
189 
190  unsigned int inano;
191  for (inano=0; inano<microsum.fNnanoslice; ++inano) {
192  this->UnpackNanoSlice(microslice, inano, evtsum, dbsum, microsum);
193  }
194 
195  ++evtsum.fNmicroSl;
196 
197  this->PublishMicroSliceSummary(evtsum,dbsum,microsum);
198 }
199 
200 //......................................................................
201 
203  unsigned int inano,
205  DataBlockSummary& dbsum,
206  MicroSliceSummary& microsum)
207 {
208  microslice.setFloatingNanoSlice(inano);
209 
210  daqdataformats::RawNanoSlice& nanoslice = (*microslice.getFloatingNanoSlice());
211  daqdataformats::RawNanoSliceHeader& nanoslicehdr = (*nanoslice.getHeader());
212 
213  NanoSliceSummary nanosum;
214 
215  nanosum.fFEB = nanoslicehdr.getFEBId();
216  nanosum.fPix = nanoslicehdr.getPixelAddr();
217  nanosum.fTDC = nanoslice. getTimeStamp();
218 
219 
220  if(fDebug) {
221  std::cout << "\n(DB/DCM/FEB/Pix): "
222  << "\t" << microsum.fDiblock
223  << "\t" << microsum.fDCM
224  << "\t" << nanosum.fFEB
225  << "\t" << nanosum.fPix;
226  }
227 
228 
229 
230  unsigned int version = nanoslicehdr.getVersion();
231  if(version == 0) {
232  nanosum.fADC = nanoslice.getPulseHeight();
233 
234  if(fDebug) {
235  std::cout << "\nversion: " << version
236  << "\tADC: " << nanosum.fADC;
237  }
238  }
239  if(version > 0) {
240  // This section is basically copied and pasted from DAQ2RawDigit/RawDigit.cxx
241  const unsigned int nSamples = nanoslice.getNSamples();
242  const unsigned int nPretrig = nanoslice.getNPretriggeredSamples();
243  const unsigned int kDCSDistance = 3; // Look back 3 samples (1.5us in the FD)
244 
245  // Check that everything makes sense, otherwise flag the ADC as bad.
246  if((nSamples <= nPretrig) || (nPretrig < kDCSDistance))
247  nanosum.fADC = kADC_ERROR;
248  else
249  nanosum.fADC = nanoslice.getValue(nPretrig) - nanoslice.getValue(nPretrig - kDCSDistance);
250 
251  if(fDebug) {
252  std::cout << "\nversion: " << version
253  << "\t(nSamples/nPretrig):"
254  << " " << nSamples
255  << " " << nPretrig
256  << "\nADC:";
257  for(unsigned int p = 0; p < nSamples; ++p)
258  std::cout << " " << nanoslice.getValue(p);
259  std::cout << "\tcomputed ADC: " << nanosum.fADC << "\n";
260 
261  }
262  }
263 
264 
265  nanosum.fUsec = nanosum.fTDC*kUSEC_PER_TDC;
266 
267  nanosum.fDataPresent = nanoslicehdr.getDataPresent();
268  nanosum.fLinkStatus = nanoslicehdr.getLinkStatus();
269  nanosum.fDebugMode = nanoslicehdr.getDebugMode();
270  nanosum.fFEBStatus = nanoslicehdr.getFEBStatus();
271 
272  // (1<<4) cooresponds to "Enable DAQ" which you want to be set to 1.
273  if (nanosum.fDataPresent == false || nanosum.fLinkStatus == false ||
274  nanosum.fDebugMode == true || nanosum.fFEBStatus != (1<<4)) {
275  ++evtsum.fNfeberr;
276  }
277 
280  nanosum.fDChan = cmap->encodeDChan((novadaq::cnv::DetId)microsum.fDet,
281  microsum.fDiblock,
282  microsum.fDCM,
283  nanosum.fFEB,
284  nanosum.fPix);
285  nanosum.fLChan = cmap->encodeLChan(nanosum.fDChan);
286  nanosum.fPlane = cmap->getPlane(nanosum.fLChan);
287  nanosum.fCell = cmap->getCell(nanosum.fLChan);;
288 
289  nanosum.fView = cmap->getView(nanosum.fDChan);
290 
292  microsum.fDCM,
293  nanosum. fFEB,
294  nanosum. fPix,
295  &nanosum.fHdwX,
296  &nanosum.fHdwY);
297  evtsum.fFEBs.insert(10000*microsum.fDiblock+100*microsum.fDCM+nanosum.fFEB);
298  ++evtsum.fNhit;
299 
300  this->PublishNanoSliceSummary(evtsum,dbsum,microsum,nanosum);
301 }
302 
303 //......................................................................
304 
306 {
307  std::list<SummarySubscriber*>::iterator i(fRESSubscriber.begin());
308  std::list<SummarySubscriber*>::iterator e(fRESSubscriber.end());
309  for (;i!=e; ++i) (*i)->GetRawEventSummary(r);
310 }
311 
312 //......................................................................
313 
315  const DataBlockSummary& d)
316 {
317  std::list<SummarySubscriber*>::iterator i(fDBSSubscriber.begin());
318  std::list<SummarySubscriber*>::iterator e(fDBSSubscriber.end());
319  for (;i!=e; ++i) (*i)->GetDataBlockSummary(r,d);
320 }
321 
322 //......................................................................
323 
325  const DataBlockSummary& d,
326  const MicroSliceSummary& m)
327 {
328  std::list<SummarySubscriber*>::iterator i(fMSSSubscriber.begin());
329  std::list<SummarySubscriber*>::iterator e(fMSSSubscriber.end());
330  for (;i!=e; ++i) (*i)->GetMicroSliceSummary(r,d,m);
331 }
332 
333 //......................................................................
334 
336  const DataBlockSummary& d,
337  const MicroSliceSummary& m,
338  const NanoSliceSummary& n)
339 {
340  std::list<SummarySubscriber*>::iterator i(fNSSSubscriber.begin());
341  std::list<SummarySubscriber*>::iterator e(fNSSSubscriber.end());
342  for (;i!=e; ++i) (*i)->GetNanoSliceSummary(r,d,m,n);
343 }
344 
345 ////////////////////////////////////////////////////////////////////////
346 
unsigned short fDebugMode
Debug mode status bit.
void UnpackDataBlock(daqdataformats::RawEvent &rawevt, unsigned int idata, RawEventSummary &evtsum)
unsigned long int fT0
Trigger time in nova time units (64 Mhz ticks)
unsigned int fMasterTrigger
Master trigger number.
unsigned int fDCM
DCM ID.
void PublishMicroSliceSummary(const RawEventSummary &res, const DataBlockSummary &dbs, const MicroSliceSummary &mbs)
IMPLEMENT_MAIN_STANDARD IMPLEMENT_MAIN_setBufferSource daqdataformats::RawNanoSliceHeader * getHeader() const
Get the NanoSlice header pointer.
Definition: RawNanoSlice.h:57
daqchannelmap::HardwareDisplay * fHardwareMapping
Map pixel address to hardware space.
Unpack the DAQ data, prepare summaries, and post data.
unsigned int fHdwX
location of channel in "hardware display" space
bool fDebug
Flag to print debugging statements.
unsigned int fDiblock
Diblock ID.
void PublishDataBlockSummary(const RawEventSummary &res, const DataBlockSummary &dbs)
Interface for classes that plot data from the event summaries.
virtual DetView_TYPE getView(dchan daqchan) const =0
Which view (X or Y) does this daq channel readout?
const char * p
Definition: xmltok.h:285
uint32_t getNumNanoSlices() const
Get current Hit Probability (for a microslice generation)
std::list< SummarySubscriber * > fDBSSubscriber
Data block summary subscribers.
void SetDebug(bool debug)
bool fMCflag
Monte Carlo flag.
std::set< unsigned int > fFEBs
The list of FEBs contributing to the event.
static const unsigned int kADC_ERROR
void SubscribeToMicroSliceSummary(SummarySubscriber *s)
void UnpackMicroSlice(daqdataformats::RawDataBlock &datablock, unsigned int imicro, RawEventSummary &evtsum, DataBlockSummary &dbsum)
void DAQToXY(unsigned int db, unsigned int dcm, unsigned int feb, unsigned int pix, unsigned int *ix, unsigned int *iy)
unsigned int fPix
Pixel number on FEB.
cell_t getCell(lchan logicalchan) const
Decode the cell number from an lchan.
bool convertNovaTimeToUnixTime(uint64_t const &inputNovaTime, struct timespec &outputUnixTime)
unsigned int fTDC
Time of hit in TDC units.
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
All the interesting event-level data.
unsigned short fLinkStatus
Link status bit.
unsigned int fEvent
Event nunber.
unsigned int fRange
Trigger length in units of 500 nsec.
const XML_Char * s
Definition: expat.h:262
unsigned int fNnanoslice
Number of nano slices.
unsigned int fByteCount
Number of bytes reported by DCM.
unsigned int fDChan
DAQ channel id of this hit.
double fUsec
Time of hit relative to start of micro slice.
void PublishRawEventSummary(const RawEventSummary &s)
bool setFloatingNanoSlice(const uint32_t inano) const
Set the SIM flag.
unsigned int fNmicroSl
Total number of micro slices.
std::set< unsigned int > fDCMs
The list of DCMs contributing to the event.
static DAQChannelMap * getInstance(int detID)
daqdataformats::RawMicroSliceHeader * getHeader() const
void UnpackRawEvent(daqdataformats::RawEvent &rawevt)
float fHour
A fractional hour of the day.
unsigned int fRun
Run number.
unsigned int fSubrun
Subrun number.
std::list< SummarySubscriber * > fMSSSubscriber
Micro slice summary subscribers.
bool fDataPresent
Data Present flag by DCM.
void SubscribeToNanoSliceSummary(SummarySubscriber *s)
Float_t d
Definition: plot.C:236
unsigned int fCell
cell number of hit
unsigned short fDataPresent
Data present status bit.
A simple object that conatins all the global settings.
void UnpackNanoSlice(daqdataformats::RawMicroSlice &microslice, unsigned int inano, RawEventSummary &evtsum, DataBlockSummary &dbsum, MicroSliceSummary &microsum)
OStream cout
Definition: OStream.cxx:6
const XML_Char * version
Definition: expat.h:187
uint32_t fFEBStatus
Status flags.
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
std::list< SummarySubscriber * > fRESSubscriber
Raw event summary subscribers.
void SubscribeToRawEventSummary(SummarySubscriber *s)
unsigned int fADC
Charge of hit in TDC units.
daqchannelmap::DetView_TYPE fView
in which view was the hit
Class to hold the MicroSlice data.
Definition: RawMicroSlice.h:48
std::set< unsigned int > fDiblocks
The list of diblocks in event.
Dumps a summary of info about events to the screen.
unsigned int fDet
Detector ID.
unsigned int fPlane
plane number of hit
unsigned int fTrigger
Trigger type.
unsigned int fNfeberr
Number of FEB errors reported in event.
unsigned int fLChan
Local channel id of this hit.
unsigned int fHdwY
location of channel in "hardware display" space
static RawEventUnpacker & Instance()
plane_t getPlane(lchan logicalchan) const
Decode the plane number from an lchan.
TRandom3 r(0)
unsigned int fFEB
FEB number of nanoslice (aka "hit")
cmap::CMap class source code
Definition: CMap.cxx:17
unsigned int fNdatablock
Number of data blocks.
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
static const double kUSEC_PER_TDC
double fT0lo32Usec
Just the lower 32 bits of T0 converted to Usec.
void SubscribeToDataBlockSummary(SummarySubscriber *s)
void PublishNanoSliceSummary(const RawEventSummary &res, const DataBlockSummary &dbs, const MicroSliceSummary &mbs, const NanoSliceSummary &s)
unsigned int fNhit
Total number of nanoslices (hits)
Float_t e
Definition: plot.C:35
All the interesting event-level data.
static Settings & Instance()
Definition: Settings.cxx:12
bool fEventIncomplete
Is the event incomplete?
bool fMissingData
Is data missing?
unsigned int fNmicroblock
Number of micro blocks.
Online Monitoring package header.
All the interesting event-level data.
std::list< SummarySubscriber * > fNSSSubscriber
Nano slice summary subscribers.
All the interesting event-level data.
daqdataformats::RawNanoSlice * getFloatingNanoSlice() const
Get the MicroSlice Timing Marker.
static constexpr Double_t year
Definition: Munits.h:185