Project
Loading...
Searching...
No Matches
o2::framework::ServiceRegistry Struct Reference

#include <ServiceRegistry.h>

Classes

struct  Index
 
struct  InstanceId
 
struct  Key
 
struct  Meta
 
struct  Salt
 
struct  SpecIndex
 

Public Types

enum struct  SpecialStreamId : short { Global = 0 , Callback = -1 , Invalid = -2 }
 
enum struct  SpecialDataProcessorId : short { Device = -1 , Invalid = -2 }
 
using hash_type = decltype(TypeIdHelpers::uniqueId< void >())
 

Public Member Functions

constexpr InstanceId instanceFromTypeSalt (ServiceTypeHash type, Salt salt) const
 
constexpr Index indexFromInstance (InstanceId id) const
 
void throwError (const char *name, int64_t hash, int64_t streamId, int64_t dataprocessorId) const
 To hide exception throwing from QC.
 
 ServiceRegistry ()
 
 ServiceRegistry (ServiceRegistry const &other)
 
ServiceRegistryoperator= (ServiceRegistry const &other)
 
void preExitCallbacks ()
 Invoke callbacks on exit.
 
void postRenderGUICallbacks ()
 
void declareService (ServiceSpec const &spec, DeviceState &state, fair::mq::ProgOptions &options, ServiceRegistry::Salt salt=ServiceRegistry::globalDeviceSalt())
 
void bindService (ServiceRegistry::Salt salt, ServiceSpec const &spec, void *service) const
 
void lateBindStreamServices (DeviceState &state, fair::mq::ProgOptions &options, ServiceRegistry::Salt salt)
 
void registerService (ServiceTypeHash typeHash, void *service, ServiceKind kind, Salt salt, char const *name=nullptr, ServiceRegistry::SpecIndex specIndex=SpecIndex{-1}) const
 
int getPos (ServiceTypeHash typeHash, Salt salt) const
 
voidget (ServiceTypeHash typeHash, Salt salt, ServiceKind kind, char const *name=nullptr) const
 
void registerService (ServiceHandle handle, Salt salt=ServiceRegistry::globalDeviceSalt())
 Register a service given an handle.
 
template<class I , class C , enum ServiceKind K = ServiceKind::Serial>
requires std::is_base_of_v<I, C>
void registerService (C *service, Salt salt=ServiceRegistry::globalDeviceSalt())
 
template<class I , class C , enum ServiceKind K = ServiceKind::Serial>
requires std::is_base_of_v<I, C>
void registerService (C const *service, Salt salt=ServiceRegistry::globalDeviceSalt())
 
template<typename T >
requires (std::is_const_v<T> == false)
bool active (Salt salt) const
 Check if service of type T is currently active.
 
template<typename T >
T & get (Salt salt) const
 
void postRenderGUICallbacks (ServiceRegistryRef ref)
 
void lock (Salt salt) const O2_DPL_ACQUIRE(mMutex)
 
void unlock (Salt salt) const O2_DPL_RELEASE(mMutex)
 

Static Public Member Functions

static constexpr int32_t valueFromSalt (Salt salt)
 
static constexpr uint64_t valueFromKey (Key key)
 
static Salt globalDeviceSalt ()
 
static Salt globalStreamSalt (short streamId)
 
static Salt dataProcessorSalt (short dataProcessorId)
 
static Salt streamSalt (short streamId, short dataProcessorId)
 

Public Attributes

std::vector< ServicePostRenderGUIHandlemPostRenderGUIHandles
 Callbacks to be executed after the main GUI has been drawn.
 
std::vector< ServiceSpecmSpecs
 
std::array< std::atomic< Key >, MAX_SERVICES+MAX_DISTANCEmServicesKey
 
std::array< void *, MAX_SERVICES+MAX_DISTANCEmServicesValue
 
std::array< Meta, MAX_SERVICES+MAX_DISTANCEmServicesMeta
 
std::array< std::atomic< bool >, MAX_SERVICES+MAX_DISTANCEmServicesBooked
 
std::recursive_mutex mMutex
 
int64_t mLastLock = -1
 
std::atomic< intlockCounter = {0}
 

Static Public Attributes

static constexpr Salt GLOBAL_CONTEXT_SALT {0, 0}
 
static constexpr int32_t MAX_DISTANCE = 8
 The maximum distance a entry can be from the optimal slot.
 
static constexpr uint32_t MAX_SERVICES = 256
 The number of slots in the hashmap.
 
static constexpr uint32_t MAX_SERVICES_MASK = MAX_SERVICES - 1
 The mask to use to calculate the initial slot id.
 

Detailed Description

Definition at line 78 of file ServiceRegistry.h.

Member Typedef Documentation

◆ hash_type

Member Enumeration Documentation

◆ SpecialDataProcessorId

Enumerator
Device 
Invalid 

Definition at line 90 of file ServiceRegistry.h.

◆ SpecialStreamId

Enumerator
Global 
Callback 
Invalid 

Definition at line 84 of file ServiceRegistry.h.

Constructor & Destructor Documentation

◆ ServiceRegistry() [1/2]

o2::framework::ServiceRegistry::ServiceRegistry ( )

Definition at line 52 of file ServiceRegistry.cxx.

◆ ServiceRegistry() [2/2]

o2::framework::ServiceRegistry::ServiceRegistry ( ServiceRegistry const &  other)

Definition at line 27 of file ServiceRegistry.cxx.

Member Function Documentation

◆ active()

template<typename T >
requires (std::is_const_v<T> == false)
bool o2::framework::ServiceRegistry::active ( Salt  salt) const
inline

Check if service of type T is currently active.

Definition at line 291 of file ServiceRegistry.h.

◆ bindService()

void o2::framework::ServiceRegistry::bindService ( ServiceRegistry::Salt  salt,
ServiceSpec const &  spec,
void service 
) const

Definition at line 272 of file ServiceRegistry.cxx.

◆ dataProcessorSalt()

static Salt o2::framework::ServiceRegistry::dataProcessorSalt ( short  dataProcessorId)
inlinestatic

A salt which is global to a specific data processor. This can be used to query properties which are not bonded to a specific stream, e.g. the name of the data processor, its inputs and outputs, it's algorithm.

Definition at line 161 of file ServiceRegistry.h.

◆ declareService()

void o2::framework::ServiceRegistry::declareService ( ServiceSpec const &  spec,
DeviceState state,
fair::mq::ProgOptions &  options,
ServiceRegistry::Salt  salt = ServiceRegistry::globalDeviceSalt() 
)

Declare a service by its ServiceSpec. If of type Global / Serial it will be immediately registered for tid 0, so that subsequent gets will ultimately use it. If it is of kind "Stream" we will create the Service only when requested by a given thread. This function is not thread safe. salt is used to create the service in the proper context FIXME: for now we create everything in the global context

Definition at line 106 of file ServiceRegistry.cxx.

◆ get() [1/2]

template<typename T >
T & o2::framework::ServiceRegistry::get ( Salt  salt) const
inline

Get a service for the given interface T. The returned reference exposed to the user is actually of the last concrete type C registered, however this should not be a problem.

Definition at line 305 of file ServiceRegistry.h.

◆ get() [2/2]

void * o2::framework::ServiceRegistry::get ( ServiceTypeHash  typeHash,
Salt  salt,
ServiceKind  kind,
char const *  name = nullptr 
) const

Definition at line 168 of file ServiceRegistry.cxx.

◆ getPos()

int o2::framework::ServiceRegistry::getPos ( ServiceTypeHash  typeHash,
Salt  salt 
) const

Definition at line 156 of file ServiceRegistry.cxx.

◆ globalDeviceSalt()

static Salt o2::framework::ServiceRegistry::globalDeviceSalt ( )
inlinestatic

A salt which is global to the whole device. This can be used to query services which are not bound to a specific stream or data processor, e.g. the services to send metrics to the driver or to send messages to the control.

Definition at line 144 of file ServiceRegistry.h.

◆ globalStreamSalt()

static Salt o2::framework::ServiceRegistry::globalStreamSalt ( short  streamId)
inlinestatic

A salt which is global to a given stream but which multiple dataprocessors can share.

Definition at line 151 of file ServiceRegistry.h.

◆ indexFromInstance()

constexpr Index o2::framework::ServiceRegistry::indexFromInstance ( InstanceId  id) const
inlineconstexpr

Definition at line 183 of file ServiceRegistry.h.

◆ instanceFromTypeSalt()

constexpr InstanceId o2::framework::ServiceRegistry::instanceFromTypeSalt ( ServiceTypeHash  type,
Salt  salt 
) const
inlineconstexpr

Definition at line 178 of file ServiceRegistry.h.

◆ lateBindStreamServices()

void o2::framework::ServiceRegistry::lateBindStreamServices ( DeviceState state,
fair::mq::ProgOptions &  options,
ServiceRegistry::Salt  salt 
)

Definition at line 128 of file ServiceRegistry.cxx.

◆ lock()

void o2::framework::ServiceRegistry::lock ( Salt  salt) const

Lock the service registry for a given salt. For the moment this is a global lock for anything but stream services.

Definition at line 302 of file ServiceRegistry.cxx.

◆ operator=()

ServiceRegistry & o2::framework::ServiceRegistry::operator= ( ServiceRegistry const &  other)

Definition at line 39 of file ServiceRegistry.cxx.

◆ postRenderGUICallbacks() [1/2]

void o2::framework::ServiceRegistry::postRenderGUICallbacks ( )

Invoke after rendering the GUI. Can be used to add custom GUI elements associated to a given service.

Definition at line 144 of file ServiceRegistry.cxx.

◆ postRenderGUICallbacks() [2/2]

void o2::framework::ServiceRegistry::postRenderGUICallbacks ( ServiceRegistryRef  ref)

Callback invoked by the driver after rendering. FIXME: Needs to stay here for the moment as it is used by the driver and not by one of the data processors.

Definition at line 265 of file ServiceRegistry.cxx.

◆ preExitCallbacks()

void o2::framework::ServiceRegistry::preExitCallbacks ( )

Invoke callbacks on exit.

◆ registerService() [1/4]

template<class I , class C , enum ServiceKind K = ServiceKind::Serial>
requires std::is_base_of_v<I, C>
void o2::framework::ServiceRegistry::registerService ( C *  service,
Salt  salt = ServiceRegistry::globalDeviceSalt() 
)
inline
Deprecated:
old API to be substituted with the ServiceHandle one

Definition at line 267 of file ServiceRegistry.h.

◆ registerService() [2/4]

template<class I , class C , enum ServiceKind K = ServiceKind::Serial>
requires std::is_base_of_v<I, C>
void o2::framework::ServiceRegistry::registerService ( C const *  service,
Salt  salt = ServiceRegistry::globalDeviceSalt() 
)
inline
Deprecated:
old API to be substituted with the ServiceHandle one

Definition at line 279 of file ServiceRegistry.h.

◆ registerService() [3/4]

void o2::framework::ServiceRegistry::registerService ( ServiceHandle  handle,
Salt  salt = ServiceRegistry::globalDeviceSalt() 
)
inline

Register a service given an handle.

Definition at line 250 of file ServiceRegistry.h.

◆ registerService() [4/4]

void o2::framework::ServiceRegistry::registerService ( ServiceTypeHash  typeHash,
void service,
ServiceKind  kind,
Salt  salt,
char const *  name = nullptr,
ServiceRegistry::SpecIndex  specIndex = SpecIndex{-1} 
) const

Type erased service registration. typeHash is the hash used to identify the service, service is a type erased pointer to the service itself. This method is supposed to be thread safe

Definition at line 68 of file ServiceRegistry.cxx.

◆ streamSalt()

static Salt o2::framework::ServiceRegistry::streamSalt ( short  streamId,
short  dataProcessorId 
)
inlinestatic

A salt which is specific to a given stream. This can be used to query properties which are of the stream itself, e.g. the currently processed time frame by a given stream.

Definition at line 171 of file ServiceRegistry.h.

◆ throwError()

void o2::framework::ServiceRegistry::throwError ( const char name,
int64_t  hash,
int64_t  streamId,
int64_t  dataprocessorId 
) const

To hide exception throwing from QC.

Definition at line 151 of file ServiceRegistry.cxx.

◆ unlock()

void o2::framework::ServiceRegistry::unlock ( Salt  salt) const

Unlock the service registry for a given salt. For the moment this is a global unlock for anything but stream services.

Definition at line 318 of file ServiceRegistry.cxx.

◆ valueFromKey()

static constexpr uint64_t o2::framework::ServiceRegistry::valueFromKey ( Key  key)
inlinestaticconstexpr

Definition at line 130 of file ServiceRegistry.h.

◆ valueFromSalt()

static constexpr int32_t o2::framework::ServiceRegistry::valueFromSalt ( Salt  salt)
inlinestaticconstexpr

Definition at line 129 of file ServiceRegistry.h.

Member Data Documentation

◆ GLOBAL_CONTEXT_SALT

constexpr Salt o2::framework::ServiceRegistry::GLOBAL_CONTEXT_SALT {0, 0}
staticconstexpr

Definition at line 95 of file ServiceRegistry.h.

◆ lockCounter

std::atomic<int> o2::framework::ServiceRegistry::lockCounter = {0}
mutable

Definition at line 262 of file ServiceRegistry.h.

◆ MAX_DISTANCE

constexpr int32_t o2::framework::ServiceRegistry::MAX_DISTANCE = 8
staticconstexpr

The maximum distance a entry can be from the optimal slot.

Definition at line 133 of file ServiceRegistry.h.

◆ MAX_SERVICES

constexpr uint32_t o2::framework::ServiceRegistry::MAX_SERVICES = 256
staticconstexpr

The number of slots in the hashmap.

Definition at line 135 of file ServiceRegistry.h.

◆ MAX_SERVICES_MASK

constexpr uint32_t o2::framework::ServiceRegistry::MAX_SERVICES_MASK = MAX_SERVICES - 1
staticconstexpr

The mask to use to calculate the initial slot id.

Definition at line 137 of file ServiceRegistry.h.

◆ mLastLock

int64_t o2::framework::ServiceRegistry::mLastLock = -1
mutable

Definition at line 261 of file ServiceRegistry.h.

◆ mMutex

std::recursive_mutex o2::framework::ServiceRegistry::mMutex
mutable

Definition at line 260 of file ServiceRegistry.h.

◆ mPostRenderGUIHandles

std::vector<ServicePostRenderGUIHandle> o2::framework::ServiceRegistry::mPostRenderGUIHandles
mutable

Callbacks to be executed after the main GUI has been drawn.

Definition at line 190 of file ServiceRegistry.h.

◆ mServicesBooked

std::array<std::atomic<bool>, MAX_SERVICES + MAX_DISTANCE> o2::framework::ServiceRegistry::mServicesBooked
mutable

Definition at line 259 of file ServiceRegistry.h.

◆ mServicesKey

std::array<std::atomic<Key>, MAX_SERVICES + MAX_DISTANCE> o2::framework::ServiceRegistry::mServicesKey
mutable

Definition at line 256 of file ServiceRegistry.h.

◆ mServicesMeta

std::array<Meta, MAX_SERVICES + MAX_DISTANCE> o2::framework::ServiceRegistry::mServicesMeta
mutable

Definition at line 258 of file ServiceRegistry.h.

◆ mServicesValue

std::array<void*, MAX_SERVICES + MAX_DISTANCE> o2::framework::ServiceRegistry::mServicesValue
mutable

Definition at line 257 of file ServiceRegistry.h.

◆ mSpecs

std::vector<ServiceSpec> o2::framework::ServiceRegistry::mSpecs
mutable

Definition at line 255 of file ServiceRegistry.h.


The documentation for this struct was generated from the following files: