AdcRegularSignalFinder_tool.cc
Go to the documentation of this file.
1 // AdcRegularSignalFinder_tool.cc
2 
4 #include <iostream>
5 
6 using std::string;
7 using std::cout;
8 using std::endl;
9 
10 using Index = AdcIndex;
11 
12 //**********************************************************************
13 // Class methods.
14 //**********************************************************************
15 
18 : m_LogLevel(lev),
19  m_Period(per),
20  m_Length(len) {
21  const string myname = "AdcRegularSignalFinder::ctor: ";
22  if ( m_LogLevel >= 1 ) {
23  cout << myname << "Configuration parameters:" << endl;
24  cout << myname << " LogLevel: " << m_LogLevel << endl;
25  cout << myname << " Period: " << m_Period << endl;
26  cout << myname << " Length: " << m_Length << endl;
27  }
28 }
29 
30 //**********************************************************************
31 
35  ps.get<unsigned int>("Period"),
36  ps.get<unsigned int>("Length"),
37  ps.get<int>("LogLevel")
38  ) { }
39 
40 //**********************************************************************
41 
43  const string myname = "AdcRegularSignalFinder::update: ";
44  Index nsam = acd.samples.size();
45  Index nper = m_Period;
46  Index nlen = m_Length == 0 ? m_Period : m_Length;
47  if ( nper == 0 ) {
48  if ( acd.rois.size() > 0 ) {
49  AdcRoi roi = acd.rois[0];
50  AdcIndex itck1 = roi.first;
51  AdcIndex itck2 = roi.second + 1;
52  if ( itck2 > itck1 ) {
53  nper = itck2 - itck1;
54  nlen = nper;
55  if ( acd.rois.size() > 1 ) {
56  roi = acd.rois[1];
57  itck1 = roi.first;
58  itck2 = roi.second + 1;
59  if ( itck2 > itck1 ) nlen = itck2 - itck1;
60  }
61  } else {
62  cout << myname << "WARNING: Input ROI does not specify a valid period." << endl;
63  }
64  } else {
65  cout << myname << "WARNING: Input ROI to specify period is not present." << endl;
66  }
67  }
68  Index nroi = 0;
69  acd.rois.clear();
70  if ( nsam > 0 && nper > 0 ) {
71  acd.signal.resize(nsam, true);
72  Index nrem = nsam % nper;
73  nroi = nsam/nper + (nrem>0);
74  for ( Index iroi=0; iroi<nroi; ++iroi ) {
75  Index isam1 = nper*iroi;
76  Index isam2 = isam1 + nlen;
77  Index isam3 = isam1 + nper;
78  if ( isam2 > nsam ) isam2 = nsam;
79  if ( isam3 > nsam ) isam3 = nsam;
80  for ( Index isam=isam2; isam<isam3; ++isam ) {
81  acd.signal[isam] = false;
82  }
83  acd.rois.emplace_back(isam1, isam2-1);
84  }
85  } else {
86  acd.signal.resize(nsam, false);
87  }
88  DataMap res(0);
89  res.setInt("roiPeriod", nper);
90  res.setInt("roiLength", nlen);
91  res.setInt("roiCount", nroi);
92  return res;
93 }
94 
95 //**********************************************************************
96 
98  AdcChannelData acdtmp;
99  acdtmp.samples = acd.samples;
100  return update(acdtmp);
101 }
102 
103 //**********************************************************************
104 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
unsigned int Index
std::string string
Definition: nybbler.cc:12
std::pair< AdcIndex, AdcIndex > AdcRoi
Definition: AdcTypes.h:54
unsigned int Index
AdcRoiVector rois
void setInt(Name name, int val)
Definition: DataMap.h:131
static constexpr double ps
Definition: Units.h:99
AdcRegularSignalFinder(AdcIndex per, AdcIndex len, int lev)
unsigned int AdcIndex
Definition: AdcTypes.h:15
DataMap view(const AdcChannelData &acd) const override
AdcFilterVector signal
DataMap update(AdcChannelData &acd) const override
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
AdcSignalVector samples
QTextStream & endl(QTextStream &s)