Public Types | Public Member Functions | Private Attributes | List of all members
TimingRawDecoderOffsetTool Class Reference

#include <TimingRawDecoderOffsetTool.h>

Inheritance diagram for TimingRawDecoderOffsetTool:
TimeOffsetTool

Public Types

using Name = std::string
 
using IndexVector = std::vector< Index >
 
using DoubleVector = std::vector< double >
 
using ScaleMap = std::map< Index, double >
 
- Public Types inherited from TimeOffsetTool
using Index = unsigned int
 
using LongIndex = unsigned long
 
using Name = std::string
 

Public Member Functions

 TimingRawDecoderOffsetTool (fhicl::ParameterSet const &ps)
 
 ~TimingRawDecoderOffsetTool () override=default
 
Offset offset (const Data &dat) const override
 
- Public Member Functions inherited from TimeOffsetTool
virtual ~TimeOffsetTool ()=default
 

Private Attributes

Index m_LogLevel
 
Index m_TpcTickPhase
 
Name m_Unit
 
IndexVector m_FembScaleIds
 
DoubleVector m_FembScaleValues
 
Name m_RunDataTool
 
const RunDataToolm_pRunDataTool =nullptr
 
ScaleMap m_fembScales
 

Detailed Description

Definition at line 47 of file TimingRawDecoderOffsetTool.h.

Member Typedef Documentation

Definition at line 53 of file TimingRawDecoderOffsetTool.h.

Definition at line 52 of file TimingRawDecoderOffsetTool.h.

Definition at line 51 of file TimingRawDecoderOffsetTool.h.

using TimingRawDecoderOffsetTool::ScaleMap = std::map<Index, double>

Definition at line 54 of file TimingRawDecoderOffsetTool.h.

Constructor & Destructor Documentation

TimingRawDecoderOffsetTool::TimingRawDecoderOffsetTool ( fhicl::ParameterSet const &  ps)

Definition at line 20 of file TimingRawDecoderOffsetTool_tool.cc.

21 : m_LogLevel(ps.get<Index>("LogLevel")),
22  m_TpcTickPhase(ps.get<Index>("TpcTickPhase")),
23  m_Unit(ps.get<Name>("Unit")),
24  m_FembScaleIds(ps.get<IndexVector>("FembScaleIds")),
25  m_FembScaleValues(ps.get<DoubleVector>("FembScaleValues")),
26  m_RunDataTool(ps.get<Name>("RunDataTool")) {
27  const Name myname = "TimingRawDecoderOffsetTool::ctor: ";
28  if ( m_RunDataTool.size() ) {
31  if ( m_pRunDataTool == nullptr ) {
32  cout << myname << "WARNING: RunDataTool not found: " << m_RunDataTool << endl;
33  }
34  }
35  Index nfmb = std::min(m_FembScaleIds.size(), m_FembScaleValues.size());
36  for ( Index kfmb=0; kfmb<nfmb; ++kfmb ) {
38  }
39  // If needed, pad FEMB scale values.
40  if ( m_FembScaleValues.size() < m_FembScaleIds.size() ) {
41  cout << myname << "WARNING: Missing scale values have been set to one." << endl;
42  }
43  if ( m_FembScaleValues.size() > m_FembScaleIds.size() ) {
44  cout << myname << "WARNING: Extra scale values will be ignored." << endl;
45  }
46  if ( m_LogLevel ) {
47  cout << myname << "Configuration:" << endl;
48  cout << myname << " LogLevel: " << m_LogLevel << endl;
49  cout << myname << " TpcTickPhase: " << m_TpcTickPhase << endl;
50  cout << myname << " Unit: " << m_Unit << endl;
51  cout << myname << " FembScales: [";
52  Index nfmb = 0;
53  for ( ScaleMap::value_type isca : m_fembScales ) {
54  if ( nfmb ) cout << ", ";
55  cout << isca.first << ":" << isca.second;
56  ++nfmb;
57  }
58  cout << "]" << endl;
59  cout << myname << " RunDataTool: " << m_RunDataTool << " @ " << m_pRunDataTool << endl;
60  }
61 }
std::vector< Index > IndexVector
ChannelGroupService::Name Name
unsigned int Index
std::vector< double > DoubleVector
Definition: fcldump.cxx:27
static constexpr double ps
Definition: Units.h:99
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
static DuneToolManager * instance(std::string fclname="", int dbg=1)
T * getShared(std::string name)
QTextStream & endl(QTextStream &s)
TimingRawDecoderOffsetTool::~TimingRawDecoderOffsetTool ( )
overridedefault

Member Function Documentation

Offset TimingRawDecoderOffsetTool::offset ( const Data dat) const
overridevirtual

Implements TimeOffsetTool.

Definition at line 65 of file TimingRawDecoderOffsetTool_tool.cc.

65  {
66  const Name myname = "TimingRawDecoderOffsetTool::offset: ";
67  Name ifname = "artdaqTimestamp-Run" + std::to_string(dat.run) +
68  "-Event" + std::to_string(dat.event) + ".dat";
69  Offset res;
70  unsigned long daqVal = dat.triggerClock;
71  static Index checkCount = 0;
72  ScaleMap::const_iterator isca = m_fembScales.find(dat.fembID);
73  bool haveScale = isca != m_fembScales.end();
74  double scale = haveScale ? isca->second : 1.0;
75  if ( checkCount ) {
76  ifstream fin(ifname.c_str());
77  if ( ! fin ) {
78  cout << myname << "Unable to find time offset file: " << ifname << endl;
79  //return res.setStatus(1);
80  }
81  unsigned long daqValFile = 0;
82  fin >> daqValFile;
83  if ( daqVal == daqValFile ) {
84  cout << myname << "Input clock matches file clock." << endl;
85  } else {
86  cout << myname << "Input clock does not match file: " << daqVal << " != " << daqValFile << endl;
87  }
88  --checkCount;
89  }
90  if ( m_Unit == "daq" ) {
91  res.value = scale*daqVal;
92  res.rem = 0.0;
93  } else if ( m_Unit == "ns" ) {
94  res.value = scale*20*daqVal;
95  res.rem = 0.0;
96  } else if ( m_Unit == "tick" ) {
97  Index runPhase = 0;
98  if ( m_pRunDataTool != nullptr ) {
99  Index icha = dat.channel;
100  RunData rdat = m_pRunDataTool->runData(dat.run, dat.subrun);
101  if ( rdat.havePhaseGroup() ) {
102  bool haveGroup = true;
103  Index igrp = 0;
105  bool useWib = false;
106  bool useFemb = false;
107  if ( rdat.phaseGroup() == "channel" ) igrp = icha;
108  else if ( rdat.phaseGroup() == "all" ) igrp = 0;
109  else if ( rdat.phaseGroup() == "wib" ) useWib = true;
110  else if ( rdat.phaseGroup() == "femb" ) useFemb = true;
111  else {
112  haveGroup = false;
113  cout << myname << "WARNING: Invalid phase group: " << rdat.phaseGroup() << endl;
114  }
115  if ( haveGroup ) {
117  if ( pchanMap.get() != nullptr ) {
118  Index kapa = pchanMap->APAFromOfflineChannel(icha);
119  Index jwib = pchanMap->WIBFromOfflineChannel(icha);
120  Index jcon = pchanMap->FEMBFromOfflineChannel(icha);
121  Index jfmb = 5*jcon + jwib;
122  Index kfmb = 20*kapa + jfmb;
123  Index kwib = 5*kapa + jfmb%5;
124  if ( useWib ) igrp = kwib;
125  if ( useFemb ) igrp = kfmb;
126  } else {
127  haveGroup = false;
128  cout << myname << "WARNING: Channel map service not found." << endl;
129  }
130  }
131  if ( haveGroup ) {
132  const RunData::IndexVector& phases = rdat.phases();
133  if ( igrp + 1 > phases.size() ) {
134  cout << myname << "WARNING: Phases is too short: " << igrp << "/" << phases.size() << endl;
135  } else {
136  runPhase = phases[igrp];
137  }
138  }
139  }
140  if ( m_LogLevel >= 3 ) cout << myname << "Run phase is " << runPhase << endl;
141  } else {
142  if ( m_LogLevel >= 3 ) cout << myname << "Run data tool not found." << endl;
143  }
144  long daqoff = daqVal + m_TpcTickPhase + runPhase;
145  if ( haveScale ) {
146  res.value = scale*daqoff/25;
147  } else {
148  res.value = daqoff/25;
149  }
150  res.rem = (daqoff % 25)/25.0;
151  } else {
152  cout << myname << "Invalid unit: " << m_Unit << ifname << endl;
153  return res.setStatus(2);
154  }
155  res.unit = m_Unit;
156  if ( m_LogLevel >= 2 ) cout << myname << "Offset is " << res.value
157  << " " << res.unit << endl;
158  return res;
159 }
const IndexVector & phases() const
Definition: RunData.h:45
T * get() const
Definition: ServiceHandle.h:63
Name phaseGroup() const
Definition: RunData.h:44
const Offset & setStatus(int val)
ChannelGroupService::Name Name
intermediate_table::const_iterator const_iterator
unsigned int Index
unsigned int APAFromOfflineChannel(unsigned int offlineChannel) const
Returns APA/crate.
bool havePhaseGroup() const
Definition: RunData.h:60
void checkCount(const ToolPtr &ptool, double vin, Count countExpected)
std::vector< Index > IndexVector
Definition: RunData.h:27
virtual RunData runData(Index run, Index subRun=0) const =0
unsigned int WIBFromOfflineChannel(unsigned int offlineChannel) const
Returns WIB/slot.
unsigned int FEMBFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB/fiber.
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
QTextStream & endl(QTextStream &s)

Member Data Documentation

IndexVector TimingRawDecoderOffsetTool::m_FembScaleIds
private

Definition at line 71 of file TimingRawDecoderOffsetTool.h.

ScaleMap TimingRawDecoderOffsetTool::m_fembScales
private

Definition at line 78 of file TimingRawDecoderOffsetTool.h.

DoubleVector TimingRawDecoderOffsetTool::m_FembScaleValues
private

Definition at line 72 of file TimingRawDecoderOffsetTool.h.

Index TimingRawDecoderOffsetTool::m_LogLevel
private

Definition at line 68 of file TimingRawDecoderOffsetTool.h.

const RunDataTool* TimingRawDecoderOffsetTool::m_pRunDataTool =nullptr
private

Definition at line 75 of file TimingRawDecoderOffsetTool.h.

Name TimingRawDecoderOffsetTool::m_RunDataTool
private

Definition at line 73 of file TimingRawDecoderOffsetTool.h.

Index TimingRawDecoderOffsetTool::m_TpcTickPhase
private

Definition at line 69 of file TimingRawDecoderOffsetTool.h.

Name TimingRawDecoderOffsetTool::m_Unit
private

Definition at line 70 of file TimingRawDecoderOffsetTool.h.


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