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
20#include "Gaudi/Property.h"
21#include "GaudiKernel/IEvtSelector.h"
22#include "GaudiKernel/ServiceHandle.h"
23#include "ISkipEventIdxSvc.h"
28
29class BatchedMinbiasSvc : public extends<AthService, IMinbiasSvc> {
30 public:
32 BatchedMinbiasSvc(const std::string& name, ISvcLocator* svc);
35
37 StatusCode initialize() override;
38
39 StatusCode beginHardScatter(const EventContext& ctx) override;
40 StoreGateSvc* getMinbias(const EventContext& ctx,
41 std::uint64_t mb_id) override;
42 std::size_t getNumForBunch(const EventContext& ctx, int bunch) const override;
43 virtual inline
44 std::int64_t get_hs_id(const EventContext& ctx) const override {
45 return m_skippedHSEvents.value() + ctx.evt();
46 }
47 StatusCode endHardScatter(const EventContext& ctx) override;
48
49 private:
51 using SGHandleArray = std::vector<SGHandle>;
52 Gaudi::Property<std::uint64_t> m_seed{this, "Seed", 0,
53 "Additional seed for PRNGs"};
54 Gaudi::Property<bool> m_onDemandMB{
55 this, "OnDemandMB", false,
56 "Should minbias event contents be read on demand"};
57 Gaudi::Property<bool> m_usePoisson{this, "UsePoisson", true,
58 "Whether to use a Poisson distribution "
59 "(if False, use a delta distribution)"};
60 Gaudi::Property<bool> m_useBeamInt{
61 this, "UseBeamInt", true, "Whether to use the beam intensity service"};
62 Gaudi::Property<bool> m_useBeamLumi{
63 this, "UseBeamLumi", true, "Whether to use the beam luminosity service"};
64 Gaudi::Property<int> m_MBBatchSize{
65 this, "MBBatchSize", 10000,
66 "Number of low pT minbias events to load per batch"};
67 Gaudi::Property<int> m_NSimultaneousBatches{
68 this, "NSimultaneousBatches", 1,
69 "Max number of batches to load simultaneously"};
70 Gaudi::Property<int> m_HSBatchSize{
71 this, "HSBatchSize", 1,
72 "Number of HS events per batch (aka max reuse factor)"};
73 Gaudi::Property<int> m_skippedHSEvents{this, "SkippedHSEvents", 0,
74 "Number of skipped HS events"};
75 Gaudi::Property<float> m_nPerBunch{
76 this, "AvgMBPerBunch", 0,
77 "Average (max) number of minbias events per bunch"};
78 Gaudi::Property<int> m_earliestDeltaBC{
79 this, "EarliestDeltaBC", -32,
80 "Earliest bunch crossing to consider (as delta)"};
81 Gaudi::Property<int> m_latestDeltaBC{
82 this, "LatestDeltaBC", +6,
83 "Latest bunch crossing to consider (as delta)"};
84 Gaudi::Property<std::vector<int>> m_actualNHSEventsPerBatch{
85 this,
86 "actualNHSEventsPerBatch",
87 {},
88 "Dynamic map of actual number of HS events for each batch, in this run."};
90 this, "SkipEvtIdxSvc", "SkipEventIdxSvc",
91 "Skipped event index (run / lb num) provider"};
93 this, "BkgEventSelector", {}, "Event selector for minbias events"};
94 ServiceHandle<IBeamIntensity> m_beamInt{this, "BeamIntSvc", "FlatBM",
95 "Beam intensity service"};
97 this, "BeamLumiSvc", "LumiProfileSvc", "Beam luminosity service"};
99 this, "ActiveStoreSvc", "ActiveStoreSvc", "ActiveStoreSvc"};
100
101 SGHandle m_spare_store{this, "StoreGateSvc",
102 std::format("StoreGateSvc/discards_{}", name()),
103 "StoreGate for discarding events"};
104 IEvtSelector::Context* m_bkg_evt_sel_ctx;
105
108 std::map<int, std::unique_ptr<SGHandleArray>> m_cache;
109 std::map<int, std::mutex> m_cache_mtxs; // protects m_cache entries
110 // prevents attempting to read multiple batches at once
112 std::deque<std::unique_ptr<SGHandleArray>> m_empty_caches;
113 std::mutex m_empty_caches_mtx; // protects m_empty_caches
114 std::vector<std::unique_ptr<std::atomic_int>> m_batch_use_count;
115 std::atomic_int m_last_loaded_batch;
116 int event_to_batch(std::int64_t hs_id);
117 std::size_t calcMBRequired(std::int64_t hs_id, const EventContext& ctx);
118};
119
120#endif // PILEUPMT_BATCHEDMINBIASSVC_H
Maintain a set of objects, one per slot.
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::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
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
SG::SlotSpecificObj< std::vector< std::uint64_t > > m_idx_lists
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
std::size_t calcMBRequired(std::int64_t hs_id, const EventContext &ctx)
SG::SlotSpecificObj< std::vector< std::uint64_t > > m_num_mb_by_bunch
Gaudi::Property< int > m_HSBatchSize
std::map< int, std::mutex > m_cache_mtxs
StatusCode beginHardScatter(const EventContext &ctx) override
std::atomic_int m_last_loaded_batch
ServiceHandle< IBeamLuminosity > m_beamLumi
Gaudi::Property< int > m_NSimultaneousBatches
Maintain a set of objects, one per slot.
The Athena Transient Store API.