RdChannelUpsampler.cc
Go to the documentation of this file.
1 #include "RdChannelUpsampler.h"
2 
3 #include <fwk/CentralConfig.h>
4 
5 #include <utl/ErrorLogger.h>
6 #include <utl/Reader.h>
7 #include <utl/config.h>
8 #include <utl/TraceAlgorithm.h>
9 #include <utl/FFTDataContainerAlgorithm.h>
10 
11 #include <evt/Event.h>
12 #include <revt/REvent.h>
13 #include <revt/Station.h>
14 #include <revt/Channel.h>
15 
16 
17 using namespace fwk;
18 using namespace utl;
19 using namespace std;
20 using namespace revt;
21 
22 
23 namespace RdChannelUpsampler {
24 
25 
28  {
29  // Read in the configurations of the xml file
30  Branch topBranch =
31  CentralConfig::GetInstance()->GetTopBranch("RdChannelUpsampler");
32  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
33  topBranch.GetChild("RemoveOffset").GetData(fRemoveOffset);
34  topBranch.GetChild("UseTargetFrequency").GetData(fUseTargetFrequency);
35  topBranch.GetChild("UpsamplingFactor").GetData(fUpsamplingFactor);
36  topBranch.GetChild("TargetFrequency").GetData(fTargetFrequency);
37 
38  ostringstream info;
39  info << "RdChannelUpsampler set up with UpsamplingFactor of "
40  << fUpsamplingFactor << " and RemoveOffset " << fRemoveOffset << ".";
41  INFOIntermediate(info);
42 
43  return eSuccess;
44  }
45 
46 
48  RdChannelUpsampler::Run(evt::Event& event)
49  {
50  // Check if upsampling shall be done at all
51  if (fUpsamplingFactor < 2) {
52  WARNING("No upsampling will be done as UpsamplingFactor < 2!");
53  return eContinueLoop;
54  }
55 
56  // Check if there are events at all
57  if (!event.HasREvent()) {
58  WARNING("No radio event found!");
59  return eContinueLoop;
60  }
61 
62  REvent& rEvent = event.GetREvent();
63  ostringstream info;
64 
65  // loop through stations and for every station through every channel
66  for (auto& station : rEvent.StationsRange()) {
67  for (auto& channel : station.ChannelsRange()) {
68 
69  if (!channel.IsActive())
70  continue;
71 
72  unsigned int upsamplingFactor = 0;
73  if (!fUseTargetFrequency)
74  upsamplingFactor = fUpsamplingFactor;
75  else {
76  const double frequency = 1. / channel.GetChannelTimeSeries().GetBinning();
77  const double ratio = fTargetFrequency / frequency;
78  constexpr double eps = 1e-6;
79  const unsigned int intratio = int(ratio + eps);
80 
81  if (ratio <= 0 || abs(ratio - intratio) > eps) {
82  ERROR ("Wrong target frequency!");
83  return eFailure;
84  }
85  upsamplingFactor = intratio;
86  }
87 
88  FFTDataContainerAlgorithm::UpsampleTimeSeries(channel.GetFFTDataContainer(),
89  upsamplingFactor, fRemoveOffset);
90 
91  info << "Upsampling of channel " << channel.GetId()
92  << " of station " << channel.GetStationId()
93  << " by a factor of " << upsamplingFactor << ".";
94  INFOIntermediate(info);
95  }
96  }
97 
98  return eSuccess;
99  }
100 
101 
103  RdChannelUpsampler::Finish()
104  {
105  return eSuccess;
106  }
107 
108 }
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
bool HasREvent() const
#define INFOIntermediate(y)
Definition: VModule.h:162
Class representing a document branch.
Definition: Branch.h:107
double abs(const SVector< n, T > &v)
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
double eps
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.