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"
25class TRTBeamConditions :
public ISInfoReceiver
28 static TRTBeamConditions &
instance();
30 virtual ~TRTBeamConditions() {}
37 static const char *m_name;
42const char *TRTBeamConditions::m_name(
"beamconditions.hitfractionTRT_longToT");
44TRTBeamConditions &TRTBeamConditions::instance()
46 static TRTBeamConditions s_instance;
50float TRTBeamConditions::get()
52 boost::mutex::scoped_lock lock(m_mutex);
56TRTBeamConditions::TRTBeamConditions() : ISInfoReceiver(IPCPartition(
"initial")), m_mutex(), m_value(0)
59 subscribe(m_name, &TRTBeamConditions::callback,
this);
60 }
catch (daq::is::Exception &ex) {
61 ERS_LOG(
"Subscribing to " << m_name <<
" IS Info failed: " << ex);
65void TRTBeamConditions::callback(ISCallbackInfo *info)
68 ISInfoFloat hitfraction;
69 info->value(hitfraction);
71 const long long timestamp =
info->time().total_mksec_utc();
72 const long long now = OWLTime().total_mksec_utc();
73 const long long maxAge = 5 * 60 * 1000000;
75 boost::mutex::scoped_lock lock(m_mutex);
76 if (now - timestamp < maxAge) {
77 m_value = hitfraction.getValue();
81 }
catch (daq::is::Exception &ex) {
82 ERS_LOG(
"Receiving " << m_name <<
" IS Info failed: " << ex);
86dqm_core::AlgorithmRegistrator<dqm_algorithms::TRTAvgEventSizeCheck> __ii__(
"TRTAvgEventSizeCheck");
92dqm_algorithms::TRTAvgEventSizeCheck::TRTAvgEventSizeCheck() : lastCollisionsSeen_(
boost::posix_time::min_date_time)
94 (void)TRTBeamConditions::instance();
97dqm_algorithms::TRTAvgEventSizeCheck *dqm_algorithms::TRTAvgEventSizeCheck::clone()
99 return new TRTAvgEventSizeCheck();
102dqm_core::Result *dqm_algorithms::TRTAvgEventSizeCheck::execute(
const std::string &name,
const TObject &
object,
const dqm_core::AlgorithmConfig &
config)
104 if (!
object.
IsA()->InheritsFrom(
"TH1")) {
105 throw dqm_core::BadConfig(ERS_HERE, name,
"histogram does not inherit from TH1");
109 throw dqm_core::BadConfig(ERS_HERE, name,
"histogram has more than one dimension");
114 const boost::posix_time::time_duration delayTime = boost::posix_time::seconds(delaySeconds);
116 const double hitFraction = TRTBeamConditions::instance().get();
117 const bool collisions = (hitFraction > noiseLimit);
118 const bool unknown = (hitFraction == 0);
120 const boost::posix_time::ptime
now = boost::posix_time::microsec_clock::universal_time();
122 const bool acceptLargeEvents = (
now <= (lastCollisionsSeen_ + delayTime) ||
unknown);
124 const char *avgThresholdName = acceptLargeEvents ?
"Avg_Collisions" :
"Avg_Noise";
130 int spyReadoutEnabled = 0;
131 int spyReadoutDisabled = 0;
134 const double binContent =
histogram.GetBinContent(i);
137 sum2 += binContent * binContent;
140 ++spyReadoutDisabled;
144 const int &
N = spyReadoutEnabled;
146 const double rms =
N ? std::sqrt(sum2 / N - avg * avg) : 0;
148 dqm_core::Result *
result =
new dqm_core::Result;
150 if (avg <= 0)
result->status_ = dqm_core::Result::Undefined;
151 else if (avg <= avgG)
result->status_ = dqm_core::Result::Green;
152 else if (avg < avgR)
result->status_ = dqm_core::Result::Yellow;
153 else result->status_ = dqm_core::Result::Red;
157 result->tags_[
"SpyReadoutDisabled"] = spyReadoutDisabled;
158 result->tags_[
"_HitFraction_"] = hitFraction;
160 result->tags_[
"_AcceptLargeEvents_"] = acceptLargeEvents;
164void dqm_algorithms::TRTAvgEventSizeCheck::printDescription(std::ostream& out)
166 out <<
"TRTAvgEventSizeCheck: checks the average event size from the TRT RODs.\n"
167 "The algorithm applies two different sets of thresholds, depending on whether we have collisions or not.\n"
168 "Mandatory parameters:\n"
169 " NoiseLimit: if \"hitfractionTRT_longToT\" is above this value, the algorithm assumes we are having collisions.\n"
170 "Optional parameters:\n"
171 " DelayTime: how long after collisions the algorithm still accepts large events (in seconds, default = 60).\n"
172 "Mandatory thresholds:\n"
173 " Avg_Collisions: the allowed average event size when we are having collisions.\n"
174 " Avg_Noise: the allowed average event size when we are not having collisions.\n"
176 " Avg: the average event size, averaged over all RODs in the histogram, excluding the ones with disabled spy readout.\n"
177 " RMS: the RMS of the average event size distribution, excluding the ones with disabled spy readout.\n"
178 " SpyReadoutDisabled: the number of RODs with disabled spy readout.\n"
179 " _HitFraction_: the value of \"hitfractionTRT_longToT\", mirrored as a DQMF result.\n"
180 " _Collisions_: is \"hitfractionTRT_longToT\" currently above the NoiseLimit?\n"
181 " _AcceptLargeEvents_: are we still in the DelayTime after collisions?" << std::endl;
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
#define IsA
Declare the TObject style functions.