AdcChannelSplitter_tool.cc
Go to the documentation of this file.
1 // AdcChannelSplitter_tool.cc
2 
3 #include "AdcChannelSplitter.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_DataPath(ps.get<Name>("DataPath")),
19  m_DataView(ps.get<Name>("DataView")) {
20  const string myname = "AdcChannelSplitter::ctor: ";
21  // Display the configuration.
22  if ( m_LogLevel >= 1 ) {
23  cout << myname << "Configuration: " << endl;
24  cout << myname << " LogLevel: " << m_LogLevel << endl;
25  cout << myname << " Length: " << m_Length << endl;
26  cout << myname << " DataPath: " << m_DataPath << endl;
27  cout << myname << " DataView: " << m_DataView << endl;
28  }
29 }
30 
31 //**********************************************************************
32 
34  const string myname = "AdcChannelSplitter::update: ";
35  DataMap ret;
36  Index dtck = m_Length;
37  if ( dtck == 0 ) {
38  cout << "ERROR: Length is zero." << endl;
39  return ret.setStatus(1);
40  }
41  Index nvie = acd.viewSize(m_DataPath);
42  Index nobj = 0;
43  if ( m_LogLevel >= 2 ) cout << myname << "Channel " << acd.channel()
44  << " input object count: " << nvie << endl;
45  Index nrawCopied = 0;
46  Index nsamCopied = 0;
47  // Loop over input objects.
48  for ( Index ivie=0; ivie<nvie; ++ivie ) {
49  AdcChannelData* pacd = acd.mutableViewEntry(m_DataPath, ivie);
50  Index nraw = pacd->raw.size();
51  Index nsam = pacd->samples.size();
52  // Create the new view. It might be left empty.
54  Index itck = 0; // Start copy at this tick
55  while ( true ) {
56  Index jtck = itck + dtck; // End copy at this tick
57  bool copyRaw = nraw >= jtck;
58  bool copySam = nsam >= jtck;
59  if ( !copyRaw && !copySam ) break;
60  acds.push_back(*pacd);
61  AdcChannelData& acdNew = acds.back();
62  acdNew.viewParent = pacd;
63  acdNew.tick0 = pacd->tick0 + itck;
64  if ( copyRaw ) {
65  for ( Index iraw=itck; iraw<jtck; ++iraw ) {
66  acdNew.raw.push_back(pacd->raw[iraw]);
67  ++nrawCopied;
68  }
69  }
70  if ( copySam ) {
71  for ( Index isam=itck; isam<jtck; ++isam ) {
72  acdNew.samples.push_back(pacd->samples[isam]);
73  ++nsamCopied;
74  }
75  }
76  if ( acdNew.samples.size() ) acdNew.sampleUnit = pacd->sampleUnit;
77  ++nobj;
78  itck = jtck;
79  }
80  }
81  if ( m_LogLevel >= 2 ) cout << myname << "Channel " << acd.channel()
82  << " output object count: " << nobj << endl;
83  ret.setInt("splitInputCount", nvie);
84  ret.setInt("splitOutputCount", nobj);
85  ret.setInt("splitRawCopyCount", nrawCopied);
86  ret.setInt("splitSampleCopyCount", nsamCopied);
87  return ret;
88 }
89 
90 //**********************************************************************
91 
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
std::string string
Definition: nybbler.cc:12
AdcChannelSplitter(fhicl::ParameterSet const &ps)
AdcChannelData * viewParent
void setInt(Name name, int val)
Definition: DataMap.h:131
DataMap update(AdcChannelData &acd) const override
static constexpr double ps
Definition: Units.h:99
AdcCountVector raw
Channel channel() const
AdcChannelData * mutableViewEntry(Name vpnam, AdcIndex ient)
View & updateView(Name vnam)
size_t viewSize() const
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
AdcSignalVector samples
QTextStream & endl(QTextStream &s)