RdChannelTimeSeriesClipper.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 #include <fwk/RunController.h>
5 
6 #include <utl/config.h>
7 #include <utl/ErrorLogger.h>
8 #include <utl/Reader.h>
9 
10 #include <evt/Event.h>
11 #include <revt/REvent.h>
12 #include <revt/Channel.h>
13 #include <revt/Station.h>
14 #include <revt/StationRecData.h>
15 
16 
17 using namespace fwk;
18 using namespace utl;
19 using namespace std;
20 using namespace revt;
21 
22 
24 
27  {
28  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdChannelTimeSeriesClipper");
29  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
30  topBranch.GetChild("NumberOfSamplesToKeep").GetData(fNumberOfSamplesToKeep);
31  topBranch.GetChild("NumberOfSamplesToRemove").GetData(fNumberOfSamplesToRemove);
32  topBranch.GetChild("ClippingMethod").GetData(fMethodTypeString);
33 
34  //setting the clipping method
35  if (fMethodTypeString == "RemoveSamplesFromFront") {
36  fMethod = eRemoveSamplesFromFront;
37  } else if (fMethodTypeString == "RemoveSamplesFromBack") {
38  fMethod = eRemoveSamplesFromBack;
39  } else {
40  fMethod = eUndefined;
41  }
42 
43  ostringstream info;
44 
45  // check for valid xml input
46  if ((fNumberOfSamplesToKeep > 0 && fNumberOfSamplesToRemove > 0) ||
47  (fNumberOfSamplesToKeep == 0 && fNumberOfSamplesToRemove == 0)) {
48  ERROR("One of the fields (NumberOfSamplesToKeep, NumberOfSamplesToRemove) must be zero to define the stragegy");
49  return eFailure;
50  }
51 
52  info.str("");
53  if (fNumberOfSamplesToKeep > 0) {
54  info << "Will set all the trace to a size of " << fNumberOfSamplesToKeep << " samples";
55  INFOFinal(info);
56  } else {
57  info << "Will remove " << fNumberOfSamplesToRemove << " samples from the trace";
58  INFOFinal(info);
59  }
60 
61  return eSuccess;
62  }
63 
64 
66  RdChannelTimeSeriesClipper::Run(evt::Event& event)
67  {
68  // Check if there are events at all
69  if (!event.HasREvent()) {
70  INFO("No radio event found!");
71  return eContinueLoop;
72  }
73 
74  REvent& rEvent = event.GetREvent();
75  ostringstream info;
76 
77  // loop through stations and for every station through every channel
78  for (auto& station : rEvent.StationsRange()) {
79  for (auto& channel : station.ChannelsRange()) {
80 
81  if (!channel.IsActive()) // skip inactive channels
82  continue;
83 
84  // Work on the time trace of this channel
85  ChannelTimeSeries& timeSeries = channel.GetChannelTimeSeries();
86  const int samplesInTrace = timeSeries.GetSize();
87 
88  if ((fMethod == eRemoveSamplesFromBack || fMethod == eRemoveSamplesFromFront) &&
89  samplesInTrace < fNumberOfSamplesToRemove && fNumberOfSamplesToKeep == 0) {
90  info.str("");
91  info << "Station "<< station.GetId() << " Channel " << channel.GetId()
92  << ": You want to remove " << fNumberOfSamplesToRemove
93  << " samples which is more than the length of the time series: " << samplesInTrace
94  << ", skip to next channel";
95  WARNING(info);
96 
97  continue;
98  }
99 
100  if ((fMethod == eRemoveSamplesFromBack || fMethod == eRemoveSamplesFromFront) &&
101  fNumberOfSamplesToKeep > 0 && fNumberOfSamplesToKeep > samplesInTrace) {
102  info.str("");
103  info << "Station " << station.GetId() << " Channel " << channel.GetId()
104  << ": You want to keep " << fNumberOfSamplesToKeep
105  << " samples which is more than the length of the time series: " << samplesInTrace
106  << ", skip to next channel";
107  WARNING(info);
108 
109  continue;
110  }
111 
112  if (fNumberOfSamplesToKeep != 0) {
113  fNumberOfSamplesToRemove = samplesInTrace - fNumberOfSamplesToKeep;
114  }
115 
116  if (fInfoLevel > eInfoIntermediate) {
117  info.str("");
118  info << "get size: " << samplesInTrace << "\n"
119  << "fNumberOfSamplesToRemove = " << fNumberOfSamplesToRemove;
120 
121  if (fNumberOfSamplesToKeep > 0)
122  info << "\nfNumberOfSamplesToKeep = " << fNumberOfSamplesToKeep;
123 
124  INFOIntermediate(info);
125  }
126 
127  // clipping the time series
128  switch(fMethod)
129  {
130  case eRemoveSamplesFromBack:
131  {
132  for (int i = 0; i < fNumberOfSamplesToRemove; ++i)
133  timeSeries.PopBack();
134  break;
135  }
136 
137  case eRemoveSamplesFromFront:
138  {
139  ChannelTimeSeries tempTimeSeries;
140  tempTimeSeries.SetBinning(timeSeries.GetBinning());
141 
142  ChannelTimeSeries::SizeType iBegin = ChannelTimeSeries::SizeType(fNumberOfSamplesToRemove);
143  for (ChannelTimeSeries::SizeType i = iBegin; i < timeSeries.GetSize(); ++i)
144  tempTimeSeries.PushBack(timeSeries[i]);
145 
146  timeSeries = tempTimeSeries; // overwrite timetrace!
147 
148  // redefining the start time. keep parameter open because it might be overwritten by other modules
149  const double newStartTime = station.GetRecData().GetParameter(eTraceStartTime) +
150  fNumberOfSamplesToRemove * timeSeries.GetBinning();
151  station.GetRecData().SetParameter(eTraceStartTime, newStartTime, false);
152  break;
153  }
154 
155  case eUndefined:
156  {
157  WARNING("Undefined ClippingMethod. No Clipping performed");
158  return eSuccess;
159  break;
160  }
161  }
162  }
163  }
164 
165  return eSuccess;
166  }
167 
168 
170  RdChannelTimeSeriesClipper::Finish()
171  {
172  return eSuccess;
173  }
174 
175 }
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
double GetBinning() const
size of one slot
Definition: Trace.h:138
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
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
std::vector< double >::size_type SizeType
Definition: Trace.h:58
void PopBack()
Remove one value at the end of the trace.
Definition: Trace.h:129
SizeType GetSize() const
Definition: Trace.h:156
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
void SetBinning(const double binning)
Definition: Trace.h:139
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 INFOFinal(y)
Definition: VModule.h:161
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
#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.