Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
AdcChannelFFT Class Reference

#include <AdcChannelFFT.h>

Inheritance diagram for AdcChannelFFT:
TpcDataTool

Public Types

using Index = unsigned int
 
using FloatVector = AdcSignalVector
 
using DFT = DuneFFT::DFT
 
using Name = std::string
 

Public Member Functions

 AdcChannelFFT (fhicl::ParameterSet const &ps)
 
 ~AdcChannelFFT () override=default
 
DataMap view (const AdcChannelData &acd) const override
 
DataMap update (AdcChannelData &acd) const override
 

Private Member Functions

DataMap viewTop (const AdcChannelData &acd) const
 
DataMap updateTop (AdcChannelData &acd) const
 
void internalView (const AdcChannelData &acd, FloatVector &sams, FloatVector &amps, FloatVector &phas, DataMap &ret) const
 
- Private Member Functions inherited from TpcDataTool
virtual DataMap updateTpcData (TpcData &) const
 
virtual DataMap viewTpcData (const TpcData &) const
 
virtual int forwardTpcData () const
 
- Private Member Functions inherited from AdcChannelTool
virtual ~AdcChannelTool ()=default
 
virtual DataMap updateMap (AdcChannelDataMap &acds) const
 
virtual DataMap viewMap (const AdcChannelDataMap &acds) const
 
virtual bool updateWithView () const
 
virtual bool viewWithUpdate () const
 
virtual DataMap beginEvent (const DuneEventInfo &) const
 
virtual DataMap endEvent (const DuneEventInfo &) const
 
virtual DataMap close (const DataMap *dmin=nullptr)
 

Private Attributes

int m_LogLevel
 
Index m_FirstTick
 
Index m_NTick
 
Index m_Action
 
Index m_ReturnOpt
 
Name m_DataView
 

Additional Inherited Members

- Private Types inherited from AdcChannelTool
using Index = unsigned int
 
- Static Private Member Functions inherited from AdcChannelTool
static int interfaceNotImplemented ()
 

Detailed Description

Definition at line 74 of file AdcChannelFFT.h.

Member Typedef Documentation

Definition at line 80 of file AdcChannelFFT.h.

Definition at line 79 of file AdcChannelFFT.h.

using AdcChannelFFT::Index = unsigned int

Definition at line 78 of file AdcChannelFFT.h.

Definition at line 81 of file AdcChannelFFT.h.

Constructor & Destructor Documentation

AdcChannelFFT::AdcChannelFFT ( fhicl::ParameterSet const &  ps)

Definition at line 24 of file AdcChannelFFT_tool.cc.

25 : m_LogLevel(ps.get<int>("LogLevel")),
26  m_FirstTick(ps.get<Index>("FirstTick")),
27  m_NTick(ps.get<Index>("NTick")),
28  m_Action(ps.get<Index>("Action")),
29  m_ReturnOpt(ps.get<Index>("ReturnOpt")),
30  m_DataView(ps.get<Name>("DataView")) {
31  const string myname = "AdcChannelFFT::ctor: ";
32  if ( m_LogLevel ) {
33  cout << myname << "Configuration: " << endl;
34  cout << myname << " LogLevel: " << m_LogLevel << endl;
35  cout << myname << " FirstTick: " << m_FirstTick << endl;
36  cout << myname << " NTick: " << m_NTick << endl;
37  cout << myname << " Action: " << m_Action << endl;
38  cout << myname << " ReturnOpt: " << m_ReturnOpt << endl;
39  cout << myname << " DataView: " << m_DataView << endl;
40  }
41 }
ChannelGroupService::Name Name
unsigned int Index
static constexpr double ps
Definition: Units.h:99
QTextStream & endl(QTextStream &s)
AdcChannelFFT::~AdcChannelFFT ( )
overridedefault

Member Function Documentation

void AdcChannelFFT::internalView ( const AdcChannelData acd,
FloatVector sams,
FloatVector amps,
FloatVector phas,
DataMap ret 
) const
private

Definition at line 151 of file AdcChannelFFT_tool.cc.

151  {
152  const string myname = "AdcChannelFFT::internalView: ";
153  bool doForward = false;
154  bool doInverse = false;
155  if ( m_Action <= 4 ) {
156  if ( m_Action > 0 ) {
157  if ( m_Action == 2 || m_Action == 4 ) {
158  doForward = acd.dftmags.size() == 0;
159  } else {
160  doForward = true;
161  }
162  }
163  } else if ( m_Action >= 10 && m_Action <= 14 ) {
164  if ( m_Action != 10 ) {
165  if ( m_Action == 12 || m_Action == 14 ) {
166  doInverse = acd.samples.size() == 0;
167  } else {
168  doInverse = true;
169  }
170  }
171  } else {
172  cout << myname << "ERROR: Invalid action: " << m_Action << endl;
173  ret.setStatus(1);
174  return;
175  }
176  Index isam0 = 0;
177  Index nsam = 0;
179  DFT dft(dftNorm);
180  int passLog = m_LogLevel < 3 ? 0 : m_LogLevel - 3;
181  if ( doForward ) {
182  isam0 = m_FirstTick;
183  if ( isam0 >= acd.samples.size() ) {
184  cout << myname << "WARNING: No data in range." << endl;
185  ret.setStatus(11);
186  return;
187  }
188  nsam = acd.samples.size() - isam0;
189  if ( m_LogLevel >= 3 ) cout << myname << "Forward FFT with " << nsam << " samples." << endl;
190  if ( m_NTick > 0 && m_NTick < nsam ) nsam = m_NTick;
191  int rstat = DuneFFT::fftForward(nsam, &acd.samples[isam0], dft, passLog);
192  if ( rstat ) {
193  ret.setStatus(10+rstat);
194  cout << myname << "WARNING: Forward FFT failed." << endl;
195  return;
196  }
197  } else if ( doInverse ) {
198  dft.copyIn(acd.dftmags, acd.dftphases);
199  if ( ! dft.isValid() ) {
200  ret.setStatus(20);
201  cout << "ERROR: Unable to find DFT in AdcChannelData." << endl;
202  return;
203  }
204  int rstat = DuneFFT::fftInverse(dft, sams, passLog);
205  xams = acd.dftmags;
206  xphs = acd.dftphases;
207  if ( m_LogLevel >= 3 ) cout << myname << "Inverse FFT for " << dft.size() << " samples." << endl;
208  if ( rstat ) {
209  ret.setStatus(20+rstat);
210  cout << myname << "WARNING: Inverse FFT failed." << endl;
211  return;
212  }
213  }
214  // Fetch return data stored in the DFT.
215  Index dftRet = m_ReturnOpt % 10;
216  if ( dftRet >= 3 ) {
217  FloatVector fftres(nsam);
218  FloatVector fftims(nsam);
219  for ( Index ifrq=0; ifrq<nsam; ++ifrq ) {
220  fftres[ifrq] = dft.real(ifrq);
221  fftims[ifrq] = dft.imag(ifrq);
222  }
223  ret.setFloatVector("fftReals", fftres);
224  ret.setFloatVector("fftImags", fftims);
225  }
226  // Move data out of the DFT (leaving it invalid).
227  if ( doForward ) dft.moveOut(xams, xphs);
228  // Fetch return data not stored in the DFT.
229  if ( m_ReturnOpt >= 1 ) {
230  ret.setInt("fftTick0", isam0);
231  ret.setInt("fftNTick", nsam);
232  }
233  if ( dftRet >= 1 ) {
234  ret.setInt("fftNMag", xams.size());
235  ret.setInt("fftNPhase", xphs.size());
236  }
237  if ( dftRet >= 2 ) {
238  ret.setFloatVector("fftMags", xams);
239  ret.setFloatVector("fftPhases", xphs);
240  }
241  if ( m_ReturnOpt >= 10 ) {
242  if ( sams.size() ) ret.setFloatVector("fftSamples", sams);
243  else ret.setFloatVector("fftSamples", acd.samples);
244  }
245  return;
246 }
DataMap & setStatus(int stat)
Definition: DataMap.h:130
static AdcIndex dftNormalization()
unsigned int Index
static int fftForward(Index ntick, const float *psam, DFT &dft, Index logLevel=0)
Definition: DuneFFT.cxx:23
void setInt(Name name, int val)
Definition: DataMap.h:131
AdcSignalVector dftphases
static int fftInverse(const DFT &dft, FloatVector &sams, Index logLevel=0)
Definition: DuneFFT.cxx:79
Dft::FloatVector FloatVector
void setFloatVector(Name name, const FloatVector &val)
Definition: DataMap.h:134
AdcSignalVector samples
AdcSignalVector dftmags
QTextStream & endl(QTextStream &s)
DataMap AdcChannelFFT::update ( AdcChannelData acd) const
overridevirtual

Reimplemented from AdcChannelTool.

Definition at line 73 of file AdcChannelFFT_tool.cc.

73  {
74  const string myname = "AdcChannelFFT::update: ";
75  if ( m_DataView.size() == 0 ) return updateTop(acd);
76  DataMap retTop;
77  if ( ! acd.hasView(m_DataView) ) {
78  if ( m_LogLevel >= 2 ) {
79  cout << myname << "View " << m_DataView << " not found for event " << acd.event()
80  << " channel " << acd.channel() << endl;
81  }
82  return retTop.setStatus(1);
83  }
84  Index nproc = 0;
85  Index nfail = 0;
86  AdcIndex nent = acd.viewSize(m_DataView);
87  for ( AdcIndex ient=0; ient<nent; ++ient ) {
88  AdcChannelData* pacd = acd.mutableViewEntry(m_DataView, ient);
89  DataMap ret;
90  if ( pacd == nullptr ) {
91  cout << myname << "Channel " << acd.channel() << " view entry "
92  << m_DataView << "[" << ient << "] is null." << endl;
93  ret.setStatus(99);
94  } else {
95  ret = updateTop(*pacd);
96  }
97  ++nproc;
98  if ( ret ) ++nfail;
99  }
100  retTop.setInt("fftNproc", nproc);
101  retTop.setInt("fftNfail", nproc);
102  if ( nfail ) retTop.setStatus(2);
103  if ( m_LogLevel >= 3 ) {
104  cout << myname << "Channel " << acd.channel() << " entry counts: "
105  << nproc << " processed, " << nfail << " failed." << endl;
106  }
107  return retTop;
108 }
DataMap & setStatus(int stat)
Definition: DataMap.h:130
unsigned int Index
void setInt(Name name, int val)
Definition: DataMap.h:131
AdcIndex event() const
unsigned int AdcIndex
Definition: AdcTypes.h:15
DataMap updateTop(AdcChannelData &acd) const
Channel channel() const
AdcChannelData * mutableViewEntry(Name vpnam, AdcIndex ient)
size_t viewSize() const
bool hasView(Name vnam) const
QTextStream & endl(QTextStream &s)
DataMap AdcChannelFFT::updateTop ( AdcChannelData acd) const
private

Definition at line 124 of file AdcChannelFFT_tool.cc.

124  {
125  const string myname = "AdcChannelFFT::update: ";
126  DataMap ret;
130  internalView(acd, sams, mags, phas, ret);
131  if ( ret ) return ret;
132  if ( m_Action == 3 || m_Action == 4 ) {
133  if ( mags.size() ) {
134  if ( m_LogLevel >= 2 ) cout << myname << "Saving DFT." << endl;
135  acd.dftmags = mags;
136  acd.dftphases = phas;
137  }
138  }
139  if ( m_Action == 13 || m_Action == 14 ) {
140  if ( sams.size() ) {
141  if ( m_LogLevel >= 2 ) cout << myname << "Saving samples." << endl;
142  acd.samples = sams;
143  }
144  }
145  return ret;
146 }
std::vector< float > FloatVector
Definition: DataMap.h:54
AdcSignalVector dftphases
AdcSignalVector samples
AdcSignalVector dftmags
QTextStream & endl(QTextStream &s)
void internalView(const AdcChannelData &acd, FloatVector &sams, FloatVector &amps, FloatVector &phas, DataMap &ret) const
DataMap AdcChannelFFT::view ( const AdcChannelData acd) const
overridevirtual

Reimplemented from AdcChannelTool.

Definition at line 45 of file AdcChannelFFT_tool.cc.

45  {
46  const string myname = "AdcChannelFFT::view: ";
47  DataMap retTop;
48  if ( m_DataView.size() == 0 ) return viewTop(acd);
49  if ( ! acd.hasView(m_DataView) ) {
50  if ( m_LogLevel >= 2 ) {
51  cout << myname << "View " << m_DataView << " not found for event " << acd.event()
52  << " channel " << acd.channel() << endl;
53  }
54  return retTop.setStatus(1);
55  }
56  Index nproc = 0;
57  Index nfail = 0;
58  AdcIndex nvie = acd.viewSize(m_DataView);
59  for ( AdcIndex ivie=0; ivie<nvie; ++ivie ) {
60  const AdcChannelData* pacd = acd.viewEntry(m_DataView, ivie);
61  DataMap ret = viewTop(*pacd);
62  ++nproc;
63  if ( ret ) ++nfail;
64  }
65  retTop.setInt("fftNproc", nproc);
66  retTop.setInt("fftNfail", nproc);
67  if ( nfail ) retTop.setStatus(2);
68  return retTop;
69 }
DataMap & setStatus(int stat)
Definition: DataMap.h:130
unsigned int Index
void setInt(Name name, int val)
Definition: DataMap.h:131
AdcIndex event() const
unsigned int AdcIndex
Definition: AdcTypes.h:15
Channel channel() const
DataMap viewTop(const AdcChannelData &acd) const
const AdcChannelData * viewEntry(Name vpnam, AdcIndex ient) const
size_t viewSize() const
bool hasView(Name vnam) const
QTextStream & endl(QTextStream &s)
DataMap AdcChannelFFT::viewTop ( const AdcChannelData acd) const
private

Definition at line 112 of file AdcChannelFFT_tool.cc.

112  {
113  const string myname = "AdcChannelFFT::view: ";
114  DataMap ret;
118  internalView(acd, sams, mags, phas, ret);
119  return ret;
120 }
std::vector< float > FloatVector
Definition: DataMap.h:54
void internalView(const AdcChannelData &acd, FloatVector &sams, FloatVector &amps, FloatVector &phas, DataMap &ret) const

Member Data Documentation

Index AdcChannelFFT::m_Action
private

Definition at line 109 of file AdcChannelFFT.h.

Name AdcChannelFFT::m_DataView
private

Definition at line 111 of file AdcChannelFFT.h.

Index AdcChannelFFT::m_FirstTick
private

Definition at line 107 of file AdcChannelFFT.h.

int AdcChannelFFT::m_LogLevel
private

Definition at line 106 of file AdcChannelFFT.h.

Index AdcChannelFFT::m_NTick
private

Definition at line 108 of file AdcChannelFFT.h.

Index AdcChannelFFT::m_ReturnOpt
private

Definition at line 110 of file AdcChannelFFT.h.


The documentation for this class was generated from the following files: