-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customize concurrency for ESSource DataProxies
Refactored ESSource specific DataProxies to allow customizing how concurrency should be handled. Provided implementations to support either concurrent or non-concurrent running of DataProxies for the same ESSource.
- Loading branch information
Showing
14 changed files
with
597 additions
and
57 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
FWCore/Framework/interface/ESSourceConcurrentDataProxyTemplate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#ifndef FWCore_Framework_ESSourceConcurrentDataProxyTemplate_h | ||
#define FWCore_Framework_ESSourceConcurrentDataProxyTemplate_h | ||
// -*- C++ -*- | ||
// | ||
// Package: FWCore/Framework | ||
// Class : ESSourceConcurrentDataProxyTemplate | ||
// | ||
/**\class ESSourceConcurrentDataProxyTemplate ESSourceConcurrentDataProxyTemplate.h "FWCore/Framework/interface/ESSourceConcurrentDataProxyTemplate.h" | ||
Description: An ESSource specific DataProxy which is type safe and can run concurrently with other DataProxies from the same ESSource. | ||
Usage: | ||
Inherit from this class and override | ||
`void prefetch(edm::eventsetup::DataKey const& iKey)` | ||
and | ||
`DataT const* fetch() const` | ||
prefetch is guaranteed to be called before fetch where fetch should return the value obtained during the call to prefetch. | ||
The inheriting class must maintain the lifetime of the object returned from fetch until invalidateCache() is called. | ||
*/ | ||
// | ||
// Original Author: Chris Jones | ||
// Created: 17/12/2021 | ||
// | ||
|
||
// system include files | ||
|
||
// user include files | ||
#include "FWCore/Framework/interface/ESSourceDataProxyConcurrentBase.h" | ||
|
||
// forward declarations | ||
|
||
namespace edm::eventsetup { | ||
template <typename DataT> | ||
class ESSourceConcurrentDataProxyTemplate : public ESSourceDataProxyConcurrentBase { | ||
public: | ||
ESSourceConcurrentDataProxyTemplate() = default; | ||
|
||
ESSourceConcurrentDataProxyTemplate(const ESSourceConcurrentDataProxyTemplate&) = delete; | ||
const ESSourceConcurrentDataProxyTemplate& operator=(const ESSourceConcurrentDataProxyTemplate&) = delete; | ||
|
||
// ---------- const member functions --------------------- | ||
|
||
// ---------- static member functions -------------------- | ||
|
||
// ---------- member functions --------------------------- | ||
protected: | ||
/** Inheriting classes must also override | ||
void prefetch(edm::eventsetup::DataKey const& iKey, EventSetupRecordDetails) override; | ||
*/ | ||
|
||
/** returns the data obtained in the call to prefetch */ | ||
virtual DataT const* fetch() const = 0; | ||
|
||
private: | ||
void const* getAfterPrefetchImpl() const final { return fetch(); } | ||
}; | ||
} // namespace edm::eventsetup | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
FWCore/Framework/interface/ESSourceDataProxyConcurrentBase.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef FWCore_Framework_ESSourceDataProxyConcurrentBase_h | ||
#define FWCore_Framework_ESSourceDataProxyConcurrentBase_h | ||
// -*- C++ -*- | ||
// | ||
// Package: FWCore/Framework | ||
// Class : ESSourceDataProxyConcurrentBase | ||
// | ||
/**\class ESSourceDataProxyConcurrentBase ESSourceDataProxyConcurrentBase.h "FWCore/Framework/interface/ESSourceDataProxyConcurrentBase.h" | ||
Description: Base class for DataProxies for ESSources that require no synchronization | ||
Usage: | ||
The ESSourceDataProxyConcurrentBase allows DataProxies from the same ESSource to be called concurrently. | ||
NOTE: if inheriting classes override `void invalidateCache()` they must be sure to call this classes | ||
implementation as part of the call. | ||
*/ | ||
// | ||
// Original Author: Chris Jones | ||
// Created: 14/05/2020 | ||
// | ||
|
||
// system include files | ||
|
||
// user include files | ||
#include "FWCore/Framework/interface/ESSourceDataProxyBase.h" | ||
|
||
// forward declarations | ||
|
||
namespace edm::eventsetup { | ||
class ESSourceDataProxyConcurrentBase : public ESSourceDataProxyBase { | ||
public: | ||
ESSourceDataProxyConcurrentBase() {} | ||
|
||
private: | ||
void prefetchAsyncImpl(edm::WaitingTaskHolder iTask, | ||
edm::eventsetup::EventSetupRecordImpl const& iES, | ||
edm::eventsetup::DataKey const& iKey, | ||
edm::EventSetupImpl const*, | ||
edm::ServiceToken const&, | ||
edm::ESParentContext const&) final; | ||
|
||
// ---------- member data -------------------------------- | ||
}; | ||
} // namespace edm::eventsetup | ||
#endif |
58 changes: 58 additions & 0 deletions
58
FWCore/Framework/interface/ESSourceDataProxyNonConcurrentBase.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef FWCore_Framework_ESSourceDataProxyNonConcurrentBase_h | ||
#define FWCore_Framework_ESSourceDataProxyNonConcurrentBase_h | ||
// -*- C++ -*- | ||
// | ||
// Package: FWCore/Framework | ||
// Class : ESSourceDataProxyNonConcurrentBase | ||
// | ||
/**\class ESSourceDataProxyNonConcurrentBase ESSourceDataProxyNonConcurrentBase.h "FWCore/Framework/interface/ESSourceDataProxyNonConcurrentBase.h" | ||
Description: Base class for DataProxies for ESSources that require synchronization | ||
Usage: | ||
The ESSourceDataProxyNonConcurrentBase uses a SerialTaskQueue to serialize all DataProxies for the ESSource and a | ||
std::mutex to protect from concurrent calls to a DataProxy and the ESSource itself. Such concurrent calls | ||
can happen if concurrent LuminosityBlocks are being used. | ||
NOTE: if inheriting classes override `void invalidateCache()` they must be sure to call this classes | ||
implementation as part of the call. | ||
*/ | ||
// | ||
// Original Author: Chris Jones | ||
// Created: 14/05/2020 | ||
// | ||
|
||
// system include files | ||
#include <mutex> | ||
|
||
// user include files | ||
#include "FWCore/Framework/interface/ESSourceDataProxyBase.h" | ||
#include "FWCore/Concurrency/interface/SerialTaskQueue.h" | ||
|
||
// forward declarations | ||
|
||
namespace edm::eventsetup { | ||
class ESSourceDataProxyNonConcurrentBase : public ESSourceDataProxyBase { | ||
public: | ||
ESSourceDataProxyNonConcurrentBase(edm::SerialTaskQueue* iQueue, std::mutex* iMutex) | ||
: m_queue(iQueue), m_mutex(iMutex) {} | ||
|
||
edm::SerialTaskQueue* queue() const { return m_queue; } | ||
std::mutex* mutex() const { return m_mutex; } | ||
|
||
private: | ||
void prefetchAsyncImpl(edm::WaitingTaskHolder iTask, | ||
edm::eventsetup::EventSetupRecordImpl const& iES, | ||
edm::eventsetup::DataKey const& iKey, | ||
edm::EventSetupImpl const*, | ||
edm::ServiceToken const&, | ||
edm::ESParentContext const&) final; | ||
|
||
// ---------- member data -------------------------------- | ||
|
||
edm::SerialTaskQueue* m_queue; | ||
std::mutex* m_mutex; | ||
}; | ||
} // namespace edm::eventsetup | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// -*- C++ -*- | ||
// | ||
// Package: FWCore/Framework | ||
// Class : __class__ | ||
// | ||
// Implementation: | ||
// [Notes on implementation] | ||
// | ||
// Original Author: __author__ | ||
// Created: __date__ | ||
// | ||
|
||
// system include files | ||
|
||
// user include files | ||
#include "FWCore/Framework/interface/ESSourceDataProxyConcurrentBase.h" | ||
|
||
// | ||
// member functions | ||
// | ||
|
||
void edm::eventsetup::ESSourceDataProxyConcurrentBase::prefetchAsyncImpl( | ||
edm::WaitingTaskHolder iTask, | ||
edm::eventsetup::EventSetupRecordImpl const& iRecord, | ||
edm::eventsetup::DataKey const& iKey, | ||
edm::EventSetupImpl const*, | ||
edm::ServiceToken const&, | ||
edm::ESParentContext const& iParent) { | ||
prefetchAsyncImplTemplate([](auto& iGroup, auto iActivity) { iGroup.run(std::move(iActivity)); }, | ||
[]() { return true; }, | ||
std::move(iTask), | ||
iRecord, | ||
iKey, | ||
iParent); | ||
} |
Oops, something went wrong.