4 #include <sevt/SEvent.h>
5 #include <sevt/EventTrigger.h>
7 #include <det/VManager.h>
9 #include <fwk/LocalCoordinateSystem.h>
10 #include <fwk/CentralConfig.h>
13 #include <boost/assign.hpp>
32 INFO(
"TriggerTimeCorrection::Init()");
33 auto topB = CentralConfig::GetInstance()->GetTopBranch(
"TriggerTimeCorrection");
37 for (
auto b = topB.GetFirstChild();
b;
b =
b.GetNextSibling()) {
39 const unsigned int stationId =
40 det::VManager::FindComponent<size_t>(
"stationId",
b.GetAttributes());
42 if (
Is(stationId).In(fTriggerMap)) {
43 ERROR(
"Duplicate station entries!");
47 vector<TriggerSoftware> trigger(1, fgFirstSoftware);
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);
55 sort(trigger.begin(), trigger.end());
57 fTriggerMap.insert(make_pair(stationId, trigger));
65 TriggerTimeCorrection::Run(
Event& event)
70 auto& sEvent =
event.GetSEvent();
71 const auto& eventTime = sEvent.GetTrigger().GetTime();
73 ostringstream stationOutput;
75 for (
auto&
s : sEvent.StationsRange()) {
76 if (!
s.HasTriggerData())
78 const auto& triggerSoft = GetTriggerSoftware(
s.GetId(), eventTime);
79 const auto& version = triggerSoft.fVersion;
80 const auto timeOffset = GetTimeOffset(version);
82 auto& trigData =
s.GetTriggerData();
83 trigData.SetPLDTimeOffset(timeOffset);
84 trigData.SetPLDVersion(version);
86 if (timeOffset.GetInterval() > numeric_limits<double>::min())
87 stationOutput <<
" (id=" <<
s.GetId() <<
", "
88 "PLD='" << version <<
"', "
89 "offset=" << timeOffset/
ns <<
"ns)";
92 const auto stationList = stationOutput.str();
93 if (!stationList.empty()) {
95 info <<
"for event at time " << eventTime <<
" the following corrections "
96 "were applied to stations:" << stationList;
105 TriggerTimeCorrection::GetTriggerSoftware(
const unsigned int stId,
109 const auto mapIter = fTriggerMap.find(stId);
110 if (mapIter == fTriggerMap.end())
111 return fgFirstSoftware;
113 const auto& trigger = mapIter->second;
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)
122 return trigger.empty() ? fgFirstSoftware : trigger.back();
127 TriggerTimeCorrection::GetTimeOffset(
const string& triggerName)
130 typedef map<string, TimeInterval> OffsetMap;
131 static const OffsetMap offsets({
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 },
152 const auto it = offsets.find(triggerName);
153 if (it != offsets.end())
157 err <<
"Unknown PLD version " << triggerName;
IsProxy< T > Is(const T &x)
Base class for exceptions arising because configuration data are not valid.
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
A TimeStamp holds GPS second and nanosecond for some event.
A TimeInterval is used to represent time elapsed between two events.
ResultFlag
Flag returned by module methods to the RunController.
#define ERROR(message)
Macro for logging error messages.