 |
ATLAS Offline Software
|
#include <BatchedMinbiasSvc.h>
Definition at line 28 of file BatchedMinbiasSvc.h.
◆ SGHandle
◆ SGHandleArray
◆ BatchedMinbiasSvc()
BatchedMinbiasSvc::BatchedMinbiasSvc |
( |
const std::string & |
name, |
|
|
ISvcLocator * |
svc |
|
) |
| |
◆ ~BatchedMinbiasSvc()
BatchedMinbiasSvc::~BatchedMinbiasSvc |
( |
| ) |
|
◆ beginHardScatter()
StatusCode BatchedMinbiasSvc::beginHardScatter |
( |
const EventContext & |
ctx | ) |
|
|
override |
Definition at line 286 of file BatchedMinbiasSvc.cxx.
287 using namespace std::chrono_literals;
288 bool first_wait =
true;
289 std::chrono::steady_clock::time_point cache_wait_start{};
290 std::chrono::steady_clock::time_point order_wait_start{};
291 const std::int64_t hs_id =
get_hs_id(ctx);
294 ctx.eventID().run_number(),
295 ctx.eventID().lumi_block(),
296 ctx.eventID().event_number());
303 return StatusCode::SUCCESS;
307 ATH_MSG_INFO(
"Waiting to prevent out-of-order loading of batches");
310 std::this_thread::sleep_for(50
ms);
314 "Waited {:%M:%S} to prevent out-of-order loading", wait_time));
320 if (empty_caches_lock.owns_lock()) {
323 empty_caches_lock.unlock();
330 std::this_thread::sleep_for(100
ms);
336 std::format(
"Waited {:%M:%S} for a free cache", wait_time));
340 ATH_MSG_INFO(
"Reading next batch in event " << ctx.evt() <<
", slot "
341 << ctx.slot() <<
" (hs_id "
357 return StatusCode::FAILURE;
359 IOpaqueAddress* addr =
nullptr;
363 return StatusCode::FAILURE;
365 if (addr ==
nullptr) {
367 return StatusCode::FAILURE;
373 for (
const auto* proxy_ptr : sg->proxies()) {
374 if (!proxy_ptr->isValid()) {
379 sg->proxy_exact(proxy_ptr->sgkey())->accessData();
391 return StatusCode::SUCCESS;
394 return StatusCode::SUCCESS;
◆ calcMBRequired()
std::size_t BatchedMinbiasSvc::calcMBRequired |
( |
std::int64_t |
hs_id, |
|
|
std::size_t |
slot, |
|
|
unsigned int |
run, |
|
|
unsigned int |
lumi, |
|
|
std::uint64_t |
event |
|
) |
| |
|
private |
Definition at line 195 of file BatchedMinbiasSvc.cxx.
204 bool sf_updated_throwaway;
205 const float beam_lumi_sf =
208 std::vector<float> avg_num_mb_by_bunch(n_bunches,
218 avg_num_mb_by_bunch[
idx] *=
m_beamInt->normFactor(bunch);
223 num_mb_by_bunch.clear();
224 num_mb_by_bunch.resize(n_bunches);
227 std::transform(avg_num_mb_by_bunch.begin(), avg_num_mb_by_bunch.end(),
228 num_mb_by_bunch.begin(), [&prng](
float avg) {
229 return std::poisson_distribution<std::uint64_t>(avg)(prng);
232 std::transform(avg_num_mb_by_bunch.begin(), avg_num_mb_by_bunch.end(),
233 num_mb_by_bunch.begin(), [](
float f) {
234 return static_cast<std::uint64_t>(std::round(f));
239 std::vector<std::uint64_t>& index_array =
m_idx_lists[slot];
242 if (num_mb > mbBatchSize) {
245 rv::iota(0ULL, num_mb_by_bunch.size()) |
247 bool good =
idx != center_bunch;
249 good && num_mb_by_bunch[
idx] > 0;
252 ranges::to<std::vector>;
255 [center_bunch](std::size_t
idx) {
256 return std::size_t(std::abs(
int(
idx) - center_bunch));
263 num_mb_by_bunch[
idx] -= num_subtracted;
264 num_mb -= num_subtracted;
265 if (num_mb <= mbBatchSize) {
270 ATH_MSG_ERROR(
"We need " << num_mb <<
" events but the batch size is "
271 << mbBatchSize <<
". Restricting to "
272 << mbBatchSize <<
" events!");
274 index_array = rv::ints(0,
int(mbBatchSize)) |
rv::sample(num_mb, prng) |
275 ranges::to<std::vector<std::uint64_t>>;
276 ranges::shuffle(index_array, prng);
277 ATH_MSG_DEBUG(
"HS ID " << hs_id <<
" uses " << num_mb <<
" events");
◆ endHardScatter()
StatusCode BatchedMinbiasSvc::endHardScatter |
( |
const EventContext & |
ctx | ) |
|
|
override |
Definition at line 416 of file BatchedMinbiasSvc.cxx.
417 using namespace std::chrono_literals;
418 const std::int64_t hs_id =
get_hs_id(ctx);
427 for (
auto&& sg : *temp) {
437 return StatusCode::SUCCESS;
◆ event_to_batch()
int BatchedMinbiasSvc::event_to_batch |
( |
std::int64_t |
hs_id | ) |
|
|
private |
◆ get_hs_id()
virtual std::int64_t BatchedMinbiasSvc::get_hs_id |
( |
const EventContext & |
ctx | ) |
const |
|
inlineoverridevirtual |
◆ getMinbias()
StoreGateSvc * BatchedMinbiasSvc::getMinbias |
( |
const EventContext & |
ctx, |
|
|
std::uint64_t |
mb_id |
|
) |
| |
|
override |
◆ getNumForBunch()
std::size_t BatchedMinbiasSvc::getNumForBunch |
( |
const EventContext & |
ctx, |
|
|
int |
bunch |
|
) |
| const |
|
override |
Definition at line 406 of file BatchedMinbiasSvc.cxx.
410 "Tried to request bunch {} which is outside the range [{}, {}]", bunch,
◆ initialize()
StatusCode BatchedMinbiasSvc::initialize |
( |
| ) |
|
|
override |
AthService initialize.
Definition at line 43 of file BatchedMinbiasSvc.cxx.
47 std::size_t n_concurrent =
48 Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents();
66 ATH_MSG_ERROR(
"Failed to create background event selector context");
67 return StatusCode::FAILURE;
72 SmartIF<IProxyProviderSvc> proxyProviderSvc{
73 serviceLocator()->service(
std::format(
"ProxyProviderSvc/BkgPPSvc_{}",
name()))
79 if (!addressProvider) {
81 "Could not cast background event selector to IAddressProvider");
83 proxyProviderSvc->addProvider(addressProvider);
86 SmartIF<IAddressProvider> athPoolAP{
87 serviceLocator()->service(
std::format(
"AthenaPoolAddressProviderSvc/BkgAPAPSvc_{}",
name()))
91 "Could not cast AthenaPoolAddressProviderSvc to IAddressProvider");
93 proxyProviderSvc->addProvider(athPoolAP);
96 SmartIF<IAddressProvider> addRemapAP{
97 serviceLocator()->service(
std::format(
"AddressRemappingSvc/BkgARSvc_{}",
name()))
100 ATH_MSG_WARNING(
"Could not cast AddressRemappingSvc to IAddressProvider");
102 proxyProviderSvc->addProvider(addRemapAP);
109 auto& sgs =
m_empty_caches.emplace_back(std::make_unique<SGHandleArray>());
110 sgs->reserve(mbBatchSize);
111 for (
int j = 0; j < mbBatchSize; ++j) {
113 auto& sg = sgs->emplace_back(
117 sg->setProxyProviderSvc(proxyProviderSvc);
127 auto skipEvent_callback = [
this, mbBatchSize](
130 using namespace std::chrono_literals;
131 auto evts = ranges::make_subrange(
begin,
end);
137 std::vector<std::tuple<int, int>> batches_with_counts{};
139 for (
int batch : batches_all) {
141 if (batches_with_counts.empty()) {
142 batches_with_counts.emplace_back(
batch, 1);
146 auto& last_entry = batches_with_counts.back();
147 if (
batch == std::get<0>(last_entry)) {
148 std::get<1>(last_entry) += 1;
151 batches_with_counts.emplace_back(
batch, 1);
159 for (
const auto& [
batch,
count] : batches_with_counts) {
167 std::this_thread::sleep_for(50
ms);
180 return StatusCode::FAILURE;
187 return StatusCode::SUCCESS;
192 return StatusCode::SUCCESS;
◆ m_activeStoreSvc
Initial value:{
this, "ActiveStoreSvc", "ActiveStoreSvc", "ActiveStoreSvc"}
Definition at line 97 of file BatchedMinbiasSvc.h.
◆ m_actualNHSEventsPerBatch
Gaudi::Property<std::vector<int> > BatchedMinbiasSvc::m_actualNHSEventsPerBatch |
|
private |
Initial value:{
this,
"actualNHSEventsPerBatch",
{},
"Dynamic map of actual number of HS events for each batch, in this run."}
Definition at line 83 of file BatchedMinbiasSvc.h.
◆ m_batch_use_count
std::vector<std::unique_ptr<std::atomic_int> > BatchedMinbiasSvc::m_batch_use_count |
|
private |
◆ m_beamInt
Initial value:{this, "BeamIntSvc", "FlatBM",
"Beam intensity service"}
Definition at line 93 of file BatchedMinbiasSvc.h.
◆ m_beamLumi
Initial value:{
this, "BeamLumiSvc", "LumiProfileSvc", "Beam luminosity service"}
Definition at line 95 of file BatchedMinbiasSvc.h.
◆ m_bkg_evt_sel_ctx
IEvtSelector::Context* BatchedMinbiasSvc::m_bkg_evt_sel_ctx |
|
private |
◆ m_bkgEventSelector
ServiceHandle<IEvtSelector> BatchedMinbiasSvc::m_bkgEventSelector |
|
private |
Initial value:{
this, "BkgEventSelector", {}, "Event selector for minbias events"}
Definition at line 91 of file BatchedMinbiasSvc.h.
◆ m_cache
std::map<int, std::unique_ptr<SGHandleArray> > BatchedMinbiasSvc::m_cache |
|
private |
◆ m_cache_mtxs
std::map<int, std::mutex> BatchedMinbiasSvc::m_cache_mtxs |
|
private |
◆ m_earliestDeltaBC
Gaudi::Property<int> BatchedMinbiasSvc::m_earliestDeltaBC |
|
private |
Initial value:{
this, "EarliestDeltaBC", -32,
"Earliest bunch crossing to consider (as delta)"}
Definition at line 77 of file BatchedMinbiasSvc.h.
◆ m_empty_caches
std::deque<std::unique_ptr<SGHandleArray> > BatchedMinbiasSvc::m_empty_caches |
|
private |
◆ m_empty_caches_mtx
std::mutex BatchedMinbiasSvc::m_empty_caches_mtx |
|
private |
◆ m_HSBatchSize
Gaudi::Property<int> BatchedMinbiasSvc::m_HSBatchSize |
|
private |
Initial value:{
this, "HSBatchSize", 1,
"Number of HS events per batch (aka max reuse factor)"}
Definition at line 69 of file BatchedMinbiasSvc.h.
◆ m_idx_lists
std::vector<std::vector<std::uint64_t> > BatchedMinbiasSvc::m_idx_lists |
|
private |
◆ m_last_loaded_batch
std::atomic_int BatchedMinbiasSvc::m_last_loaded_batch |
|
private |
◆ m_latestDeltaBC
Gaudi::Property<int> BatchedMinbiasSvc::m_latestDeltaBC |
|
private |
Initial value:{
this, "LatestDeltaBC", +6,
"Latest bunch crossing to consider (as delta)"}
Definition at line 80 of file BatchedMinbiasSvc.h.
◆ m_MBBatchSize
Gaudi::Property<int> BatchedMinbiasSvc::m_MBBatchSize |
|
private |
Initial value:{
this, "MBBatchSize", 10000,
"Number of low pT minbias events to load per batch"}
Definition at line 63 of file BatchedMinbiasSvc.h.
◆ m_nPerBunch
Gaudi::Property<float> BatchedMinbiasSvc::m_nPerBunch |
|
private |
Initial value:{
this, "AvgMBPerBunch", 0,
"Average (max) number of minbias events per bunch"}
Definition at line 74 of file BatchedMinbiasSvc.h.
◆ m_NSimultaneousBatches
Gaudi::Property<int> BatchedMinbiasSvc::m_NSimultaneousBatches |
|
private |
Initial value:{
this, "NSimultaneousBatches", 1,
"Max number of batches to load simultaneously"}
Definition at line 66 of file BatchedMinbiasSvc.h.
◆ m_num_mb_by_bunch
std::vector<std::vector<std::uint64_t> > BatchedMinbiasSvc::m_num_mb_by_bunch |
|
private |
◆ m_onDemandMB
Gaudi::Property<bool> BatchedMinbiasSvc::m_onDemandMB |
|
private |
Initial value:{
this, "OnDemandMB", false,
"Should minbias event contents be read on demand"}
Definition at line 53 of file BatchedMinbiasSvc.h.
◆ m_reading_batch_mtx
std::mutex BatchedMinbiasSvc::m_reading_batch_mtx |
|
private |
◆ m_seed
Gaudi::Property<std::uint64_t> BatchedMinbiasSvc::m_seed |
|
private |
Initial value:{this, "Seed", 0,
"Additional seed for PRNGs"}
Definition at line 51 of file BatchedMinbiasSvc.h.
◆ m_skipEventIdxSvc
Initial value:{
this, "SkipEvtIdxSvc", "SkipEventIdxSvc",
"Skipped event index (run / lb num) provider"}
Definition at line 88 of file BatchedMinbiasSvc.h.
◆ m_skippedHSEvents
Gaudi::Property<int> BatchedMinbiasSvc::m_skippedHSEvents |
|
private |
Initial value:{this, "SkippedHSEvents", 0,
"Number of skipped HS events"}
Definition at line 72 of file BatchedMinbiasSvc.h.
◆ m_spare_store
SGHandle BatchedMinbiasSvc::m_spare_store |
|
private |
Initial value:{this, "StoreGateSvc",
"StoreGate for discarding events"}
Definition at line 100 of file BatchedMinbiasSvc.h.
◆ m_useBeamInt
Gaudi::Property<bool> BatchedMinbiasSvc::m_useBeamInt |
|
private |
Initial value:{
this, "UseBeamInt", true, "Whether to use the beam intensity service"}
Definition at line 59 of file BatchedMinbiasSvc.h.
◆ m_useBeamLumi
Gaudi::Property<bool> BatchedMinbiasSvc::m_useBeamLumi |
|
private |
Initial value:{
this, "UseBeamLumi", true, "Whether to use the beam luminosity service"}
Definition at line 61 of file BatchedMinbiasSvc.h.
◆ m_usePoisson
Gaudi::Property<bool> BatchedMinbiasSvc::m_usePoisson |
|
private |
Initial value:{this, "UsePoisson", true,
"Whether to use a Poisson distribution "
"(if False, use a delta distribution)"}
Definition at line 56 of file BatchedMinbiasSvc.h.
The documentation for this class was generated from the following files:
ServiceHandle< ISkipEventIdxSvc > m_skipEventIdxSvc
std::deque< std::unique_ptr< SGHandleArray > > m_empty_caches
Gaudi::Property< int > m_earliestDeltaBC
Gaudi::Property< int > m_MBBatchSize
std::pair< long int, long int > indices
int event_to_batch(std::int64_t hs_id)
Temporarily change the current store.
Gaudi::Property< std::uint64_t > m_seed
std::mutex m_empty_caches_mtx
bool greater(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Gaudi::Property< bool > m_usePoisson
Gaudi::Property< int > m_HSBatchSize
Gaudi::Property< bool > m_useBeamInt
Gaudi::Property< bool > m_onDemandMB
std::map< int, std::mutex > m_cache_mtxs
POOL::TEvent event(POOL::TEvent::kClassAccess)
std::vector< EvtId >::const_iterator EvtIter
std::map< int, std::unique_ptr< SGHandleArray > > m_cache
::StatusCode StatusCode
StatusCode definition for legacy code.
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
AthROOTErrorHandlerSvc * svc
IEvtSelector::Context * m_bkg_evt_sel_ctx
Gaudi::Property< int > m_latestDeltaBC
ServiceHandle< ActiveStoreSvc > m_activeStoreSvc
std::size_t calcMBRequired(std::int64_t hs_id, std::size_t slot, unsigned int run, unsigned int lumi, std::uint64_t event)
std::vector< std::unique_ptr< std::atomic_int > > m_batch_use_count
Gaudi::Property< std::vector< int > > m_actualNHSEventsPerBatch
Gaudi::Property< float > m_nPerBunch
std::vector< std::vector< std::uint64_t > > m_num_mb_by_bunch
virtual std::int64_t get_hs_id(const EventContext &ctx) const override
accumulate
Update flags based on parser line args.
Gaudi::Property< int > m_skippedHSEvents
#define ATH_MSG_WARNING(x)
ServiceHandle< IEvtSelector > m_bkgEventSelector
Gaudi::Property< int > m_NSimultaneousBatches
Gaudi::Property< bool > m_useBeamLumi
std::vector< std::vector< std::uint64_t > > m_idx_lists
std::atomic_int m_last_loaded_batch
ServiceHandle< IBeamLuminosity > m_beamLumi
std::mutex m_reading_batch_mtx
ServiceHandle< IBeamIntensity > m_beamInt