Public Member Functions | Private Member Functions | Private Attributes | List of all members
daq2raw::BeamlineUnpack Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-09-26/DAQ2RawDigit/testbeam/BeamlineUnpack.h"

Public Member Functions

 BeamlineUnpack (const fhicl::ParameterSet &pset)
 
 ~BeamlineUnpack ()
 
void reconfigure (const fhicl::ParameterSet &pset)
 
void EndSpill ()
 
void Unpack (const LariatFragment *spillFrag, const std::vector< TDUFragment * > tduFrag, unsigned int run=0, std::string filename="")
 
BeamlineEventsGetBeamlineEvents () const
 

Private Member Functions

std::vector< TriggerPattern::TriggerPattern_t > CleanTriggers (const TriggerFragment &triggerFrag)
 
std::vector< TDUFragment * > CleanTDU (const std::vector< TDUFragment * > &tduFrags)
 
void UnpackConfig (unsigned int run)
 
void UnpackTrigger (const std::vector< TriggerPattern::TriggerPattern_t > &beamlineTriggers, const std::vector< TDUFragment * > &beamlineTDUs, std::string filename="")
 
void UnpackDigits (const std::vector< V1742Fragment > &frags)
 
void UnpackWC (const TDCFragment &frag)
 

Private Attributes

art::ServiceHandle< beamlineutil::BeamlineChannelMapfChannelMap
 
art::ServiceHandle< beamlinegeo::BeamlineGeometryfGeometry
 
art::ServiceHandle< beamlineutil::BeamlineMagneticFieldfMagneticField
 
std::string fTriggerSource
 
bool fUnpackTrigger
 
bool fUnpackDigitizer
 
bool fUnpackWireChamber
 
bool fUnpackTDU
 
unsigned int fChannelsPerTDC
 
unsigned int fTDCsPerWC
 
unsigned int fTriggerLatency
 
int fTDUOffset
 
BeamlineEventsfBeamlineEvents
 

Detailed Description

Definition at line 184 of file BeamlineUnpack.h.

Constructor & Destructor Documentation

daq2raw::BeamlineUnpack::BeamlineUnpack ( const fhicl::ParameterSet pset)

Definition at line 292 of file BeamlineUnpack.cxx.

References reconfigure().

292  :
293  fBeamlineEvents(nullptr) {
294  this->reconfigure(pset);
295 }
void reconfigure(const fhicl::ParameterSet &pset)
BeamlineEvents * fBeamlineEvents
daq2raw::BeamlineUnpack::~BeamlineUnpack ( )

Definition at line 298 of file BeamlineUnpack.cxx.

References EndSpill().

298  {
299  this->EndSpill();
300 }

Member Function Documentation

std::vector< TDUFragment * > daq2raw::BeamlineUnpack::CleanTDU ( const std::vector< TDUFragment * > &  tduFrags)
private

Definition at line 345 of file BeamlineUnpack.cxx.

Referenced by Unpack().

345  {
346 
347  // filter just beamline triggers from
348  // the TDU timestamps
349  std::vector<TDUFragment*> beamlineTDUs;
350 
351  // also remove duplicated timestamps
352  std::vector<uint64_t> prevTs;
353 
354  for (std::vector<TDUFragment*>::const_iterator tduFragIt = tduFrags.begin();
355  tduFragIt != tduFrags.end(); ++tduFragIt) {
356 
357  const TDUFragment::TDUFragment_t& tduFrag = (*tduFragIt)->tduFragment[0];
358 
359  if (tduFrag.type == 1 and
360  std::find(prevTs.begin(), prevTs.end(), tduFrag.timestamp) == prevTs.end()) {
361  beamlineTDUs.push_back(*tduFragIt);
362  prevTs.push_back(tduFrag.timestamp);
363  }
364 
365  }
366 
367  return beamlineTDUs;
368 
369 }
std::vector< TriggerPattern::TriggerPattern_t > daq2raw::BeamlineUnpack::CleanTriggers ( const TriggerFragment &  triggerFrag)
private

Definition at line 319 of file BeamlineUnpack.cxx.

References fTriggerLatency, and submit_syst::pattern.

Referenced by Unpack().

319  {
320 
321  // filter triggers saved by the trigger
322  // board to remove any which occured directly
323  // after the previous one
324  std::vector<TriggerPattern::TriggerPattern_t> beamlineTriggers;
325 
326  uint32_t prevT = 0;
327  for (size_t trigIt = 0; trigIt < triggerFrag.triggerFragment.nEntries; ++trigIt) {
328 
329  TriggerPattern::TriggerPattern_t pattern =
330  triggerFrag.triggerFragment.patterns[trigIt];
331 
332  if (pattern.timeStamp - prevT > fTriggerLatency)
333  beamlineTriggers.push_back(pattern);
334 
335  prevT = pattern.timeStamp;
336 
337  }
338 
339  return beamlineTriggers;
340 
341 }
unsigned int fTriggerLatency
void daq2raw::BeamlineUnpack::EndSpill ( )

Definition at line 372 of file BeamlineUnpack.cxx.

References fBeamlineEvents.

Referenced by ~BeamlineUnpack().

372  {
373  if (fBeamlineEvents)
374  delete fBeamlineEvents;
375  fBeamlineEvents = nullptr;
376 }
BeamlineEvents * fBeamlineEvents
daq2raw::BeamlineEvents * daq2raw::BeamlineUnpack::GetBeamlineEvents ( ) const

Definition at line 379 of file BeamlineUnpack.cxx.

References fBeamlineEvents.

379  {
380  return fBeamlineEvents;
381 }
BeamlineEvents * fBeamlineEvents
void daq2raw::BeamlineUnpack::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 303 of file BeamlineUnpack.cxx.

References fChannelsPerTDC, fTDCsPerWC, fTDUOffset, fTriggerLatency, fTriggerSource, fUnpackDigitizer, fUnpackTDU, fUnpackTrigger, fUnpackWireChamber, and fhicl::ParameterSet::get().

Referenced by BeamlineUnpack().

303  {
304  fTriggerSource = pset.get<std::string>("TriggerSource", "Trigger");
305  fUnpackTrigger = pset.get<bool>("UnpackTrigger", true);
306  fUnpackDigitizer = pset.get<bool>("UnpackDigitizer", true);
307  fUnpackWireChamber = pset.get<bool>("UnpackWireChamber", true);
308  fUnpackTDU = pset.get<bool>("UnpackTDU", true);
309 
310  fChannelsPerTDC = pset.get<unsigned int>("ChannelsPerTDC", 64);
311  fTDCsPerWC = pset.get<unsigned int>("TDCsPerWC", 2);
312 
313  fTriggerLatency = pset.get<unsigned int>("TriggerLatency", 0);
314  fTDUOffset = pset.get<int> ("TDUOffset", 0);
315 }
T get(std::string const &key) const
Definition: ParameterSet.h:231
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
unsigned int fChannelsPerTDC
unsigned int fTriggerLatency
void daq2raw::BeamlineUnpack::Unpack ( const LariatFragment *  spillFrag,
const std::vector< TDUFragment * >  tduFrag,
unsigned int  run = 0,
std::string  filename = "" 
)

Definition at line 384 of file BeamlineUnpack.cxx.

References CleanTDU(), CleanTriggers(), allTimeWatchdog::endl, fBeamlineEvents, fTriggerSource, fUnpackDigitizer, fUnpackTDU, fUnpackTrigger, fUnpackWireChamber, UnpackConfig(), UnpackDigits(), UnpackTrigger(), and UnpackWC().

387  {
388 
389  // get trigger information
390  const TriggerFragment triggerFrag = spillFrag->triggerFragment;
391 
392  // get digits
393  const std::vector<V1742Fragment> v1742Frags = spillFrag->v1742Frags;
394 
395  // get wire chambers
396  TDCFragment tdcFrag;
397  if (fUnpackWireChamber and spillFrag->tdcFrags.size())
398  tdcFrag = spillFrag->tdcFrags[0];
399 
400  mf::LogVerbatim("BeamlineUnpack::Unpack")
401  << "There are " << triggerFrag.triggerFragment.nEntries << " triggers, "
402  << v1742Frags.size() << " digitizer triggers, "
403  << tdcFrag.tdcEvents.size() << " wire chamber triggers and "
404  << tduFrags.size() << " TDU timestamps." << std::endl;
405 
406  // clean up various fragments of data
407  std::vector<TriggerPattern::TriggerPattern_t> triggers_clean
408  = CleanTriggers(triggerFrag);
409  std::vector<TDUFragment*> tdu_clean = CleanTDU(tduFrags);
410 
411  mf::LogVerbatim("BeamlineUnpack::Unpack")
412  << "After cleaning, there are " << triggers_clean.size() << " triggers, "
413  << v1742Frags.size() << " digitizer triggers, "
414  << tdcFrag.tdcEvents.size() << " wire chamber triggers and "
415  << tdu_clean.size() << " TDU timestamps." << std::endl;
416 
417  // for testing and commissioning, we may have variable numbers of triggers
418  // in each component.
419  // deal with all possibilities
420  unsigned int numTriggers = 0;
421  if (fTriggerSource == "Trigger")
422  numTriggers = triggers_clean.size();
423  else if (fTriggerSource == "Digitizer")
424  numTriggers = v1742Frags.size();
425  else if (fTriggerSource == "WireChamber")
426  numTriggers = tdcFrag.tdcEvents.size();
427  else if (fTriggerSource == "TDU")
428  numTriggers = tdu_clean.size();
429 
430  // strictly enforce the correct number of fragments for each of the
431  // front-end data components we are trying to unpack
432  if ((fUnpackTrigger and triggers_clean.size() != numTriggers) or
433  (fUnpackDigitizer and v1742Frags.size() != numTriggers) or
434  (fUnpackWireChamber and tdcFrag.tdcEvents.size() != numTriggers) or
435  (fUnpackTDU and tdu_clean.size() != numTriggers))
436  throw cet::exception("BeamlineUnpack")
437  << "Inconsistent number of data fragments: "
438  << "Triggers: " << triggers_clean.size() << "; "
439  << "Digitizer: " << v1742Frags.size() << "; "
440  << "Wire Chambers: " << tdcFrag.tdcEvents.size() << "; "
441  << "TDU: " << tdu_clean.size() << "."
442  << std::endl;
443 
444  // make a new BeamlineEvents object to contain the information
445  fBeamlineEvents = new BeamlineEvents(numTriggers);
446 
447  // get the spill information
448  //LariatFragment::SpillTrailer spillFrag = frag->spillTrailer;
449 
450  // unpack everything
451  this->UnpackConfig(run);
452  if (fUnpackTrigger or fUnpackTDU)
453  this->UnpackTrigger(triggers_clean, tdu_clean, filename);
454  if (fUnpackDigitizer)
455  this->UnpackDigits(v1742Frags);
456  if (fUnpackWireChamber)
457  this->UnpackWC(tdcFrag);
458 
459  return;
460 
461 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
string filename
Definition: shutoffs.py:106
BeamlineEvents * fBeamlineEvents
std::vector< TDUFragment * > CleanTDU(const std::vector< TDUFragment * > &tduFrags)
Definition: run.py:1
void UnpackTrigger(const std::vector< TriggerPattern::TriggerPattern_t > &beamlineTriggers, const std::vector< TDUFragment * > &beamlineTDUs, std::string filename="")
void UnpackDigits(const std::vector< V1742Fragment > &frags)
void UnpackWC(const TDCFragment &frag)
std::vector< TriggerPattern::TriggerPattern_t > CleanTriggers(const TriggerFragment &triggerFrag)
void UnpackConfig(unsigned int run)
void daq2raw::BeamlineUnpack::UnpackConfig ( unsigned int  run)
private

Definition at line 464 of file BeamlineUnpack.cxx.

References daq2raw::BeamlineEvent::AddConfig(), gen_flatrecord::config, e, fBeamlineEvents, daq2raw::BeamlineEvents::FindEvent(), fMagneticField, beamlineutil::BeamlineMagneticField::MagneticField(), daq2raw::BeamlineEvents::NumEvents(), rawdata::RawBeamlineConfig::SetBeamlineRun(), and rawdata::RawBeamlineConfig::SetBField().

Referenced by Unpack().

464  {
465 
467 
468  // beamline run
469  config.SetBeamlineRun(run);
470 
471  // magnetic field
472  float b_field = 0.;
473  try {
474  b_field = fMagneticField->MagneticField(run);
475  }
476  catch (cet::exception& e) {
477  e.what();
478  }
479  config.SetBField(b_field);
480 
481  for (unsigned int event = 0; event < fBeamlineEvents->NumEvents(); ++event)
482  fBeamlineEvents->FindEvent(event)->AddConfig(config);
483 
484  return;
485 
486 }
void SetBeamlineRun(unsigned int run)
Definition: RawBeamline.cxx:18
BeamlineEvent * FindEvent(unsigned int event)
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
BeamlineEvents * fBeamlineEvents
void SetBField(float b_field)
Definition: RawBeamline.cxx:24
Definition: run.py:1
art::ServiceHandle< beamlineutil::BeamlineMagneticField > fMagneticField
float MagneticField(unsigned int beamline_run)
Return the magnetic field for a given beamline data run.
void AddConfig(rawdata::RawBeamlineConfig config)
Float_t e
Definition: plot.C:35
unsigned int NumEvents() const
void daq2raw::BeamlineUnpack::UnpackDigits ( const std::vector< V1742Fragment > &  frags)
private

Definition at line 561 of file BeamlineUnpack.cxx.

References beamlineutil::BeamlineChannelMap::ActiveDigitChannel(), daq2raw::BeamlineEvent::AddCherenkov(), daq2raw::BeamlineEvent::AddMuonStack(), daq2raw::BeamlineEvent::AddOtherDigit(), daq2raw::BeamlineEvent::AddPaddleDigit(), daq2raw::BeamlineEvent::AddToF(), daq2raw::BeamlineEvent::AddWCDigit(), beamlinegeo::Cherenkov, beamlineutil::BeamlineChannelMap::DigitChannel(), fBeamlineEvents, fChannelMap, daq2raw::BeamlineEvents::FindEvent(), beamlinegeo::MuonStack, beamlinegeo::Other, beamlinegeo::Paddle, rawdata::RawBeamlineDigit::SetWaveform(), submit_nova_art::timestamp, beamlinegeo::ToF, and beamlinegeo::WCDigit.

Referenced by Unpack().

561  {
562 
563  // Look through all triggers
564  for (unsigned int v1742FragIt = 0; v1742FragIt < frags.size(); ++v1742FragIt) {
565 
566  const V1742Fragment& v1742Frag = frags[v1742FragIt];
567 
568  std::vector<rawdata::RawBeamlineDigit> cherenkovDigits, tofDigits,
569  muonStackDigits, paddleDigits, wcDigits, otherDigits;
570 
571  // Get all channels for this V1742 fragment
572  for (unsigned int waveform = 0; waveform < v1742Frag.waveForms.size(); ++waveform) {
573 
574  if (!fChannelMap->ActiveDigitChannel(waveform))
575  continue;
576 
577  uint64_t timestamp
578  = static_cast<uint64_t>(v1742Frag.triggerTimeStamps[static_cast<int>(waveform/8)]); // timestamps are saved per group
579  long double timestamp_ns = static_cast<long double>(timestamp) * 8.5; //ns
580 
582  digit.SetWaveform(v1742Frag.waveForms[waveform].data);
583  digit.SetTimestamp(timestamp_ns);
584 
585  switch (digit.ChannelID().System) {
587  cherenkovDigits.push_back(digit); break;
589  tofDigits.push_back(digit); break;
591  muonStackDigits.push_back(digit); break;
593  paddleDigits.push_back(digit); break;
595  wcDigits.push_back(digit); break;
597  otherDigits.push_back(digit); break;
598  default:
599  break;
600  }
601 
602  }
603 
604  fBeamlineEvents->FindEvent(v1742FragIt)->AddToF(tofDigits);
605  fBeamlineEvents->FindEvent(v1742FragIt)->AddCherenkov(cherenkovDigits);
606  fBeamlineEvents->FindEvent(v1742FragIt)->AddMuonStack(muonStackDigits);
607  fBeamlineEvents->FindEvent(v1742FragIt)->AddPaddleDigit(paddleDigits);
608  fBeamlineEvents->FindEvent(v1742FragIt)->AddWCDigit(wcDigits);
609  fBeamlineEvents->FindEvent(v1742FragIt)->AddOtherDigit(otherDigits);
610 
611  }
612 
613  return;
614 
615 }
void AddOtherDigit(std::vector< rawdata::RawBeamlineDigit > other)
void AddToF(std::vector< rawdata::RawBeamlineDigit > tof)
BeamlineEvent * FindEvent(unsigned int event)
void AddWCDigit(std::vector< rawdata::RawBeamlineDigit > mwpc)
void SetWaveform(std::vector< uint16_t > waveform)
art::ServiceHandle< beamlineutil::BeamlineChannelMap > fChannelMap
BeamlineEvents * fBeamlineEvents
bool ActiveDigitChannel(unsigned int channel) const
Enquire whether this online digitizer channel is active.
void AddMuonStack(std::vector< rawdata::RawBeamlineDigit > muonstack)
ChannelID DigitChannel(unsigned int channel) const
Offline ChannelID for this online digitizer channel.
void AddPaddleDigit(std::vector< rawdata::RawBeamlineDigit > paddle)
void AddCherenkov(std::vector< rawdata::RawBeamlineDigit > cherenkov)
void daq2raw::BeamlineUnpack::UnpackTrigger ( const std::vector< TriggerPattern::TriggerPattern_t > &  beamlineTriggers,
const std::vector< TDUFragment * > &  beamlineTDUs,
std::string  filename = "" 
)
private

Definition at line 489 of file BeamlineUnpack.cxx.

References daq2raw::BeamlineEvent::AddTDUTime(), daq2raw::BeamlineEvent::AddTimestamp(), daq2raw::BeamlineEvent::AddTrigger(), fBeamlineEvents, fChannelMap, daq2raw::BeamlineEvents::FindEvent(), fTDUOffset, fUnpackTDU, fUnpackTrigger, findDuplicateFiles::key, make_syst_table_plots::line, runNovaSAM::metadata, elec2geo::pos, rawdata::RawBeamlineTrigger::SetTimestamp(), submit_nova_art::timestamp, and beamlineutil::BeamlineChannelMap::TrigDetector().

Referenced by Unpack().

491  {
492 
493  // get number of triggers
494  unsigned int numTrigs = fUnpackTDU ?
495  beamlineTDUs.size() : beamlineTriggers.size();
496 
497  // get metadata, containing other information about the trigger
499  if (!filename.empty()) {
500  char* fullpathname = (char*)filename.c_str();
501  std::string relfilename = std::string(basename(fullpathname));
503  try {
504  metadata = ifdhp->getMetadata(relfilename);
505  }
506  catch (WebAPIException) {
507  metadata = "";
508  }
509  }
510 
511  // get trigger condition for this file
512  std::string trigger_condition = "";
513  std::istringstream metadataStream;
514  metadataStream.str(metadata);
515  while (metadataStream.good()) {
517  std::getline(metadataStream, line);
518  size_t pos = line.find(":");
519  if (pos != std::string::npos) {
520  key = line.substr(0, pos);
521  value = line.substr(pos+1);
522  if (key.find("Beamline.BeamlineTrigger") != std::string::npos) {
523  value.erase(std::remove(value.begin(), value.end(), ' '), value.end());
524  trigger_condition = value;
525  }
526  }
527  }
528 
529  // make new RawBeamlineTriggers
530  for (unsigned int triggerIt = 0; triggerIt < numTrigs; ++triggerIt) {
531 
532  // get timestamps
533  uint64_t timestamp =
534  fUnpackTrigger? static_cast<uint64_t>(beamlineTriggers[triggerIt].timeStamp) : 0;
535  long double timestamp_ns = timestamp * 10; //ns
536 
537  // get tdu timestamp
538  uint64_t tduTime = fUnpackTDU? (beamlineTDUs[triggerIt]->tduFragment.at(0).timestamp + fTDUOffset) : 0;
539 
540  // make trigger object
542  triggerIt);
543  trigger.SetTimestamp(timestamp_ns);
544  trigger.SetPattern(fUnpackTrigger? beamlineTriggers[triggerIt].inputPattern : 0);
545  trigger.SetTDUTime(tduTime);
546  trigger.SetTriggerCondition(trigger_condition);
547  std::vector<rawdata::RawBeamlineTrigger> triggers = {trigger};
548 
549  // add to event
550  fBeamlineEvents->FindEvent(triggerIt)->AddTrigger(triggers);
551  fBeamlineEvents->FindEvent(triggerIt)->AddTimestamp(timestamp_ns);
552  fBeamlineEvents->FindEvent(triggerIt)->AddTDUTime(tduTime);
553 
554  }
555 
556  return;
557 
558 }
void AddTimestamp(uint64_t timestamp)
DetectorID TrigDetector() const
Offline DetectorID for trigger.
BeamlineEvent * FindEvent(unsigned int event)
void AddTrigger(std::vector< rawdata::RawBeamlineTrigger > trigger)
string filename
Definition: shutoffs.py:106
art::ServiceHandle< beamlineutil::BeamlineChannelMap > fChannelMap
const XML_Char int const XML_Char * value
Definition: expat.h:331
BeamlineEvents * fBeamlineEvents
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void AddTDUTime(uint64_t tduTime)
void SetTimestamp(uint64_t timestamp)
Definition: RawBeamline.cxx:58
void daq2raw::BeamlineUnpack::UnpackWC ( const TDCFragment &  frag)
private

Definition at line 618 of file BeamlineUnpack.cxx.

References daq2raw::BeamlineEvent::AddWC(), allTimeWatchdog::endl, fBeamlineEvents, fChannelMap, fChannelsPerTDC, fGeometry, daq2raw::BeamlineEvents::FindEvent(), fTDCsPerWC, makeTrainCVSamples::int, beamlinegeo::BeamlineGeometry::NumWCs(), daq2raw::BeamlineEvent::SetBadEvent(), submit_nova_art::timestamp, submit_hadd::u, and beamlineutil::BeamlineChannelMap::WCDetector().

Referenced by Unpack().

618  {
619 
620  // loop over events
621  unsigned int event = 0;
622  std::vector<std::vector<TDCFragment::TdcEventData> > tdcEvents = frag.tdcEvents;
623  for (std::vector<std::vector<TDCFragment::TdcEventData> >::const_iterator tdcEventIt = tdcEvents.begin();
624  tdcEventIt != tdcEvents.end(); ++tdcEventIt, ++event) {
625 
626  std::vector<rawdata::RawBeamlineWC> wcs(fGeometry->NumWCs());
627  for (unsigned int wc_num = 0; wc_num < wcs.size(); ++wc_num)
628  wcs[wc_num] = rawdata::RawBeamlineWC(fChannelMap->WCDetector(wc_num));
629 
630  // get the timestamp for this event
631  // Non-trivial!
632  // See https://cdcvs.fnal.gov/redmine/attachments/51083/TDC_Format_Description_B.pdf for a full description
633  // Each TDC header has a 'controller timestamp' (16 bit, 1.18 ns ticks) and 'tdc timestamp' (32 bit, 9.4 ns ticks)
634  // --> I _believe_ they should be the same for each TDC in the event (so enforce this)
635  // The bits 11..3 for the controller timestamp should be identical to bits 8..0 in the TDC timestamp
636  // In order to construct the full timestamp, need to concatenate the 3 lsbs from the controller timestamp
637  // to the TDC timestamp to make a 35 bit word. This is a timestamp in 1.18 ns ticks since the start of the spill
638  std::map<unsigned int, uint16_t> controllerTimestamps;
639  std::map<unsigned int, uint32_t> tdcTimestamps;
640 
641  // loop over TDCs in this event
642  for (std::vector<TDCFragment::TdcEventData>::const_iterator tdcIt = tdcEventIt->begin(); tdcIt != tdcEventIt->end(); ++tdcIt) {
643 
644  unsigned int tdcNumber = (int)tdcIt->tdcEventHeader.tdcNumber - 1;
645  unsigned int wcNumber = tdcNumber / fGeometry->NumWCs();
646  unsigned int tdc_on_wc = tdcNumber % fGeometry->NumWCs();
647  unsigned int tdc_on_plane = tdc_on_wc % fTDCsPerWC;
648  unsigned int plane_on_wc = tdc_on_wc / fTDCsPerWC;
649 
650  // timestamps
651  controllerTimestamps[tdcNumber] = tdcIt->tdcEventHeader.controllerTimeStamp;
652  tdcTimestamps[tdcNumber] = tdcIt->tdcEventHeader.tdcTimeStamp;
653 
654  // overflow register, one for each TDC so if any are set then the whole WC gets true
655  if (tdcIt->tdcEventHeader.eventStatus != 0)
657 
658  // loop over hits in this TDC
659  for (std::vector<TDCFragment::TdcHit>::const_iterator hitIt = tdcIt->tdcHits.begin(); hitIt != tdcIt->tdcHits.end(); ++hitIt) {
660  unsigned int channel_on_plane = (tdc_on_plane * fChannelsPerTDC) + (int)hitIt->channel;
661  rawdata::RawBeamlineWC::WCPulse pulse(channel_on_plane, hitIt->timeBin);
662  plane_on_wc ? wcs[wcNumber].AddYPulse(pulse) : wcs[wcNumber].AddXPulse(pulse);
663  }
664 
665  }
666 
667  // form total timestamp for event relative to start of spill
668  for (std::map<unsigned int, uint16_t>::const_iterator controllerTsIt = controllerTimestamps.begin();
669  controllerTsIt != controllerTimestamps.end(); ++controllerTsIt)
670  if (controllerTsIt->second != controllerTimestamps.begin()->second)
671  throw cet::exception("BeamlineUnpack::UnpackWC")
672  << "WC controller timestamps differ between TDC fragments." << std::endl;
673 
674  for (std::map<unsigned int, uint32_t>::const_iterator tdcTsIt = tdcTimestamps.begin();
675  tdcTsIt != tdcTimestamps.end(); ++tdcTsIt)
676  if (tdcTsIt->second != tdcTimestamps.begin()->second)
677  throw cet::exception("BeamlineUnpack::UnpackWC")
678  << "TDC timestamps differ between TDC fragments." << std::endl;
679 
680  uint32_t tdcTs = tdcTimestamps.begin()->second;
681  uint32_t controllerTs = controllerTimestamps.begin()->second;
682 
683  uint16_t tdcCommon = tdcTs & 0x1FFu;
684  uint16_t controllerCommon = (controllerTs & 0xFF8u) >> 3;
685  if (tdcCommon != controllerCommon)
686  throw cet::exception("BeamlineUnpack::UnpackWC")
687  << "Synchronization problem between MWPC controller and TDC timestamps." << std::endl
688  << "Bits 8..0 of TDC timestamp " << std::bitset<9>(tdcCommon) << "; "
689  << "bits 11..3 of controller timetamp " << std::bitset<9>(controllerCommon) << std::endl;
690 
691  uint64_t timestamp = static_cast<uint64_t>(((std::bitset<35>(tdcTimestamps.begin()->second) << 3) |
692  (std::bitset<35>(controllerTimestamps.begin()->second & 0x7))).to_ullong());
693  long double timestamp_ns = timestamp * 1.18; //ns
694  for (std::vector<rawdata::RawBeamlineWC>::iterator wcIt = wcs.begin(); wcIt != wcs.end(); ++wcIt)
695  wcIt->SetTimestamp(timestamp_ns);
696 
697  fBeamlineEvents->FindEvent(event)->AddWC(wcs);
698 
699  }
700 
701  return;
702 
703 }
art::ServiceHandle< beamlinegeo::BeamlineGeometry > fGeometry
BeamlineEvent * FindEvent(unsigned int event)
unsigned int NumWCs() const
Number of WCs in beamline.
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
void AddWC(std::vector< rawdata::RawBeamlineWC > wc)
art::ServiceHandle< beamlineutil::BeamlineChannelMap > fChannelMap
BeamlineEvents * fBeamlineEvents
unsigned int fChannelsPerTDC
DetectorID WCDetector(unsigned int detector) const
Offline DetectorID for this online WC detector.

Member Data Documentation

BeamlineEvents* daq2raw::BeamlineUnpack::fBeamlineEvents
private
art::ServiceHandle<beamlineutil::BeamlineChannelMap> daq2raw::BeamlineUnpack::fChannelMap
private

Definition at line 207 of file BeamlineUnpack.h.

Referenced by UnpackDigits(), UnpackTrigger(), and UnpackWC().

unsigned int daq2raw::BeamlineUnpack::fChannelsPerTDC
private

Definition at line 218 of file BeamlineUnpack.h.

Referenced by reconfigure(), and UnpackWC().

art::ServiceHandle<beamlinegeo::BeamlineGeometry> daq2raw::BeamlineUnpack::fGeometry
private

Definition at line 208 of file BeamlineUnpack.h.

Referenced by UnpackWC().

art::ServiceHandle<beamlineutil::BeamlineMagneticField> daq2raw::BeamlineUnpack::fMagneticField
private

Definition at line 209 of file BeamlineUnpack.h.

Referenced by UnpackConfig().

unsigned int daq2raw::BeamlineUnpack::fTDCsPerWC
private

Definition at line 219 of file BeamlineUnpack.h.

Referenced by reconfigure(), and UnpackWC().

int daq2raw::BeamlineUnpack::fTDUOffset
private

Definition at line 221 of file BeamlineUnpack.h.

Referenced by reconfigure(), and UnpackTrigger().

unsigned int daq2raw::BeamlineUnpack::fTriggerLatency
private

Definition at line 220 of file BeamlineUnpack.h.

Referenced by CleanTriggers(), and reconfigure().

std::string daq2raw::BeamlineUnpack::fTriggerSource
private

Definition at line 212 of file BeamlineUnpack.h.

Referenced by reconfigure(), and Unpack().

bool daq2raw::BeamlineUnpack::fUnpackDigitizer
private

Definition at line 214 of file BeamlineUnpack.h.

Referenced by reconfigure(), and Unpack().

bool daq2raw::BeamlineUnpack::fUnpackTDU
private

Definition at line 216 of file BeamlineUnpack.h.

Referenced by reconfigure(), Unpack(), and UnpackTrigger().

bool daq2raw::BeamlineUnpack::fUnpackTrigger
private

Definition at line 213 of file BeamlineUnpack.h.

Referenced by reconfigure(), Unpack(), and UnpackTrigger().

bool daq2raw::BeamlineUnpack::fUnpackWireChamber
private

Definition at line 215 of file BeamlineUnpack.h.

Referenced by reconfigure(), and Unpack().


The documentation for this class was generated from the following files: