ATLAS Offline Software
Loading...
Searching...
No Matches
BatchedMinbiasSvc.h
Go to the documentation of this file.
1/* -*- C++ -*- */
2/*
3 Copyright (C) 2022, 2023 CERN for the benefit of the ATLAS collaboration
4*/
5
6#ifndef PILEUPMT_BATCHEDMINBIASSVC_H
7#define PILEUPMT_BATCHEDMINBIASSVC_H
8
9#include <atomic>
10#include <deque>
11#include <format>
12#include <map>
13#include <memory>
14#include <mutex>
15#include <string>
16#include <vector>
17
19#include "Gaudi/Property.h"
20#include "GaudiKernel/IEvtSelector.h"
21#include "GaudiKernel/ServiceHandle.h"
22#include "ISkipEventIdxSvc.h"
27
28class BatchedMinbiasSvc : public extends<AthService, IMinbiasSvc> {
29 public:
31 BatchedMinbiasSvc(const std::string& name, ISvcLocator* svc);
34
36 StatusCode initialize() override;
37
38 StatusCode beginHardScatter(const EventContext& ctx) override;
39 StoreGateSvc* getMinbias(const EventContext& ctx,
40 std::uint64_t mb_id) override;
41 std::size_t getNumForBunch(const EventContext& ctx, int bunch) const override;
42 virtual inline
43 std::int64_t get_hs_id(const EventContext& ctx) const override {
44 return m_skippedHSEvents.value() + ctx.evt();
45 }
46 StatusCode endHardScatter(const EventContext& ctx) override;
47
48 private:
50 using SGHandleArray = std::vector<SGHandle>;
51 Gaudi::Property<std::uint64_t> m_seed{this, "Seed", 0,
52 "Additional seed for PRNGs"};
53 Gaudi::Property<bool> m_onDemandMB{
54 this, "OnDemandMB", false,
55 "Should minbias event contents be read on demand"};
56 Gaudi::Property<bool> m_usePoisson{this, "UsePoisson", true,
57 "Whether to use a Poisson distribution "
58 "(if False, use a delta distribution)"};
59 Gaudi::Property<bool> m_useBeamInt{
60 this, "UseBeamInt", true, "Whether to use the beam intensity service"};
61 Gaudi::Property<bool> m_useBeamLumi{
62 this, "UseBeamLumi", true, "Whether to use the beam luminosity service"};
63 Gaudi::Property<int> m_MBBatchSize{
64 this, "MBBatchSize", 10000,
65 "Number of low pT minbias events to load per batch"};
66 Gaudi::Property<int> m_NSimultaneousBatches{
67 this, "NSimultaneousBatches", 1,
68 "Max number of batches to load simultaneously"};
69 Gaudi::Property<int> m_HSBatchSize{
70 this, "HSBatchSize", 1,
71 "Number of HS events per batch (aka max reuse factor)"};
72 Gaudi::Property<int> m_skippedHSEvents{this, "SkippedHSEvents", 0,
73 "Number of skipped HS events"};
74 Gaudi::Property<float> m_nPerBunch{
75 this, "AvgMBPerBunch", 0,
76 "Average (max) number of minbias events per bunch"};
77 Gaudi::Property<int> m_earliestDeltaBC{
78 this, "EarliestDeltaBC", -32,
79 "Earliest bunch crossing to consider (as delta)"};
80 Gaudi::Property<int> m_latestDeltaBC{
81 this, "LatestDeltaBC", +6,
82 "Latest bunch crossing to consider (as delta)"};
83 Gaudi::Property<std::vector<int>> m_actualNHSEventsPerBatch{
84 this,
85 "actualNHSEventsPerBatch",
86 {},
87 "Dynamic map of actual number of HS events for each batch, in this run."};
89 this, "SkipEvtIdxSvc", "SkipEventIdxSvc",
90 "Skipped event index (run / lb num) provider"};
92 this, "BkgEventSelector", {}, "Event selector for minbias events"};
93 ServiceHandle<IBeamIntensity> m_beamInt{this, "BeamIntSvc", "FlatBM",
94 "Beam intensity service"};
96 this, "BeamLumiSvc", "LumiProfileSvc", "Beam luminosity service"};
98 this, "ActiveStoreSvc", "ActiveStoreSvc", "ActiveStoreSvc"};
99
100 SGHandle m_spare_store{this, "StoreGateSvc",
101 std::format("StoreGateSvc/discards_{}", name()),
102 "StoreGate for discarding events"};
103 IEvtSelector::Context* m_bkg_evt_sel_ctx;
104
105 std::vector<std::vector<std::uint64_t>> m_num_mb_by_bunch;
106 std::vector<std::vector<std::uint64_t>> m_idx_lists;
107 std::map<int, std::unique_ptr<SGHandleArray>> m_cache;
108 std::map<int, std::mutex> m_cache_mtxs; // protects m_cache entries
109 // prevents attempting to read multiple batches at once
111 std::deque<std::unique_ptr<SGHandleArray>> m_empty_caches;
112 std::mutex m_empty_caches_mtx; // protects m_empty_caches
113 std::vector<std::unique_ptr<std::atomic_int>> m_batch_use_count;
114 std::atomic_int m_last_loaded_batch;
115 int event_to_batch(std::int64_t hs_id);
116 std::size_t calcMBRequired(std::int64_t hs_id, std::size_t slot,
117 unsigned int run, unsigned int lumi,
118 std::uint64_t event);
119};
120
121#endif // PILEUPMT_BATCHEDMINBIASSVC_H
provides the relative beam intensity as a function of the bunch xing.
provides the relative beam luminosity as a function of the bunch xing.
StatusCode initialize() override
AthService initialize.
ServiceHandle< IEvtSelector > m_bkgEventSelector
Gaudi::Property< std::uint64_t > m_seed
Gaudi::Property< float > m_nPerBunch
Gaudi::Property< bool > m_useBeamLumi
std::vector< std::vector< std::uint64_t > > m_idx_lists
std::map< int, std::unique_ptr< SGHandleArray > > m_cache
ServiceHandle< IBeamIntensity > m_beamInt
~BatchedMinbiasSvc()
Destructor.
Gaudi::Property< std::vector< int > > m_actualNHSEventsPerBatch
Gaudi::Property< bool > m_onDemandMB
int event_to_batch(std::int64_t hs_id)
StoreGateSvc * getMinbias(const EventContext &ctx, std::uint64_t mb_id) override
Gaudi::Property< int > m_earliestDeltaBC
std::vector< std::unique_ptr< std::atomic_int > > m_batch_use_count
Gaudi::Property< bool > m_usePoisson
std::vector< std::vector< std::uint64_t > > m_num_mb_by_bunch
ServiceHandle< ActiveStoreSvc > m_activeStoreSvc
Gaudi::Property< int > m_latestDeltaBC
std::deque< std::unique_ptr< SGHandleArray > > m_empty_caches
std::mutex m_reading_batch_mtx
std::size_t getNumForBunch(const EventContext &ctx, int bunch) const override
StatusCode endHardScatter(const EventContext &ctx) override
Gaudi::Property< bool > m_useBeamInt
Gaudi::Property< int > m_skippedHSEvents
std::mutex m_empty_caches_mtx
Gaudi::Property< int > m_MBBatchSize
BatchedMinbiasSvc(const std::string &name, ISvcLocator *svc)
Constructor.
ServiceHandle< ISkipEventIdxSvc > m_skipEventIdxSvc
IEvtSelector::Context * m_bkg_evt_sel_ctx
std::vector< SGHandle > SGHandleArray
virtual std::int64_t get_hs_id(const EventContext &ctx) const override
ServiceHandle< StoreGateSvc > SGHandle
Gaudi::Property< int > m_HSBatchSize
std::map< int, std::mutex > m_cache_mtxs
std::size_t calcMBRequired(std::int64_t hs_id, std::size_t slot, unsigned int run, unsigned int lumi, std::uint64_t event)
StatusCode beginHardScatter(const EventContext &ctx) override
std::atomic_int m_last_loaded_batch
ServiceHandle< IBeamLuminosity > m_beamLumi
Gaudi::Property< int > m_NSimultaneousBatches
The Athena Transient Store API.
Definition run.py:1