7 #include <GaudiKernel/ConcurrencyFlags.h>
10 #include <boost/core/demangle.hpp>
14 #include <range/v3/algorithm.hpp>
15 #include <range/v3/numeric/accumulate.hpp>
16 #include <range/v3/to_container.hpp>
17 #include <range/v3/view.hpp>
33 m_bkg_evt_sel_ctx(nullptr),
34 m_proxyProviderSvc(
"ProxyProviderSvc/BkgPPSvc_"+
name,
name),
53 ATH_MSG_ERROR(
"Failed to create background event selector context");
54 return StatusCode::FAILURE;
63 if (!addressProvider) {
65 "Could not cast background event selector to IAddressProvider");
70 SmartIF<IAddressProvider> athPoolAP{
71 serviceLocator()->service(
std::format(
"AthenaPoolAddressProviderSvc/BkgAPAPSvc_{}",
name()))
75 "Could not cast AthenaPoolAddressProviderSvc to IAddressProvider");
80 SmartIF<IAddressProvider> addRemapAP{
81 serviceLocator()->service(
std::format(
"AddressRemappingSvc/BkgARSvc_{}",
name()))
84 ATH_MSG_WARNING(
"Could not cast AddressRemappingSvc to IAddressProvider");
89 const std::size_t n_concurrent =
90 Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents();
100 const int n_stores = 50;
102 for (std::size_t
i = 0;
i < n_concurrent; ++
i) {
104 sgs.reserve(n_stores);
105 for (
int j = 0; j < n_stores; ++j) {
107 auto& sg = sgs.emplace_back(
119 auto skipEvent_callback = [
this](
122 using namespace std::chrono_literals;
131 << n_to_skip <<
" pileup events");
132 for (std::size_t
i = 0;
i < n_to_skip; ++
i) {
135 return StatusCode::FAILURE;
141 return StatusCode::SUCCESS;
145 return StatusCode::SUCCESS;
154 <<
"| hs_id " << hs_id);
157 std::vector<std::uint64_t> stack_num_mb_by_bunch{};
158 std::vector<std::uint64_t>& num_mb_by_bunch =
160 num_mb_by_bunch.clear();
161 num_mb_by_bunch.resize(n_bunches);
165 bool sf_updated_throwaway;
166 const float beam_lumi_sf =
169 const float beam_lumi = beam_lumi_sf *
m_nPerBunch.value();
170 std::vector<float> avg_num_mb_by_bunch(n_bunches, beam_lumi);
179 avg_num_mb_by_bunch[
idx] *=
m_beamInt->normFactor(bunch);
184 std::transform(avg_num_mb_by_bunch.begin(), avg_num_mb_by_bunch.end(),
185 num_mb_by_bunch.begin(), [&prng](
float avg) {
186 return std::poisson_distribution<std::uint64_t>(avg)(prng);
189 std::transform(avg_num_mb_by_bunch.begin(), avg_num_mb_by_bunch.end(),
190 num_mb_by_bunch.begin(), [](
float f) {
191 return static_cast<std::uint64_t>(std::round(f));
201 std::vector<std::uint64_t>& index_array =
m_idx_lists[slot];
203 index_array.resize(num_mb);
204 std::iota(index_array.begin(), index_array.end(), 0);
216 using namespace std::chrono_literals;
217 std::chrono::steady_clock::time_point order_wait_start{};
219 const std::int64_t hs_id =
get_hs_id(ctx);
220 const std::size_t slot = ctx.slot();
221 const std::size_t num_to_load =
223 ctx.eventID().lumi_block(), ctx.eventID().event_number());
226 if (stores.size() < num_to_load) {
227 ATH_MSG_INFO(
"Adding " << num_to_load - stores.size() <<
" stores");
228 stores.reserve(num_to_load);
229 for (std::size_t
i = stores.size();
i < num_to_load; ++
i) {
230 auto& sg = stores.emplace_back(
240 ATH_MSG_INFO(
"Waiting to prevent out-of-order loading. Last loaded is "
244 std::this_thread::sleep_for(50
ms);
255 for (std::size_t
i = 0;
i < num_to_load; ++
i) {
256 auto& sg = stores[
i];
264 return StatusCode::FAILURE;
266 IOpaqueAddress* addr =
nullptr;
270 return StatusCode::FAILURE;
272 if (addr ==
nullptr) {
274 return StatusCode::FAILURE;
280 for (
const auto* proxy_ptr : sg->proxies()) {
282 sg->proxy_exact(proxy_ptr->sgkey())->accessData();
292 return StatusCode::SUCCESS;
297 const std::size_t slot = ctx.slot();
306 "Tried to request bunch {} which is outside the range [{}, {}]", bunch,
314 for (
auto&& sg :
m_stores[ctx.slot()]) {
317 return StatusCode::SUCCESS;