The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
ConditionAccessorHolder.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
13#include <Gaudi/Property.h>
17#include <any>
18#include <mutex>
19#include <string>
20
22 namespace details {
25 public:
26 using ConditionContext = int;
27 using ConditionKey = std::string;
28
29 static ConditionsStore& instance();
30
31 void declareKey( const ConditionKey& key );
32
33 const ConditionContext& getConditionContext( const EventContext& ctx ) const;
34
35 template <typename T>
36 const T& getCondition( const ConditionKey& key, const ConditionContext& ctx ) const {
37 return *std::any_cast<T>( getConditionAny( key, ctx ) );
38 }
39
40 private:
41 ConditionsStore() = default;
42 const std::any* getConditionAny( const ConditionKey& key, const ConditionContext& ctx ) const;
43
44 using IOVSlot = std::map<ConditionKey, std::any>;
45 using IOVSlots = std::map<ConditionContext, IOVSlot>;
46
47 mutable std::mutex m_storageMtx;
49 std::set<ConditionKey> m_requestedKeys;
50 };
51 } // namespace details
52
76 template <typename Base>
77 class ConditionAccessorHolder : public Base {
78 public:
80 using Base::Base;
81
85
90
95
102 template <typename T>
104 public:
106 ConditionAccessor( base_class* owner, const std::string& keyName, const ConditionKey& keyDefault,
107 const std::string& keyDoc = "" )
108 : m_key{ owner, keyName, keyDefault, keyDoc } {
109 owner->registerConditionAccessor( *this );
110 }
111
115 const ConditionKey& key() const { return m_key; }
116
118 const T& get( const ConditionContext& ctx ) const {
120 }
121
122 private:
125 };
126
128 auto sc = Base::initialize();
129 if ( !sc ) return sc;
130
131 // backend-specific initialization
132
133 // trigger delayed registrations
134 for ( auto& action : m_delayedRegistrations ) { action(); }
136
137 return sc;
138 }
139
144
145 private:
146 template <typename T>
147 friend class ConditionAccessor;
148
150 template <typename T>
152 if ( this->targetFSMState() == Gaudi::StateMachine::INITIALIZED ) {
154 } else {
155 m_delayedRegistrations.push_back( [this, &accessor]() { registerConditionAccessor( accessor ); } );
156 }
157 }
158
163 std::list<std::function<void()>> m_delayedRegistrations;
164 };
165} // namespace Gaudi::TestSuite::Conditions
This class represents an entry point to all the event specific data.
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
Class wrapping the communication between condition users and conditions backend.
const T & get(const ConditionContext &ctx) const
Get the condition value for the requested condition slot.
const ConditionKey & key() const
Helper to access the key of the current accessor.
ConditionAccessor(base_class *owner, const std::string &keyName, const ConditionKey &keyDefault, const std::string &keyDoc="")
Constructor a ConditionAccessor instance registering it to the current holder.
Gaudi::Property< ConditionKey > m_key
Internal property object for the condition key.
Example of a ConditionAccessorHolder implementation.
details::ConditionsStore::ConditionContext ConditionContext
Forward backend specific ConditionContext to specializations.
ConditionAccessorHolder< Base > base_class
Helper to expose this class to specializations without having to spell the whole name (see Gaudi::Tes...
void registerConditionAccessor(ConditionAccessor< T > &accessor)
Register a ConditionAccessor instance to internal bookkeeping.
const ConditionContext & getConditionContext(const EventContext &ctx) const
Helper to map the event being processed to the corresponding conditions slot.
std::list< std::function< void()> > m_delayedRegistrations
Helper to postpone the registration to the backend.
details::ConditionsStore::ConditionKey ConditionKey
Forward backend specific ConditionKey to specializations.
const ConditionContext & getConditionContext(const EventContext &ctx) const
Definition Backend.cpp:26
const T & getCondition(const ConditionKey &key, const ConditionContext &ctx) const
const std::any * getConditionAny(const ConditionKey &key, const ConditionContext &ctx) const
Definition Backend.cpp:33
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64