The Gaudi Framework  master (37c0b60a)
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>
16 #include <GaudiKernel/StatusCode.h>
17 #include <any>
18 #include <mutex>
19 #include <string>
20 
22  namespace details {
25  public:
26  using ConditionContext = int;
28 
29  static ConditionsStore& instance();
30 
31  void declareKey( const ConditionKey& key );
32 
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 
46 
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 
127  StatusCode initialize() override {
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 
143  }
144 
145  private:
146  template <typename T>
147  friend class ConditionAccessor;
148 
150  template <typename T>
151  void registerConditionAccessor( ConditionAccessor<T>& accessor ) {
152  if ( this->targetFSMState() == Gaudi::StateMachine::INITIALIZED ) {
154  } else {
155  m_delayedRegistrations.push_back( [this, &accessor]() { registerConditionAccessor( accessor ); } );
156  }
157  }
158 
164  };
165 } // namespace Gaudi::TestSuite::Conditions
Gaudi::TestSuite::Conditions::details::ConditionsStore::instance
static ConditionsStore & instance()
Definition: Backend.cpp:15
std::string
STL class.
Gaudi::TestSuite::Conditions::details::ConditionsStore::ConditionKey
std::string ConditionKey
Definition: ConditionAccessorHolder.h:27
std::list
STL class.
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::ConditionAccessor
friend class ConditionAccessor
Definition: ConditionAccessorHolder.h:147
Gaudi::TestSuite::Conditions::details::ConditionsStore::getCondition
const T & getCondition(const ConditionKey &key, const ConditionContext &ctx) const
Definition: ConditionAccessorHolder.h:36
Gaudi::TestSuite::Conditions::details::ConditionsStore::getConditionContext
const ConditionContext & getConditionContext(const EventContext &ctx) const
Definition: Backend.cpp:26
std::function
StatusCode.h
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::ConditionAccessor::key
const ConditionKey & key() const
Helper to access the key of the current accessor.
Definition: ConditionAccessorHolder.h:115
std::list::clear
T clear(T... args)
std::list::push_back
T push_back(T... args)
Gaudi::TestSuite::Conditions::details::ConditionsStore::declareKey
void declareKey(const ConditionKey &key)
Definition: Backend.cpp:20
StateMachine.h
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::ConditionAccessor::get
const T & get(const ConditionContext &ctx) const
Get the condition value for the requested condition slot.
Definition: ConditionAccessorHolder.h:118
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
details
Definition: AnyDataWrapper.h:19
Gaudi::TestSuite::Conditions::details::ConditionsStore::m_requestedKeys
std::set< ConditionKey > m_requestedKeys
Definition: ConditionAccessorHolder.h:49
CommonMessaging
Definition: CommonMessaging.h:66
Gaudi::TestSuite::Conditions
Definition: ConditionAccessorHolder.h:21
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::ConditionAccessor::ConditionAccessor
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.
Definition: ConditionAccessorHolder.h:106
Gaudi::TestSuite::Conditions::details::ConditionsStore
Example class to implement an actual backend for Gaudi::TestSuite::Conditions::ConditionAccessorHolde...
Definition: ConditionAccessorHolder.h:24
std::map
STL class.
Gaudi::TestSuite::Conditions::details::ConditionsStore::ConditionContext
int ConditionContext
Definition: ConditionAccessorHolder.h:26
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::ConditionAccessor
Class wrapping the communication between condition users and conditions backend.
Definition: ConditionAccessorHolder.h:103
Gaudi::TestSuite::Conditions::details::ConditionsStore::m_storage
IOVSlots m_storage
Definition: ConditionAccessorHolder.h:48
Gaudi::TestSuite::Conditions::ConditionAccessorHolder
Example of a ConditionAccessorHolder implementation.
Definition: ConditionAccessorHolder.h:77
Gaudi::TestSuite::Conditions::details::ConditionsStore::ConditionsStore
ConditionsStore()=default
EventContext.h
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::getConditionContext
const ConditionContext & getConditionContext(const EventContext &ctx) const
Helper to map the event being processed to the corresponding conditions slot.
Definition: ConditionAccessorHolder.h:141
Gaudi::StateMachine::INITIALIZED
@ INITIALIZED
Definition: StateMachine.h:25
EventContext
Definition: EventContext.h:34
Gaudi::TestSuite::Conditions::ConditionAccessorHolder< Algorithm >::ConditionContext
details::ConditionsStore::ConditionContext ConditionContext
Forward backend specific ConditionContext to specializations.
Definition: ConditionAccessorHolder.h:89
std::mutex
STL class.
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::registerConditionAccessor
void registerConditionAccessor(ConditionAccessor< T > &accessor)
Register a ConditionAccessor instance to internal bookkeeping.
Definition: ConditionAccessorHolder.h:151
Gaudi::TestSuite::Conditions::details::ConditionsStore::m_storageMtx
std::mutex m_storageMtx
Definition: ConditionAccessorHolder.h:47
gaudirun.action
action
Definition: gaudirun.py:153
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::ConditionAccessor::m_key
Gaudi::Property< ConditionKey > m_key
Internal property object for the condition key.
Definition: ConditionAccessorHolder.h:124
ProduceConsume.key
key
Definition: ProduceConsume.py:84
std::set
STL class.
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:37
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::m_delayedRegistrations
std::list< std::function< void()> > m_delayedRegistrations
Helper to postpone the registration to the backend.
Definition: ConditionAccessorHolder.h:163
Gaudi::TestSuite::Conditions::details::ConditionsStore::getConditionAny
const std::any * getConditionAny(const ConditionKey &key, const ConditionContext &ctx) const
Definition: Backend.cpp:33
Property.h
Gaudi::TestSuite::Conditions::ConditionAccessorHolder::initialize
StatusCode initialize() override
Definition: ConditionAccessorHolder.h:127