AdcUnderflowFlagger_tool.cc
Go to the documentation of this file.
1 // AdcUnderflowFlagger_tool.cc
2 
3 #include "AdcUnderflowFlagger.h"
4 #include <iostream>
5 #include <fstream>
6 #include <sstream>
7 #include <iomanip>
8 
9 using std::string;
10 using std::cout;
11 using std::endl;
12 using std::ofstream;
13 using std::ostream;
14 using std::ostringstream;
15 using std::setw;
16 using std::fixed;
17 using std::setprecision;
18 using std::vector;
19 
20 using Index = unsigned int;
21 
22 //**********************************************************************
23 // Class methods.
24 //**********************************************************************
25 
27 : m_LogLevel(ps.get<int>("LogLevel")),
28  m_AdcThresholds(ps.get<AdcCountVector>("AdcThresholds")),
29  m_DefaultThreshold(ps.get<int>("DefaultThreshold")),
30  m_modifyCount(0) {
31  const string myname = "AdcUnderflowFlagger::ctor: ";
32  if ( m_LogLevel >= 1 ) {
33  cout << myname << "Configuration parameters:" << endl;
34  cout << myname << " LogLevel: " << m_LogLevel << endl;
35  cout << myname << " AdcThresholds: [";
36  Index maxcha = 10;
37  Index ncha = m_AdcThresholds.size();
38  bool haveMore = ncha > maxcha;
39  if ( ! haveMore ) maxcha = ncha;
40  for ( Index icha=0; icha<maxcha; ++icha ) {
41  if ( icha ) cout << ",";
42  cout << " " << m_AdcThresholds[icha];
43  }
44  if ( haveMore ) cout << ",...";
45  cout << "]" << endl;
46  }
47 }
48 
49 //**********************************************************************
50 
52  const string myname = "AdcUnderflowFlagger::view: ";
53  AdcChannelData acdtmp;
54  acdtmp.setChannelInfo(acd.channel());
55  acdtmp.raw = acd.raw;
56  return update(acdtmp);
57 }
58 
59 //**********************************************************************
60 
62  const string myname = "AdcUnderflowFlagger::update: ";
63  if ( m_LogLevel >= 3 ) cout << myname << "Calling " << endl;
64  DataMap res(0);
65  AdcChannel icha = acd.channel();
66  res.setInt("channel", icha);
67  res.setInt("nModify", m_modifyCount);
68  if ( icha == AdcChannelData::badChannel() ) {
69  if ( m_LogLevel >= 2 ) cout << myname << "Data does not have an assigned channel." << endl;
70  return res.setStatus(1);
71  }
72  IntVector::value_type sthr = -1;
73  Index ncha = m_AdcThresholds.size();
74  if ( icha < ncha ) sthr = m_AdcThresholds[icha];
75  else sthr = m_DefaultThreshold;
76  if ( sthr < 0 ) {
77  if ( m_LogLevel >= 2 ) cout << myname << "No threshold set for channel " << icha << endl;
78  return res.setStatus(2 + icha >= ncha);
79  }
80  AdcCount thr = sthr;
81  Index nraw = acd.raw.size();
82  Index nflg = acd.flags.size();
83  if ( nflg < nraw ) acd.flags.resize(nraw, AdcGood);
84  Index nunder = 0;
85  for ( Index isam=0; isam<nraw; ++isam ) {
86  if ( acd.raw[isam] <= thr ) {
87  ++nunder;
88  acd.flags[isam] = AdcUnderflow;
89  }
90  }
91  res.setInt("nUnderflow", nunder);
92  return res;
93 }
94 
95 //**********************************************************************
96 
DataMap view(const AdcChannelData &acd) const override
AdcUnderflowFlagger(fhicl::ParameterSet const &ps)
std::vector< AdcCount > AdcCountVector
Definition: AdcTypes.h:19
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
G4double thr[100]
Definition: G4S2Light.cc:59
unsigned int Index
DataMap & setStatus(int stat)
Definition: DataMap.h:130
std::string string
Definition: nybbler.cc:12
struct vector vector
DataMap update(AdcChannelData &acd) const override
const AdcFlag AdcUnderflow
Definition: AdcTypes.h:33
unsigned int Index
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
const AdcFlag AdcGood
Definition: AdcTypes.h:32
void setChannelInfo(ChannelInfoPtr pchi)
void setInt(Name name, int val)
Definition: DataMap.h:131
static constexpr double ps
Definition: Units.h:99
AdcCountVector raw
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Channel channel() const
unsigned int AdcChannel
Definition: AdcTypes.h:50
static Index badChannel()
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
short AdcCount
Definition: AdcTypes.h:18
QTextStream & endl(QTextStream &s)
AdcFlagVector flags