13#include "GaudiKernel/DirSearchPath.h"
14#include "GaudiKernel/IIncidentSvc.h"
15#include "Gaudi/Interfaces/IOptionsSvc.h"
16#include "eformat/DetectorMask.h"
17#include "eformat/SourceIdentifier.h"
26 std::string folder2HistName(
const std::string& folder)
28 std::string
s(folder);
29 if (
s.front() ==
'/')
s.erase(0, 1);
30 std::replace(
s.begin(),
s.end(),
'/',
'_');
35 StatusCode readReleaseData(
const std::string&
file, std::map<std::string, std::string>& result)
38 f.open(
file.c_str(), std::ifstream::in);
39 if (!
f.is_open())
return StatusCode::FAILURE;
42 while (getline(f, line)) {
44 std::string::size_type loc =
line.find(
':');
45 if (loc == std::string::npos || loc == 0)
continue;
49 return StatusCode::SUCCESS;
55 base_class(name, pSvcLocator),
56 m_histPath(
"/EXPERT/HLTFramework/" + name +
"/")
68 return StatusCode::SUCCESS;
89 return StatusCode::SUCCESS;
95 [[maybe_unused]]
const static bool once = [&]() {
111 return StatusCode::SUCCESS;
120 m_iovChangeHist =
new TH2I(
"CoolFolderUpdate_LB",
"COOL folder updates;Lumiblock;", 1, 0, 1, 1, 0, 1);
123 m_magFieldHist =
new TH2I(
"MagneticFieldSettings",
"Magnetic field settings", 2, 0, 2, 2, 0, 2);
129 m_releaseHist =
new TH1I(
"GeneralOpInfo",
"General operational info;;Applications", 1, 0, 1);
131 m_mtConfigHist =
new TH2I(
"MTConfig",
"Multi-threading configuration", 2, 0, 2, 10, 0, 10);
136 m_workersHist =
new TH1I(
"MPWorkers",
"Worker IDs;Worker ID;Number of workers", 10, 0, 10);
139 m_subdetHist =
new TH2I(
"Subdetectors",
"State of subdetectors", 1, 0, 1, 3, 0, 3);
145 m_lumiHist =
new TProfile(
"Luminosity",
"Luminosity;Lumiblock;Luminosity [10^{33} cm^{-2}s^{-1}]",
155 for (TH1*
h : hist) {
159 return StatusCode::SUCCESS;
176 std::vector<std::string> keyList;
180 TH2I* IOVDbRunHist =
new TH2I(
"IOVDbRunRange",
"IOVDb Run Range", 1, 0, 1, 1, 0, 1);
181 TH2I* IOVDbTimeHist =
new TH2I(
"IOVDbTimeRange",
"IOVDb Time Range", 1, 0, 1, 1, 0, 1);
182 TProfile* IOVDbBytesReadHist =
new TProfile(
"IOVDbBytesRead",
"Folder data read", 1, 0, 1);
183 IOVDbBytesReadHist->SetYTitle(
"Data read [bytes]");
184 TProfile* IOVDbReadTimeHist =
new TProfile(
"IOVDbReadTime",
"Folder update time", 1, 0, 1);
185 IOVDbReadTimeHist->SetYTitle(
"Update time [ms]");
189 for (
const std::string& key : keyList) {
191 if (
m_IOVDbSvc->getKeyInfo(key, info) && info.retrieved) {
196 IOVTime stop(info.range.stop());
199 if (
start.isRunEvent()) {
200 IOVDbRunHist->Fill(std::to_string(
start.run()).c_str(), info.folderName.c_str(), 1.0);
204 if (
start.isTimestamp()) {
205 IOVDbTimeHist->Fill(std::to_string(
start.timestamp()).c_str(), info.folderName.c_str(), 1.0);
209 if (stop.isRunEvent()) {
211 IOVDbRunHist->Fill(
"infinity", info.folderName.c_str(), 1.0);
214 IOVDbRunHist->Fill(std::to_string(stop.run()).c_str(), info.folderName.c_str(), 1.0);
219 if (stop.isTimestamp()) {
221 IOVDbTimeHist->Fill(
"infinity", info.folderName.c_str(), 1.0);
224 IOVDbTimeHist->Fill(std::to_string(stop.timestamp()).c_str(), info.folderName.c_str(), 1.0);
229 IOVDbBytesReadHist->Fill(info.folderName.c_str(), info.bytesRead, 1.0);
230 IOVDbReadTimeHist->Fill(info.folderName.c_str(), info.readTime * 1000, 1.0);
235 IOVDbRunHist->LabelsDeflate(
"X");
236 IOVDbRunHist->LabelsDeflate(
"Y");
237 IOVDbRunHist->GetYaxis()->LabelsOption(
"a");
239 IOVDbTimeHist->LabelsDeflate(
"X");
240 IOVDbTimeHist->LabelsDeflate(
"Y");
241 IOVDbTimeHist->GetYaxis()->LabelsOption(
"a");
243 IOVDbBytesReadHist->LabelsDeflate(
"X");
244 IOVDbReadTimeHist->LabelsDeflate(
"X");
247 TH1* hist[] = {IOVDbRunHist, IOVDbTimeHist, IOVDbBytesReadHist, IOVDbReadTimeHist};
248 for (TH1*
h : hist) {
255 std::vector<std::string> keys;
260 for (
const std::string& k : keys) {
262 if (not
m_IOVDbSvc->getKeyInfo(k, info))
continue;
263 if (not info.retrieved)
continue;
272 if (info.range != curIOV->second) {
273 ATH_MSG_INFO(
"IOV of " << k <<
" changed from " << curIOV->second <<
" to " << info.range
274 <<
" on event: " << ctx.eventID());
279 m_iovChangeHist->Fill(std::to_string(ctx.eventID().lumi_block()).c_str(), info.folderName.c_str(),
289 std::string name(folder2HistName(info.folderName));
292 fh->second.h_time =
new TH1F((name +
"_ReadTime").c_str(),
293 (
"Update time for " + info.folderName +
";Time [ms];Entries").c_str(),
296 fh->second.h_bytes =
new TH1F(
297 (name +
"_BytesRead").c_str(),
298 (
"Bytes read for " + info.folderName +
";Data [bytes];Entries").c_str(), 100, 0, 1000);
300 for (TH1*
h : {fh->second.h_time, fh->second.h_bytes}) {
306 fh->second.h_time->Fill(info.readTime * 1000 -
m_folderHist[info.folderName].total_time);
307 fh->second.total_time += info.readTime * 1000;
309 fh->second.h_bytes->Fill(info.bytesRead -
m_folderHist[info.folderName].total_bytes);
310 fh->second.total_bytes += info.bytesRead;
322 m_lumiHist->Fill(ctx.eventID().lumi_block(), lumiData->lbAverageLuminosity());
323 m_muHist->Fill(ctx.eventID().lumi_block(), lumiData->lbAverageInteractionsPerCrossing());
329 const char* ld_lib_path = getenv(
"LD_LIBRARY_PATH");
330 if (ld_lib_path ==
nullptr) {
331 ATH_MSG_WARNING(
"LD_LIBRARY_PATH is not defined. Will not fill release histogram.");
336 std::list<DirSearchPath::path> file_list = DirSearchPath(ld_lib_path,
":").find_all(
m_releaseData.value());
338 if (file_list.empty()) {
340 <<
" in LD_LIBRARY_PATH");
345 for (
const auto& f : file_list) {
347 std::map<std::string, std::string> result;
348 if (readReleaseData(f.string(), result).isFailure()) {
355 if (result.find(
"project name") == result.end() || result.find(
"release") == result.end()) {
361 m_releaseHist->Fill((result[
"project name"] +
" " + result[
"release"]).c_str(), 1);
369 auto getIntProp = [
this](std::string_view name,
const std::string& prop) -> std::optional<int> {
370 IProperty* svc = serviceLocator()->service(name).as<IProperty>();
371 if (svc ==
nullptr)
return std::nullopt;
373 return std::stoi(svc->getProperty(prop).toString());
380 const std::optional<int> numThreads = getIntProp(
"AvalancheSchedulerSvc",
"ThreadPoolSize");
381 if (numThreads.has_value()) {
385 ATH_MSG_WARNING(
"Could not retrieve the number of threads to fill the monitoring histogram");
388 const std::optional<int> numSlots = getIntProp(
"EventDataSvc",
"NSlots");
389 if (numSlots.has_value()) {
393 ATH_MSG_WARNING(
"Could not retrieve the number of slots to fill the monitoring histogram");
401 auto jobOptionsSvc = service<Gaudi::Interfaces::IOptionsSvc>(
"JobOptionsSvc",
false);
402 if (!jobOptionsSvc.isValid()) {
403 ATH_MSG_WARNING(
"Could not retrieve JobOptionsSvc, will not fill SubDetectors histogram");
407 Gaudi::Property<std::vector<uint32_t>> enabledROBsProp(
"EnabledROBs",{});
408 std::set<uint32_t> enabledROBs;
409 if (enabledROBsProp.fromString(jobOptionsSvc->get(
"DataFlowConfig.DF_Enabled_ROB_IDs",
"[]")).isSuccess()) {
410 enabledROBs.insert(enabledROBsProp.value().begin(), enabledROBsProp.value().end());
412 <<
" ROBs from DataFlowConfig.DF_Enabled_ROB_IDs");
415 ATH_MSG_ERROR(
"Could not parse DataFlowConfig.DF_Enabled_ROB_IDs from JobOptionsSvc");
419 SmartIF<StoreGateSvc> inputMetaDataStore = service<StoreGateSvc>(
"InputMetaDataStore",
false);
420 if (!inputMetaDataStore.isValid()) {
421 ATH_MSG_WARNING(
"Could not retrieve InputMetaDataStore, will not fill SubDetectors histogram");
425 if (inputMetaDataStore->retrieve(metadatacont,
"ByteStreamMetadata").isFailure()) {
426 ATH_MSG_WARNING(
"Could not retrieve ByteStreamMetadata, will not fill SubDetectors histogram");
431 uint64_t detMaskLeast = metadata->getDetectorMask();
432 uint64_t detMaskMost = metadata->getDetectorMask2();
435 std::vector<eformat::SubDetector> subDetOn;
436 std::vector<eformat::SubDetector> subDetOff;
437 std::vector<eformat::SubDetector> subDetAll;
438 eformat::helper::DetectorMask(detMaskLeast, detMaskMost).sub_detectors(subDetOn);
439 eformat::helper::DetectorMask(~detMaskLeast, ~detMaskMost).sub_detectors(subDetOff);
440 eformat::helper::DetectorMask(~std::bitset<128>()).sub_detectors(subDetAll);
443 for (
const eformat::SubDetector sd : subDetAll) {
444 m_subdetHist->GetXaxis()->FindBin(eformat::helper::SubDetectorDictionary.
string(sd).data());
449 for (
const eformat::SubDetector sd : subDetOn) {
450 m_subdetHist->Fill(eformat::helper::SubDetectorDictionary.
string(sd).data(),
"on", 1.0);
454 for (
const eformat::SubDetector sd : subDetOff) {
455 m_subdetHist->Fill(eformat::helper::SubDetectorDictionary.
string(sd).data(),
"off", 1.0);
459 for (
const uint32_t robid : enabledROBs) {
460 const std::string sdname = eformat::helper::SourceIdentifier(robid).human_detector();
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
OH histogram lock header file.
Online operations monitoring.
Header file for AthHistogramAlgorithm.
static const std::string & type()
Incident type.
int workerID() const
assigned worker ID from processing unit
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Basic time unit for IOVSvc.
static constexpr uint64_t MAXTIMESTAMP
static constexpr uint32_t MAXRUN
bool solenoidOn() const
status of the magnets
void fillProcThreadHist(int workerID)
std::string m_histPath
histogram booking path
std::unordered_map< std::string, IOVRange > m_currentIOVs
current IOVs managed by IOVDbSvc
ServiceHandle< ITHistSvc > m_histSvc
ServiceHandle< IIncidentSvc > m_incidentSvc
virtual StatusCode initialize() override
void fillReleaseDataHist()
TrigOpMonitor(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_detailedHists
virtual StatusCode start() override
virtual StatusCode execute(const EventContext &ctx) override
void fillIOVDbChangeHist(const EventContext &ctx)
Gaudi::Property< unsigned short int > m_maxLB
Gaudi::Property< std::string > m_releaseData
SG::ReadCondHandleKey< AtlasFieldMapCondObj > m_fieldMapKey
virtual void handle(const Incident &incident) override
std::unordered_map< std::string, FolderHist > m_folderHist
histograms for COOL folders
SG::ReadCondHandleKey< LuminosityCondData > m_lumiDataKey
void fillLumiHist(const EventContext &ctx)
EventIDBase::number_type m_previousLB
LB of previous event.
SmartIF< IIOVDbSvc > m_IOVDbSvc
Scoped lock to be used for threaded histogram operations.
::StatusCode StatusCode
StatusCode definition for legacy code.
Filled by IIOVDbSvc::getKeyInfo.
Histograms for COOL folders.