![Logo](../../ATLAS-Logo-Square-Blue-RGB.png) |
ATLAS Offline Software
|
Go to the documentation of this file.
7 #include <GaudiKernel/ConcurrencyFlags.h>
8 #include <fmt/chrono.h>
9 #include <fmt/format.h>
12 #include <boost/core/demangle.hpp>
15 #include <range/v3/algorithm.hpp>
16 #include <range/v3/numeric/accumulate.hpp>
17 #include <range/v3/to_container.hpp>
18 #include <range/v3/view.hpp>
25 #include "EventInfo/EventInfo.h"
29 namespace rv = ranges::views;
37 : base_class(
name,
svc), m_bkg_evt_sel_ctx(nullptr), m_last_loaded_hs() {}
54 ATH_MSG_ERROR(
"Failed to create background event selector context");
55 return StatusCode::FAILURE;
65 auto* addressProvider =
67 if (addressProvider ==
nullptr) {
69 "Could not cast background event selector to IAddressProvider");
74 IService* athPoolSvc =
nullptr;
79 if (athPoolAP ==
nullptr) {
81 "Could not cast AthenaPoolAddressProviderSvc to IAddressProvider");
86 IService* addRemapSvc =
nullptr;
90 if (addRemapAP ==
nullptr) {
91 ATH_MSG_WARNING(
"Could not cast AddressRemappingSvc to IAddressProvider");
96 const std::size_t n_concurrent =
97 Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents();
107 const int n_stores = 50;
109 for (std::size_t
i = 0;
i < n_concurrent; ++
i) {
111 sgs.reserve(n_stores);
112 for (
int j = 0; j < n_stores; ++j) {
114 auto& sg = sgs.emplace_back(
126 auto skipEvent_callback = [
this](
129 using namespace std::chrono_literals;
133 for (
auto iter =
begin; iter <
end; ++iter) {
134 const auto&
evt = *iter;
138 << n_to_skip <<
" pileup events");
139 for (std::size_t
i = 0;
i < n_to_skip; ++
i) {
142 return StatusCode::FAILURE;
148 return StatusCode::SUCCESS;
152 return StatusCode::SUCCESS;
161 <<
"| hs_id " << hs_id);
164 std::vector<std::uint64_t> stack_num_mb_by_bunch{};
165 std::vector<std::uint64_t>& num_mb_by_bunch =
167 num_mb_by_bunch.clear();
168 num_mb_by_bunch.resize(n_bunches);
172 bool sf_updated_throwaway;
173 const float beam_lumi_sf =
176 const float beam_lumi = beam_lumi_sf *
m_nPerBunch.value();
177 std::vector<float> avg_num_mb_by_bunch(n_bunches, beam_lumi);
186 avg_num_mb_by_bunch[
idx] *=
m_beamInt->normFactor(bunch);
191 std::transform(avg_num_mb_by_bunch.begin(), avg_num_mb_by_bunch.end(),
192 num_mb_by_bunch.begin(), [&prng](
float avg) {
193 return std::poisson_distribution<std::uint64_t>(avg)(prng);
196 std::transform(avg_num_mb_by_bunch.begin(), avg_num_mb_by_bunch.end(),
197 num_mb_by_bunch.begin(), [](
float f) {
198 return static_cast<std::uint64_t>(std::round(f));
208 std::vector<std::uint64_t>& index_array =
m_idx_lists[slot];
210 index_array.resize(num_mb);
211 std::iota(index_array.begin(), index_array.end(), 0);
214 ATH_MSG_DEBUG(
"HS ID " << hs_id <<
" uses " << num_mb <<
" events\n"
221 using namespace std::chrono_literals;
222 std::chrono::steady_clock::time_point order_wait_start{};
224 const std::int64_t hs_id =
get_hs_id(ctx);
225 const std::size_t slot = ctx.slot();
226 const std::size_t num_to_load =
228 ctx.eventID().lumi_block(), ctx.eventID().event_number());
231 if (stores.size() < num_to_load) {
232 ATH_MSG_INFO(
"Adding " << num_to_load - stores.size() <<
" stores");
233 stores.reserve(num_to_load);
234 for (std::size_t
i = stores.size();
i < num_to_load; ++
i) {
235 auto& sg = stores.emplace_back(
245 ATH_MSG_INFO(
"Waiting to prevent out-of-order loading. Last loaded is "
249 std::this_thread::sleep_for(50
ms);
260 for (std::size_t
i = 0;
i < num_to_load; ++
i) {
261 auto& sg = stores[
i];
269 return StatusCode::FAILURE;
271 IOpaqueAddress* addr =
nullptr;
275 return StatusCode::FAILURE;
277 if (addr ==
nullptr) {
279 return StatusCode::FAILURE;
284 for (
const auto* proxy_ptr : sg->proxies()) {
287 sg->proxy_exact(proxy_ptr->sgkey())->accessData();
297 return StatusCode::SUCCESS;
302 const std::size_t slot = ctx.slot();
311 "Tried to request bunch {} which is outside the range [{}, {}]", bunch,
319 for (
auto&& sg :
m_stores[ctx.slot()]) {
322 return StatusCode::SUCCESS;
ServiceHandle< IBeamLuminosity > m_beamLumi
std::string CLIDToString(const CLID &clid)
Gaudi::Property< bool > m_useBeamInt
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
std::vector< std::vector< std::uint64_t > > m_num_mb_by_bunch
OnDemandMinbiasSvc(const std::string &name, ISvcLocator *svc)
Constructor.
Temporarily change the current store.
static const std::type_info * CLIDToTypeinfo(CLID clid)
Translate between CLID and type_info.
ServiceHandle< ISkipEventIdxSvc > m_skipEventIdxSvc
std::size_t calcMBRequired(std::int64_t hs_id, std::size_t slot, unsigned int run, unsigned int lumi, std::uint64_t event)
ServiceHandle< IEvtSelector > m_bkgEventSelector
std::vector< std::vector< std::uint64_t > > m_idx_lists
Gaudi::Property< bool > m_usePoisson
IProxyProviderSvc * m_proxyProviderSvc
~OnDemandMinbiasSvc() final
Destructor.
The Athena Transient Store API.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
virtual void addProvider(IAddressProvider *aProvider)=0
IAddressProvider manager functionality add a provider to the set of known ones.
virtual std::int64_t get_hs_id(const EventContext &ctx) const override
StoreGateSvc * getMinbias(const EventContext &ctx, std::uint64_t mb_id) override
POOL::TEvent event(POOL::TEvent::kClassAccess)
std::atomic_int64_t m_last_loaded_hs
std::vector< EvtId >::const_iterator EvtIter
Gaudi::Property< bool > m_onDemandMB
::StatusCode StatusCode
StatusCode definition for legacy code.
Gaudi::Property< bool > m_useBeamLumi
static constexpr std::size_t s_NoSlot
interface for IOA providers
StatusCode beginHardScatter(const EventContext &ctx) override
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
std::vector< std::vector< SGHandle > > m_stores
AthROOTErrorHandlerSvc * svc
uint32_t CLID
The Class ID type.
IEvtSelector::Context * m_bkg_evt_sel_ctx
StatusCode initialize() final
AthService initialize.
std::string join(const std::vector< std::string > &v, const char c=',')
Gaudi::Property< float > m_nPerBunch
Gaudi::Property< int > m_latestDeltaBC
StatusCode endHardScatter(const EventContext &ctx) override
ServiceHandle< IBeamIntensity > m_beamInt
#define ATH_MSG_WARNING(x)
std::size_t getNumForBunch(const EventContext &ctx, int bunch) const override
std::mutex m_reading_batch_mtx
Gaudi::Property< int > m_earliestDeltaBC
ServiceHandle< ActiveStoreSvc > m_activeStoreSvc
Gaudi::Property< std::uint64_t > m_seed