TriggerTimeCorrection.cc
Go to the documentation of this file.
2 
3 #include <evt/Event.h>
4 #include <sevt/SEvent.h>
5 #include <sevt/EventTrigger.h>
6 
7 #include <det/VManager.h>
8 
9 #include <fwk/LocalCoordinateSystem.h>
10 #include <fwk/CentralConfig.h>
11 #include <utl/Is.h>
12 
13 #include <boost/assign.hpp>
14 #include <algorithm>
15 
16 using namespace evt;
17 using namespace sevt;
18 
19 using namespace std;
20 using namespace utl;
21 using namespace fwk;
22 
23 
25 
26  const TriggerTimeCorrection::TriggerSoftware TriggerTimeCorrection::fgFirstSoftware("251003", TimeStamp());
27 
28 
31  {
32  INFO("TriggerTimeCorrection::Init()");
33  auto topB = CentralConfig::GetInstance()->GetTopBranch("TriggerTimeCorrection");
34 
35  fTriggerMap.clear();
36 
37  for (auto b = topB.GetFirstChild(); b; b = b.GetNextSibling()) {
38 
39  const unsigned int stationId =
40  det::VManager::FindComponent<size_t>("stationId", b.GetAttributes());
41 
42  if (Is(stationId).In(fTriggerMap)) {
43  ERROR("Duplicate station entries!");
44  return eFailure;
45  }
46 
47  vector<TriggerSoftware> trigger(1, fgFirstSoftware);
48 
49  for (auto c = b.GetFirstChild(); c; c = c.GetNextSibling()) {
50  const auto& softName = det::VManager::FindComponent<string>("name", c.GetAttributes());
51  const auto installationTime = c.Get<TimeStamp>();
52  trigger.emplace_back(softName, installationTime);
53  }
54 
55  sort(trigger.begin(), trigger.end());
56 
57  fTriggerMap.insert(make_pair(stationId, trigger));
58  }
59 
60  return eSuccess;
61  }
62 
63 
65  TriggerTimeCorrection::Run(Event& event)
66  {
67  if (!event.HasSEvent())
68  return eSuccess;
69 
70  auto& sEvent = event.GetSEvent();
71  const auto& eventTime = sEvent.GetTrigger().GetTime();
72 
73  ostringstream stationOutput;
74 
75  for (auto& s : sEvent.StationsRange()) {
76  if (!s.HasTriggerData())
77  continue;
78  const auto& triggerSoft = GetTriggerSoftware(s.GetId(), eventTime);
79  const auto& version = triggerSoft.fVersion;
80  const auto timeOffset = GetTimeOffset(version);
81 
82  auto& trigData = s.GetTriggerData();
83  trigData.SetPLDTimeOffset(timeOffset);
84  trigData.SetPLDVersion(version);
85 
86  if (timeOffset.GetInterval() > numeric_limits<double>::min())
87  stationOutput << " (id=" << s.GetId() << ", "
88  "PLD='" << version << "', "
89  "offset=" << timeOffset/ns << "ns)";
90  }
91 
92  const auto stationList = stationOutput.str();
93  if (!stationList.empty()) {
94  ostringstream info;
95  info << "for event at time " << eventTime << " the following corrections "
96  "were applied to stations:" << stationList;
97  INFO(info);
98  }
99 
100  return eSuccess;
101  }
102 
103 
105  TriggerTimeCorrection::GetTriggerSoftware(const unsigned int stId,
106  const TimeStamp& time)
107  const
108  {
109  const auto mapIter = fTriggerMap.find(stId);
110  if (mapIter == fTriggerMap.end())
111  return fgFirstSoftware;
112 
113  const auto& trigger = mapIter->second;
114 
115  for (size_t i = 1, n = trigger.size(); i < n; ++i) {
116  const auto& curr = trigger[i];
117  const auto& prev = trigger[i-1];
118  if (prev.fInstallationTime < time && time < curr.fInstallationTime)
119  return prev;
120  }
121 
122  return trigger.empty() ? fgFirstSoftware : trigger.back();
123  }
124 
125 
127  TriggerTimeCorrection::GetTimeOffset(const string& triggerName)
128  const
129  {
130  typedef map<string, TimeInterval> OffsetMap;
131  static const OffsetMap offsets({
132  { "160703", 0 },
133  { "251003", 0 },
134  { "140205", 0 },
135  { "060405", 0 },
136  { "030805", 0 },
137  { "250210", 0 },
138  { "071110", 0 },
139  { "211110", 75*ns },
140  { "270211", 100*ns },
141  { "190511", 100*ns },
142  { "020811", 100*ns },
143  { "171011", 100*ns },
144  { "191011", 100*ns },
145  { "121211", 100*ns },
146  { "200112", 100*ns },
147  { "220512", 100*ns },
148  { "230512", 100*ns },
149  { "270612", 100*ns }
150  });
151 
152  const auto it = offsets.find(triggerName);
153  if (it != offsets.end())
154  return it->second;
155 
156  ostringstream err;
157  err << "Unknown PLD version " << triggerName;
158  ERROR(err);
159  throw InvalidConfigurationException(err.str());
160 
161  return TimeInterval();
162  }
163 
164 }
IsProxy< T > Is(const T &x)
Definition: Is.h:46
Base class for exceptions arising because configuration data are not valid.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
constexpr double s
Definition: AugerUnits.h:163
const double ns
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
bool HasSEvent() const

, generated on Tue Sep 26 2023.