AdcChannelTrimmer_tool.cc
Go to the documentation of this file.
1 // AdcChannelTrimmer_tool.cc
2 
3 #include "AdcChannelTrimmer.h"
4 #include <iostream>
5 #include <vector>
6 
7 using std::string;
8 using std::cout;
9 using std::endl;
10 
11 //**********************************************************************
12 // Class methods.
13 //**********************************************************************
14 
16 : m_LogLevel(ps.get<int>("LogLevel")),
17  m_Length(ps.get<Index>("Length")),
18  m_MaxTrim(ps.get<Index>("MaxTrim")) {
19  const string myname = "AdcChannelTrimmer::ctor: ";
20  // Display the configuration.
21  if ( m_LogLevel >= 1 ) {
22  cout << myname << "Configuration: " << endl;
23  cout << myname << " LogLevel: " << m_LogLevel << endl;
24  cout << myname << " Length: " << m_Length << endl;
25  cout << myname << " MaxTrim: " << m_MaxTrim << endl;
26  }
27 }
28 
29 //**********************************************************************
30 
32  const string myname = "AdcChannelTrimmer::view: ";
33  DataMap ret;
34  Index nsam = acd.samples.size();
35  if ( nsam == m_Length ) {
36  ret.setInt("trimAction", 0);
37  if ( m_LogLevel >= 3 ) cout << "Samples have requested length of "
38  << m_Length << "." << endl;
39  return ret;
40  }
41  if ( nsam == 0 ) {
42  ret.setInt("trimAction", 3);
43  if ( m_LogLevel >= 3 ) cout << "WARNING: No samples found." << endl;
44  return ret;
45  }
46  int idsam = nsam < m_Length ? -int(m_Length - nsam) : int(nsam - m_Length);
47  Index udsam = idsam < 0 ? -idsam : idsam;
48  ret.setInt("trimLength", idsam);
49  if ( m_MaxTrim && udsam > m_MaxTrim ) {
50  ret.setInt("trimAction", 2);
51  cout << myname << "ERROR: Channel " << acd.channel() << " sample length " << nsam
52  << " is outside of trim range " << m_MaxTrim << "." << endl;
53  } else {
54  ret.setInt("trimAction", -1);
55  if ( m_LogLevel >= 2 ) cout << myname << "Trimming channel " << acd.channel() << " from "
56  << nsam << " to " << m_Length << " samples." << endl;
57  }
58  return ret;
59 }
60 
61 //**********************************************************************
62 
64  const string myname = "AdcChannelTrimmer::update: ";
65  DataMap ret = view(acd);
66  int action = ret.getInt("trimAction");
67  if ( action != -1 ) return ret;
68  Index nsam = acd.samples.size();
69  acd.samples.resize(m_Length);
70  Index jsam = 0;
71  for ( Index isam=nsam; isam<m_Length; ++isam ) {
72  acd.samples[isam] = acd.samples[jsam++];
73  }
74  ret.setInt("trimAction", 1);
75  return ret;
76 }
77 
78 //**********************************************************************
79 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
unsigned int Index
std::string string
Definition: nybbler.cc:12
void setInt(Name name, int val)
Definition: DataMap.h:131
static constexpr double ps
Definition: Units.h:99
DataMap update(AdcChannelData &acd) const override
Channel channel() const
int getInt(Name name, int def=0) const
Definition: DataMap.h:218
AdcChannelTrimmer(fhicl::ParameterSet const &ps)
DataMap view(const AdcChannelData &acd) const override
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
AdcSignalVector samples
QTextStream & endl(QTextStream &s)