ATLAS Offline Software
Loading...
Searching...
No Matches
WebdaqInfoSvc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIGSERVICES_WEBDAQINFOSVC_H
6#define TRIGSERVICES_WEBDAQINFOSVC_H
7
9#include "GaudiKernel/IIncidentListener.h"
11
12#include "TrigServicesUtils.h"
13
14#include "hltinterface/IInfoRegister.h"
15
16#include <nlohmann/json_fwd.hpp>
17
18#include <atomic>
19#include <map>
20#include <memory>
21#include <mutex>
22#include <string>
23#include <thread>
24#include <unordered_map>
25#include <vector>
26
27class TObject;
28
29namespace hltinterface {
30 class ContainerFactory;
31 class GenericHLTContainer;
32}
33
51class WebdaqInfoSvc : public extends<AthService, IIncidentListener>,
52 public hltinterface::IInfoRegister
53{
54public:
55 using base_class::base_class;
56 virtual ~WebdaqInfoSvc() noexcept override {}
57
58 virtual StatusCode initialize ATLAS_NOT_THREAD_SAFE () override;
59 virtual StatusCode configure() override { return StatusCode::SUCCESS; }
60 virtual StatusCode stop() override;
61 virtual StatusCode finalize() override;
62 virtual void handle(const Incident& incident) override;
63
64 // ------------------------------------------------------------------------
65 // hltinterface::IInfoRegister — IS
66 // ------------------------------------------------------------------------
67 virtual bool configure (const boost::property_tree::ptree&) override { return true; }
68 virtual bool prepareForRun (const boost::property_tree::ptree&) override { return true; }
69 virtual bool prepareWorker (const boost::property_tree::ptree&) override { return true; }
70 virtual bool finalizeWorker(const boost::property_tree::ptree&) override { return true; }
71 virtual bool finalize (const boost::property_tree::ptree&) override { return true; }
72
73 // The by-value strings below are imposed by the hltinterface::IInfoRegister base class.
74 // cppcheck-suppress passedByValue; signature fixed by hltinterface::IInfoRegister
75 virtual bool registerObject(const std::string publishPath,
76 std::shared_ptr<hltinterface::GenericHLTContainer> obj) override;
79 // cppcheck-suppress passedByValue; signature fixed by hltinterface::IInfoRegister
80 virtual bool releaseObject (const std::string fullName) override;
81 virtual bool pullInfo (const std::string&, const std::string&) override { NOSUPPORT(DEBUG, "pullInfo"); }
82
83 virtual bool beginEvent(const boost::property_tree::ptree&) override { return true; }
84 virtual bool endEvent (const boost::property_tree::ptree&) override;
85
86 virtual std::vector<std::shared_ptr<hltinterface::GenericHLTContainer>>
87 queryISRegistry(const std::string&) override { NOSUPPORT(DEBUG, "queryISRegistry"); }
88
89 // ------------------------------------------------------------------------
90 // hltinterface::IInfoRegister — Histograms (handled by WebdaqHistSvc, unsupported).
91 // ------------------------------------------------------------------------
92 virtual void get (const std::string&, THList&) override { NOSUPPORT_VOID(DEBUG, "Histogram retrieval"); }
93 virtual void getUnsummed(const std::string&,
94 std::map<std::string, std::vector<TObject*>>&) override { NOSUPPORT_VOID(DEBUG, "Histogram retrieval"); }
95 virtual void clear (const std::string&) override { NOSUPPORT_VOID(DEBUG, "Histogram clearing"); }
96 virtual void reset (const std::string&) override { NOSUPPORT_VOID(DEBUG, "Histogram reset"); }
97
98 virtual bool registerTObject (const std::string&, const std::string&, TObject*) override { NOSUPPORT(WARNING, "Histogram registration"); }
99 virtual bool discoverTObject (const std::string&, const std::string&, TObject*&) override { NOSUPPORT(WARNING, "Histogram discovery"); }
100 virtual bool releaseTObject (const std::string&, const std::string&) override { NOSUPPORT(WARNING, "Histogram release"); }
101 virtual void clearToRelease (const std::string&) override { NOSUPPORT_VOID(DEBUG, "Histogram release"); }
102
115 virtual mutex_type& getPublicationMutex() const override {
116 // We want to give non-const access through a const interface (IInfoRegister declares this const) --> need annotated local
117 mutex_type& mtx ATLAS_THREAD_SAFE = m_pubMutex;
118 return mtx;
119 }
120 virtual void setModification(bool b) override { p_setModification(b); }
121
122private:
124 struct Holder;
125
127 void publishingTask() const;
129 bool publishOne(Holder& h) const;
131 static nlohmann::json serializeContainer(hltinterface::GenericHLTContainer& cont);
133 std::vector<std::shared_ptr<Holder>> holders() const;
134
136 std::shared_ptr<hltinterface::ContainerFactory> m_factory;
137
139 std::unordered_map<std::string, std::shared_ptr<Holder>> m_objs;
140 mutable std::mutex m_objsMtx;
141
143 std::thread m_thread;
144 std::atomic<bool> m_stopFlag{false};
145
146 std::string m_partition;
147 std::string m_tdaqWebdaqBase;
149
151 mutable std::mutex m_pubMutex;
152
153 Gaudi::Property<std::string> m_isServerName{this, "ISServerName", "DF",
154 "Name of the IS server to publish to (used if TDAQ_IS_SERVER unset)"};
155 Gaudi::Property<unsigned int> m_intervalSeconds{this, "IntervalSeconds", 10,
156 "Period between publication cycles (s)"};
157};
158
159#endif // TRIGSERVICES_WEBDAQINFOSVC_H
#define NOSUPPORT(lvl, what)
Helper to mark unsupported interfaces.
#define NOSUPPORT_VOID(lvl, what)
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
Header file for AthHistogramAlgorithm.
Service that publishes IS objects via the webdaq REST API.
virtual ~WebdaqInfoSvc() noexcept override
virtual bool configure(const boost::property_tree::ptree &) override
virtual mutex_type & getPublicationMutex() const override
Producers are expected to hold m_pubMutex while mutating a registered container, and across the endEv...
virtual bool registerTObject(const std::string &, const std::string &, TObject *) override
virtual StatusCode configure() override
std::thread m_thread
Background publishing thread + stop flag.
virtual StatusCode finalize() override
std::mutex m_pubMutex
Publication mutex handed out by getPublicationMutex().
bool publishOne(Holder &h) const
Send the pre-built snapshot via webdaq::is::put.
virtual void clearToRelease(const std::string &) override
virtual std::vector< std::shared_ptr< hltinterface::GenericHLTContainer > > queryISRegistry(const std::string &) override
virtual void get(const std::string &, THList &) override
virtual bool prepareForRun(const boost::property_tree::ptree &) override
virtual StatusCode initialize ATLAS_NOT_THREAD_SAFE() override
virtual bool finalizeWorker(const boost::property_tree::ptree &) override
virtual bool beginEvent(const boost::property_tree::ptree &) override
virtual bool pullInfo(const std::string &, const std::string &) override
virtual bool endEvent(const boost::property_tree::ptree &) override
std::mutex m_objsMtx
virtual bool releaseTObject(const std::string &, const std::string &) override
virtual bool registerObject(const std::string publishPath, std::shared_ptr< hltinterface::GenericHLTContainer > obj) override
std::unordered_map< std::string, std::shared_ptr< Holder > > m_objs
Registered IS objects, keyed by full IS name (publishPath + object name).
virtual void getUnsummed(const std::string &, std::map< std::string, std::vector< TObject * > > &) override
std::atomic< bool > m_stopFlag
virtual bool releaseObject(const std::string fullName) override
De-register an object.
std::string m_tdaqIsServerName
virtual void handle(const Incident &incident) override
virtual void clear(const std::string &) override
virtual bool discoverTObject(const std::string &, const std::string &, TObject *&) override
virtual bool finalize(const boost::property_tree::ptree &) override
std::string m_tdaqWebdaqBase
void publishingTask() const
Background loop that periodically publishes containers.
virtual void setModification(bool b) override
std::string m_partition
std::shared_ptr< hltinterface::ContainerFactory > m_factory
Container factory.
virtual StatusCode stop() override
std::vector< std::shared_ptr< Holder > > holders() const
Copy of the registered holders, taken under m_objsMtx.
virtual void reset(const std::string &) override
Gaudi::Property< std::string > m_isServerName
static nlohmann::json serializeContainer(hltinterface::GenericHLTContainer &cont)
Serialise all supported fields into a JSON object.
virtual bool prepareWorker(const boost::property_tree::ptree &) override
Gaudi::Property< unsigned int > m_intervalSeconds
#define DEBUG
Definition page_access.h:11
void initialize()