SdBadStationRejector.cc
Go to the documentation of this file.
1 #include "SdBadStationRejector.h"
2 #include <fwk/CentralConfig.h>
3 #include <det/VManager.h>
4 #include <utl/Branch.h>
5 #include <utl/ErrorLogger.h>
6 #include <utl/String.h>
7 #include <evt/Event.h>
8 #include <sevt/SEvent.h>
9 #include <sevt/StationConstants.h>
10 
11 #include <sstream>
12 
13 using namespace std;
14 using namespace fwk;
15 using namespace det;
16 using namespace utl;
17 using namespace evt;
18 using namespace sevt;
19 using namespace SdBadStationRejectorKG;
20 
21 
24 {
25  auto topB = CentralConfig::GetInstance()->GetTopBranch("SdBadStationRejector");
26 
27  fRejectMap.clear();
28 
29  ostringstream info;
30  info << "registered stations:";
31  for (auto b = topB.GetFirstChild(); b; b = b.GetNextSibling()) {
32  const auto stationId = VManager::FindComponent<size_t>("id", b.GetAttributes());
33  const auto reason = VManager::FindComponent<string>("reason", b.GetAttributes());
34 
35  const auto range = b.Get<vector<utl::TimeStamp>>();
36 
37  fRejectMap.insert(make_pair(range[0], make_pair(range[1], stationId)));
38 
39  info << ' ' << stationId << " [" << range[0] << ", " << range[1] << ')';
40  }
41  INFO(info);
42 
43  return fRejectMap.empty() ? eFailure : eSuccess;
44 }
45 
46 
48 SdBadStationRejector::Run(Event& event)
49 {
50  if (!event.HasSEvent())
51  return eSuccess;
52 
53  auto& sEvent = event.GetSEvent();
54 
55  const auto& time = det::Detector::GetInstance().GetTime();
56 
57  const auto badIds = fRejectMap.GetBadStations(time);
58 
59  vector<int> infoList;
60  for (const auto& sId : badIds) {
61  if (sEvent.HasStation(sId)) {
62  infoList.push_back(sId);
63  // other rejection status?
64  sEvent.GetStation(sId).SetRejected(StationConstants::eOffGrid);
65  }
66  }
67 
68  if (!infoList.empty()) {
69  ostringstream info;
70  info << Join(" ", infoList) << "rejected.";
71  INFO(info);
72  }
73 
74  return eSuccess;
75 }
76 
77 
79 SdBadStationRejector::Finish()
80 {
81  TimeRangeMap().swap(fRejectMap);
82 
83  return eSuccess;
84 }
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
oss<< "0b";oss<< ((x >> i)&1);return oss.str();}template< class S, class V > std::string Join(const S &sep, const V &v)
Definition: String.h:60
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
bool HasSEvent() const

, generated on Tue Sep 26 2023.