AdcRoiSlicer_tool.cc
Go to the documentation of this file.
1 // AdcRoiSlicer_tool.cc
2 
3 #include "AdcRoiSlicer.h"
4 #include <iostream>
5 
7 using Index = unsigned int;
8 using std::cout;
9 using std::endl;
10 
11 //**********************************************************************
12 // Class methods.
13 //**********************************************************************
14 
16 : m_LogLevel(ps.get<int>("LogLevel")),
17  m_OutViewName(ps.get<Name>("OutViewName")),
18  m_SliceOpt(ps.get<int>("SliceOpt")),
19  m_CopyRaw(ps.get<bool>("CopyRaw")) {
20  const Name myname = "AdcRoiSlicer::ctor: ";
21  if ( m_LogLevel >= 1 ) {
22  cout << myname << "Configuration parameters:" << endl;
23  cout << myname << " LogLevel: " << m_LogLevel << endl;
24  cout << myname << " OutViewName: " << m_OutViewName << endl;
25  cout << myname << " SliceOpt: " << m_SliceOpt << endl;
26  cout << myname << " CopyRaw: " << (m_CopyRaw ? "true" : "false") << endl;
27  }
28 }
29 
30 //**********************************************************************
31 
33  const Name myname = "AdcRoiSlicer::update: ";
34  DataMap ret;
35  bool keepRoi = m_SliceOpt == 1 || m_SliceOpt == 3;
36  bool keepNot = m_SliceOpt == 2 || m_SliceOpt == 3;
37  bool copyRaw = m_CopyRaw;
38  if ( ! keepRoi && ! keepNot ) {
39  cout << "ERROR: Invalid slice option: " << m_SliceOpt << endl;
40  return ret.setStatus(1);
41  }
42  Index nsam = acd.samples.size();
43  if ( acd.signal.size() != nsam ) {
44  cout << "ERROR: Signal size does not match samples: " << acd.signal.size()
45  << " != " << nsam << endl;
46  return ret.setStatus(2);
47  }
48  if ( acd.hasView(m_OutViewName) ) {
49  cout << "ERROR: Data for channel " << acd.channel() << " already has view " << m_OutViewName << endl;
50  return ret.setStatus(3);
51  }
52  if ( copyRaw && acd.raw.size() < nsam ) {
53  cout << "ERROR: Insufficient raw data for channel " << acd.channel() << ": "
54  << acd.raw.size() << " < " << nsam << "." << endl;
55  copyRaw = false;
56  }
58  Index nsamKeep = 0;
59  Index nsamSkip = 0;
60  if ( m_LogLevel >= 3 ) {
61  cout << myname << "Looping over " << nsam << " samples for channel "
62  << acd.channel() << endl;
63  }
64  for ( Index isam=0; isam<nsam; ++isam ) {
65  bool isRoi = acd.signal[isam];
66  bool keep = (isRoi && keepRoi) || (!isRoi && keepNot);
67  bool changeRoi = isam==0 || acd.signal[isam] != acd.signal[isam-1];
68  bool startData = keep && changeRoi;
69  if ( startData ) {
70  if ( m_LogLevel >= 3 ) cout << myname << "Creating data view at tick " << isam << endl;
71  view.push_back(acd);
72  AdcChannelData& acdout = view.back();
73  acdout.viewParent = &acd;
74  acdout.tick0 = isam;
75  }
76  if ( keep ) {
77  AdcChannelData& acdout = view.back();
78  if ( copyRaw ) acdout.raw.push_back(acd.raw[isam]);
79  acdout.samples.push_back(acd.samples[isam]);
80  acdout.signal.push_back(acd.signal[isam]);
81  ++nsamKeep;
82  } else {
83  ++nsamSkip;
84  }
85  }
86  if ( m_LogLevel >= 2 ) {
87  cout << myname << "End of update. Nview=" << view.size()
88  << ". # sample keep/skip/tot: " << nsamKeep << "/" << nsamSkip
89  << "/" << nsam << endl;
90  }
91  ret.setInt("nRoiView", view.size());
92  return ret;
93 }
94 
95 //**********************************************************************
96 
std::vector< AdcChannelData > View
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
unsigned int Index
DataMap & setStatus(int stat)
Definition: DataMap.h:130
ChannelGroupService::Name Name
unsigned int Index
DataMap update(AdcChannelData &acd) const override
virtual DataMap view(const AdcChannelData &acd) const
Name m_OutViewName
Definition: AdcRoiSlicer.h:36
AdcChannelData * viewParent
void setInt(Name name, int val)
Definition: DataMap.h:131
static constexpr double ps
Definition: Units.h:99
AdcCountVector raw
Channel channel() const
AdcRoiSlicer(fhicl::ParameterSet const &ps)
AdcFilterVector signal
View & updateView(Name vnam)
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
bool hasView(Name vnam) const
std::string Name
Definition: AdcRoiSlicer.h:26
int bool
Definition: qglobal.h:345
AdcSignalVector samples
QTextStream & endl(QTextStream &s)