SdStationChecker.cc
Go to the documentation of this file.
1 #include "SdStationChecker.h"
2 #include <evt/Event.h>
3 #include <sevt/SEvent.h>
4 #include <sevt/EventTrigger.h>
5 #include <utl/String.h>
6 
7 using namespace fwk;
8 using namespace sevt;
9 using namespace utl;
10 using namespace std;
11 
12 
13 namespace SdStationCheckerOG {
14 
15  void
16  MakeInfo(const vector<int>& ids, const string& message)
17  {
18  if (ids.empty())
19  return;
20  ostringstream info;
21  info << "station" << String::Plural(ids) << ' ' << String::OfSortedIds(ids) << ' ' << message;
22  INFO(info);
23  }
24 
25 
27  SdStationChecker::Run(evt::Event& event)
28  {
29  if (!event.HasSEvent())
30  return eSuccess;
31  auto& sEvent = event.GetSEvent();
32 
33  vector<int> randomTrigger;
34  vector<int> badCompression;
35  int noTrigger = 0;
36 
37  const bool isCommsCrisis = kCommsCrisis.IsInRange(det::Detector::GetInstance().GetTime());
38 
39  // loop on stations
40  for (auto& station : sEvent.StationsRange()) {
41 
42  if (!station.HasTriggerData()) {
43  station.SetRejected(StationConstants::eNoTrigger);
44  ++noTrigger;
45  continue;
46  }
47 
48  // T2Life() has to be checked before SetSilent() is applied!
49  if (!station.IsT2Life())
50  station.SetRejected(StationConstants::eNotAliveT2);
51  if (isCommsCrisis && !station.IsT2Life120())
52  station.SetRejected(StationConstants::eNotAliveT120);
53 
54  const auto& trig = station.GetTriggerData();
55  if (trig.GetErrorCode() & 0xff) { // for UUBs errorcodes are above 256.
56  if (trig.IsSilent() && !station.IsRejected())
57  station.SetSilent();
58  else
59  station.SetRejected(StationConstants::eErrorCode);
60  continue;
61  }
62 
63  if (trig.IsRandom()) {
64  randomTrigger.push_back(station.GetId());
65  station.SetRejected(StationConstants::eRandom);
66  continue;
67  }
68 
69  if (!station.HasCalibData()) {
70  station.SetRejected(StationConstants::eNoCalibData);
71  continue;
72  }
73 
74  // exclude FADCs with Patrick's data
75  if (station.GetCalibData().GetVersion() > 32000) {
76  ostringstream warn;
77  warn << "Station " << station.GetId() << " has LS calibration version "
78  << station.GetCalibData().GetVersion() << '!';
79  WARNING(warn);
80  station.SetRejected(StationConstants::eNoCalibData);
81  continue;
82  }
83 
84  if (!station.HasGPSData()) {
85  station.SetRejected(StationConstants::eNoGPSData);
86  continue;
87  }
88 
89  ApplyTimeCorrection(station);
90 
91  // check for "bad compressed data"
92  if (sEvent.HasTrigger()) {
93  const int trigSecond = sEvent.GetTrigger().GetTime().GetGPSSecond();
94  const int timeDiff = int(station.GetGPSData().GetSecond()) - trigSecond;
95  if (abs(timeDiff) > 1) {
96  station.GetTriggerData().SetErrorCode(StationTriggerData::eBadCompress);
97  station.SetRejected(StationConstants::eBadCompress);
98  const int sId = station.GetId();
99  badCompression.push_back(sId);
100  ostringstream info;
101  info << "Bad compress data: station " << sId << " has " << timeDiff
102  << " sec of time difference to event trigger.";
103  INFO(info);
104  continue;
105  }
106  }
107 
108  } // end of loop over stations
109 
110  MakeInfo(randomTrigger, "with random trigger rejected.");
111  MakeInfo(badCompression, "with bad compression data rejected.");
112 
113  if (noTrigger) {
114  ostringstream info;
115  info << noTrigger << " station" << String::Plural(noTrigger)
116  << String::OfSortedIds(badCompression) << " without trigger data rejected.";
117  INFO(info);
118  }
119 
120  return eSuccess;
121  }
122 
123 
124  void
126  {
127  auto& gpsData = station.GetGPSData();
128 
129  // NEW : TAP 26/04/2003 -> From CDAS v1r2 : taking into account Offsets...
130  // Warning, part of the field is used for the tick offset:
131  // GPS Offset = 0.01*(short)(gps->Offset & 0xffff)
132  // Tick Offset = (short)(gps->Offset>>16)
133  // New: taking into account 100ns jumps
134  // From Moulin Rouge and Dia Noche we found that the TickFall-Tick
135  // can be 0, 9, 10, 11 or a big number. The big number could be
136  // understood if it is the trigger of another event. It was found
137  // that if the dt is 0, there is a 100ns jump in the event, and not
138  // in any other case, including big values. Hence this empiric
139  // correction
140  //
141  // This is the code from IoSd v1r2 :
142  // gps->NanoSecond =
143  // (unsigned int)((gps->Tick*(1000000000.0 + gps->NextST - gps->CurrentST)
144  // /gps->Next100) + gps->CurrentST + 0.01*(short)(gps->Offset & 0xffff))
145  // -100*(gps->TickFall == gps->Tick);
146 
147  const unsigned int tick = gpsData.GetTick();
148  const int currentST = gpsData.GetCurrentST();
149  const int next100 = gpsData.GetNext100();
150  const int nextST = gpsData.GetNextST();
151 
152 #ifndef IOSD_V1R0
153  const unsigned int tickFall = gpsData.GetTickFall();
154  const int offset = gpsData.GetOffset();
155 
156  const unsigned int nanosecond =
157  (unsigned int)((tick * (1e9 + nextST - currentST) / next100) + currentST +
158  0.01 * short(offset & 0xffff)) - 100 * (tickFall == tick);
159 #else
160  const unsigned int nanosecond =
161  (unsigned int)((tick * (1e9 + nextST - currentST) / next100) + currentST);
162 #endif
163 
164  gpsData.SetCorrectedNanosecond(nanosecond);
165  }
166 
167 }
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void ApplyTimeCorrection(StationGPSData &gpsData)
const char * Plural(const T n)
Definition: String.h:104
unsigned int GetTick() const
class to hold data at Station level
constexpr double nanosecond
Definition: AugerUnits.h:143
double abs(const SVector< n, T > &v)
sevt::StationGPSData & GetGPSData()
Get GPS data for the station.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void MakeInfo(const vector< int > &ids, const string &message)
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
string OfSortedIds(vector< int > ids)
Definition: String.cc:65
bool HasSEvent() const

, generated on Tue Sep 26 2023.