AdcSampleScaler_tool.cc
Go to the documentation of this file.
1 // AdcSampleScaler_tool.cc
2 
3 #include "AdcSampleScaler.h"
4 #include <iostream>
5 
6 using std::string;
7 using std::cout;
8 using std::endl;
9 
10 using Index = unsigned int;
11 
12 //**********************************************************************
13 // Class methods.
14 //**********************************************************************
15 
17 : m_LogLevel(ps.get<int>("LogLevel")),
18  m_ScaleFactor(ps.get<float>("ScaleFactor")),
19  m_OutputUnit(ps.get<string>("OutputUnit")),
20  m_InputUnit(ps.get<string>("InputUnit")) {
21  const string myname = "AdcSampleScaler::ctor: ";
22  if ( m_LogLevel >= 1 ) {
23  cout << myname << "Parameters:" << endl;
24  cout << myname << " LogLevel: " << m_LogLevel << endl;
25  cout << myname << " ScaleFactor: " << m_ScaleFactor << endl;
26  cout << myname << " OutputUnit: " << m_OutputUnit << endl;
27  cout << myname << " InputUnit: " << m_InputUnit << endl;
28  }
29 }
30 
31 //**********************************************************************
32 
34  const string myname = "AdcSampleScaler::update: ";
35  if ( m_LogLevel >= 2 ) cout << "Processing run " << acd.run() << " event " << acd.event()
36  << " channel " << acd.channel() << endl;
37  DataMap ret;
38 
39  // Check input data unit.
40  int unitCheck = 0;
41  if ( m_InputUnit.size() ) {
42  if ( acd.sampleUnit.size() == 0 ) {
43  cout << myname << "WARNING: Input data does not have a sample unit." << endl;
44  unitCheck = 1;
45  } else if ( acd.sampleUnit != m_InputUnit ) {
46  cout << myname << "WARNING: Unexpected input data unit: " << acd.sampleUnit
47  << " != " << m_InputUnit << endl;
48  unitCheck = 2;
49  }
50  }
51 
52  // Scale samples.
53  for ( float& sam : acd.samples ) sam *= m_ScaleFactor;
54  if ( m_OutputUnit.size() ) acd.sampleUnit = m_OutputUnit;
55 
56  ret.setInt("acsUnitCheck", unitCheck);
57  ret.setInt("acsSampleCount", acd.samples.size());
58 
59  return ret;
60 }
61 
62 //**********************************************************************
63 
AdcSampleScaler(fhicl::ParameterSet const &ps)
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
unsigned int Index
AdcIndex run() const
DataMap update(AdcChannelData &acd) const override
void setInt(Name name, int val)
Definition: DataMap.h:131
AdcIndex event() const
static constexpr double ps
Definition: Units.h:99
Channel channel() const
std::string m_OutputUnit
std::string m_InputUnit
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
AdcSignalVector samples
QTextStream & endl(QTextStream &s)