AcdDigitReader_tool.cc
Go to the documentation of this file.
1 // AcdDigitReader_tool.cc
2 
3 #include "AcdDigitReader.h"
4 #include <iostream>
5 #include <iomanip>
7 #include "lardataobj/RawData/raw.h" // compression fns are here
8 
9 using std::string;
10 using std::cout;
11 using std::endl;
12 using std::setw;
13 using Index = unsigned int;
14 using raw::RawDigit;
15 
16 //**********************************************************************
17 
19 : m_LogLevel(ps.get<int>("LogLevel")) {
20  const string myname = "AcdDigitReader::ctor: ";
21  if ( m_LogLevel > 0 ) {
22  cout << myname << " LogLevel: " << m_LogLevel << endl;
23  }
24 }
25 
26 //**********************************************************************
27 
29  const string myname = "AcdDigitReader::update: ";
30  // Take the digit from the channel data.
31  const RawDigit* pdig = acd.digit;
32  if ( pdig == nullptr ) {
33  cout << myname << "ERROR: Digit is null." << endl;
34  return DataMap(1);
35  }
36  const RawDigit& dig = *pdig;
37  // Check the input data is empty.
38  if ( acd.raw.size() ) {
39  cout << myname << "ERROR: ADC channel has raw data." << endl;
40  return DataMap(2);
41  }
42  if ( acd.flags.size() ) {
43  cout << myname << "ERROR: ADC channel has flag data." << endl;
44  return DataMap(3);
45  }
46  if ( acd.pedestal != AdcChannelData::badSignal() ) {
47  cout << myname << "ERROR: ADC channel has a pedestal." << endl;
48  return DataMap(4);
49  }
50  // Set or check the channel number.
51  if ( acd.channel() == AdcChannelData::badChannel() ) {
52  acd.setChannelInfo(dig.Channel());
53  } else {
54  if ( acd.channel() != dig.Channel() ) {
55  cout << myname << "ERROR: Raw digit has inconsistent channel number." << endl;
56  return DataMap(5);
57  }
58  }
59  // Copy pedestal.
60  acd.pedestal = dig.GetPedestal();
61  acd.metadata["inputPedestal"] = dig.GetPedestal();
62  // Copy raw data.
63  if ( dig.Compression() == raw::kNone ) {
64  acd.raw = dig.ADCs();
65  } else {
66  unsigned int nsig = dig.Samples();
67  acd.raw.resize(nsig, -999); // See https://cdcvs.fnal.gov/redmine/issues/11572.
68  if ( nsig < dig.ADCs().size() ) {
69  cout << myname << "WARNING: " << "Uncompressed size is smaller than compressed: "
70  << nsig << " < " << dig.ADCs().size() << endl;
71  }
72  raw::Uncompress(dig.ADCs(), acd.raw, dig.GetPedestal(), dig.Compression());
73  }
74  // Initialize flags to good.
75  acd.flags.resize(acd.raw.size(), AdcGood);
76  if ( m_LogLevel >= 4 ) {
77  cout << myname << setw(8) << acd.channel() << ": [";
78  Index mdig = acd.raw.size();
79  bool toomany = mdig > 10 ;
80  if ( toomany ) mdig = 10;
81  for ( Index idig=0; idig<mdig; ++idig ) cout << setw(5) << acd.raw[idig];
82  if ( toomany ) cout << " ...";
83  cout << "]" << endl;
84  } else if ( m_LogLevel >= 3 ) {
85  cout << myname << "Channel " << acd.channel() << " raw count: " << acd.raw.size() << endl;
86  }
87  return DataMap(0);
88 }
89 
90 //**********************************************************************
91 
float GetPedestal() const
Definition: RawDigit.h:214
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:210
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
unsigned int Index
std::string string
Definition: nybbler.cc:12
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
AcdDigitReader(fhicl::ParameterSet const &ps)
unsigned int Index
const raw::RawDigit * digit
no compression
Definition: RawTypes.h:9
const AdcFlag AdcGood
Definition: AdcTypes.h:32
static Index badSignal()
void setChannelInfo(ChannelInfoPtr pchi)
DataMap update(AdcChannelData &acd) const override
static constexpr double ps
Definition: Units.h:99
AdcCountVector raw
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:216
Channel channel() const
AdcSignal pedestal
static Index badChannel()
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
QTextStream & endl(QTextStream &s)
AdcFlagVector flags