10#include "dqm_core/AlgorithmManager.h"
11#include "dqm_core/AlgorithmRegistrator.h"
12#include "dqm_core/AlgorithmConfig.h"
15#include "ipc/partition.h"
16#include "is/inforeceiver.h"
17#include "is/callbackinfo.h"
26class TRTBeamConditions :
public ISInfoReceiver
29 static TRTBeamConditions &
instance();
31 virtual ~TRTBeamConditions() {}
43const char *TRTBeamConditions::m_name(
"beamconditions.hitfractionTRT_longToT");
45TRTBeamConditions &TRTBeamConditions::instance()
47 static TRTBeamConditions s_instance;
51float TRTBeamConditions::get()
53 std::lock_guard<std::mutex>
lock(m_mutex);
57TRTBeamConditions::TRTBeamConditions() : ISInfoReceiver(IPCPartition(
"initial")),
m_mutex(), m_value(0)
60 subscribe(m_name, &TRTBeamConditions::callback,
this);
61 }
catch (daq::is::Exception &ex) {
62 ERS_LOG(
"Subscribing to " << m_name <<
" IS Info failed: " << ex);
66void TRTBeamConditions::callback(ISCallbackInfo *info)
69 ISInfoFloat hitfraction;
70 info->value(hitfraction);
72 const long long timestamp =
info->time().total_mksec_utc();
73 const long long now = OWLTime().total_mksec_utc();
74 const long long maxAge = 5 * 60 * 1000000;
76 std::lock_guard<std::mutex>
lock(m_mutex);
77 if (now - timestamp < maxAge) {
78 m_value = hitfraction.getValue();
82 }
catch (daq::is::Exception &ex) {
83 ERS_LOG(
"Receiving " << m_name <<
" IS Info failed: " << ex);
87dqm_core::AlgorithmRegistrator<dqm_algorithms::TRTAvgEventSizeCheck> __ii__(
"TRTAvgEventSizeCheck");
93dqm_algorithms::TRTAvgEventSizeCheck::TRTAvgEventSizeCheck() : lastCollisionsSeen_(
boost::posix_time::min_date_time)
95 (void)TRTBeamConditions::instance();
98dqm_algorithms::TRTAvgEventSizeCheck *dqm_algorithms::TRTAvgEventSizeCheck::clone()
100 return new TRTAvgEventSizeCheck();
103dqm_core::Result *dqm_algorithms::TRTAvgEventSizeCheck::execute(
const std::string &name,
const TObject &
object,
const dqm_core::AlgorithmConfig &config)
105 if (!
object.
IsA()->InheritsFrom(
"TH1")) {
106 throw dqm_core::BadConfig(ERS_HERE, name,
"histogram does not inherit from TH1");
108 const TH1 &
histogram =
dynamic_cast<const TH1 &
>(object);
110 throw dqm_core::BadConfig(ERS_HERE, name,
"histogram has more than one dimension");
115 const boost::posix_time::time_duration delayTime = boost::posix_time::seconds(delaySeconds);
117 const double hitFraction = TRTBeamConditions::instance().get();
118 const bool collisions = (hitFraction > noiseLimit);
119 const bool unknown = (hitFraction == 0);
121 const boost::posix_time::ptime
now = boost::posix_time::microsec_clock::universal_time();
123 const bool acceptLargeEvents = (
now <= (lastCollisionsSeen_ + delayTime) ||
unknown);
125 const char *avgThresholdName = acceptLargeEvents ?
"Avg_Collisions" :
"Avg_Noise";
131 int spyReadoutEnabled = 0;
132 int spyReadoutDisabled = 0;
135 const double binContent =
histogram.GetBinContent(i);
138 sum2 += binContent * binContent;
141 ++spyReadoutDisabled;
145 const int &
N = spyReadoutEnabled;
147 const double rms =
N ? std::sqrt(sum2 / N - avg * avg) : 0;
149 dqm_core::Result *
result =
new dqm_core::Result;
151 if (avg <= 0)
result->status_ = dqm_core::Result::Undefined;
152 else if (avg <= avgG)
result->status_ = dqm_core::Result::Green;
153 else if (avg < avgR)
result->status_ = dqm_core::Result::Yellow;
154 else result->status_ = dqm_core::Result::Red;
158 result->tags_[
"SpyReadoutDisabled"] = spyReadoutDisabled;
159 result->tags_[
"_HitFraction_"] = hitFraction;
161 result->tags_[
"_AcceptLargeEvents_"] = acceptLargeEvents;
165void dqm_algorithms::TRTAvgEventSizeCheck::printDescription(std::ostream& out)
167 out <<
"TRTAvgEventSizeCheck: checks the average event size from the TRT RODs.\n"
168 "The algorithm applies two different sets of thresholds, depending on whether we have collisions or not.\n"
169 "Mandatory parameters:\n"
170 " NoiseLimit: if \"hitfractionTRT_longToT\" is above this value, the algorithm assumes we are having collisions.\n"
171 "Optional parameters:\n"
172 " DelayTime: how long after collisions the algorithm still accepts large events (in seconds, default = 60).\n"
173 "Mandatory thresholds:\n"
174 " Avg_Collisions: the allowed average event size when we are having collisions.\n"
175 " Avg_Noise: the allowed average event size when we are not having collisions.\n"
177 " Avg: the average event size, averaged over all RODs in the histogram, excluding the ones with disabled spy readout.\n"
178 " RMS: the RMS of the average event size distribution, excluding the ones with disabled spy readout.\n"
179 " SpyReadoutDisabled: the number of RODs with disabled spy readout.\n"
180 " _HitFraction_: the value of \"hitfractionTRT_longToT\", mirrored as a DQMF result.\n"
181 " _Collisions_: is \"hitfractionTRT_longToT\" currently above the NoiseLimit?\n"
182 " _AcceptLargeEvents_: are we still in the DelayTime after collisions?" << std::endl;
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
std::string m_name
The primary name part of this expression.
#define IsA
Declare the TObject style functions.