ATLAS Offline Software
Loading...
Searching...
No Matches
PileUpMergeSvc.h
Go to the documentation of this file.
1/* -*- C++ -*- */
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
12#ifndef PILEUPTOOLS_PILEUPMERGESVC_H
13#define PILEUPTOOLS_PILEUPMERGESVC_H
14
17#include "PileUpTools/IPileUpTool.h" /* subEventIterator*/
19
21#include "GaudiKernel/ClassID.h"
22#include "Gaudi/Property.h" /*StringArrayProperty*/
23#include "GaudiKernel/StatusCode.h"
24#include "GaudiKernel/ServiceHandle.h"
25#include "GaudiKernel/ToolHandle.h"
26
27#include "AthLinks/DataLink.h"
29
32
33#include <cassert>
34
35#include <list>
36#include <map>
37#include <utility> /*std::pair*/
38#include <mutex>
39
40class ISvcLocator;
41class StoreGateSvc;
42class ITriggerTime;
43class IToolSvc;
44
45
55
56class PileUpMergeSvc : public AthService {
57
58public:
60 PileUpMergeSvc(const std::string& name, ISvcLocator* svc);
61
62 virtual ~PileUpMergeSvc() {}
63
64 virtual StatusCode initialize() override;
65
67 template <typename DATA>
68 struct TimedList {
69 typedef DATA data_t;
71 typedef std::pair<PileUpTimeEventIndex, DataLink<DATA> > value_t;
73 typedef std::list<value_t> type;
74 };
75
77 template <typename KEY, typename DATA>
78 StatusCode
79 retrieveOriginal(const KEY& dataKey, const DATA*& data);
80
81 template <typename KEY, typename DATA>
82 StatusCode
83 retrieveSingleSubEvtData(const KEY& dataKey, const DATA*& data, int bunchXing, SubEventIterator iEvt);
84
86 template <typename KEY, typename TIMEDDATA>
87 StatusCode
88 retrieveSubEvtsData(const KEY& dataKey, //orig evt key
89 TIMEDDATA& timedData);
90
91 template <typename KEY, typename TIMEDDATA>
92 StatusCode
93 retrieveSubSetEvtData(const KEY& dataKey, //orig evt key
94 TIMEDDATA& timedData, int bunchXing,
95 SubEventIterator bSubEvents, SubEventIterator eSubEvents);
96
98 template <typename KEY, typename TIMEDDATA>
99 StatusCode
100 retrieveSubEvtsData(const KEY& dataKey, //orig evt key
101 TIMEDDATA& timedData, unsigned int& numberOfSimHits);
102
103
104// ///retrieve default DATA objs for all sub-events and attach a time to them
105// template <typename TIMEDDATA>
106// StatusCode
107// retrieveSubEvtsData(TIMEDDATA& timedData);
108
111 StatusCode clearDataCaches();
112
115 const std::string& einame ) const;
116
117private:
119 ToolHandleArray<IPileUpXingFolder> m_intervals{this, "Intervals", {},
120 "Folders specifying bunch xing intervals for different data objects"};
121
122 // Protect against multiple threads trying to make EventInfo
123 // for the same slot.
125
126 template <typename DATA, typename KEY>
127 bool isLive(const KEY& key, int iXing);
128 bool isLive(CLID id, const std::string& dataKey, int iXing);
129
130 void decodeIntervals();
131
133 class Range {
134 public:
136 Range(int first, int last, double cacheRefreshFrequency) :
137 m_noLimits(false), m_first(first), m_last(last),
138 m_cacheRefreshFrequency(cacheRefreshFrequency) {
140 }
145 Range& operator =(const Range& rhs)
146 {
147 if (this == &rhs) {return *this;} // Handle self assignment
149 m_first = rhs.m_first;
150 m_last = rhs.m_last;
152 return *this;
153 }
154 bool contains(int xing) const {
155 return m_noLimits || (m_first<=xing && xing<=m_last);
156 }
157 bool doRefresh(float random) const {
158 assert(0.0 <= random && random <= 1.0);
159 // bool result(random < m_cacheRefreshFrequency);
160 // std::cerr << "Range::doRefresh: random " << random
161 // << " frequency " << m_cacheRefreshFrequency
162 // << " result " << result << std::endl;
163 return ( random < m_cacheRefreshFrequency );
164 }
165 private:
169 };
170 typedef std::map<std::pair<CLID, std::string>, Range> RangeContainer;
172
173 ToolHandle<ITriggerTime> m_pITriggerTime{this, "TriggerTimeTool", "",
174 "allows to apply a trigger time offset"};
175
177 BooleanProperty m_returnTimedData{this, "ReturnTimedData", true,
178 "determine whether the TimedData returned by retrieveSubEvts have non trivial "
179 "PileUpTimeEventIndex. May be set to false for overlay with real events"};
180
181 bool doRefresh(const Range& r, int iXing);
182
183 //Default name for EventInfo
184 StringProperty m_EventInfoKeyName{this, "EventInfoKeyName", "OverlayEvent",
185 "default name for EventInfo"};
186
188 ToolHandle< xAODMaker::IEventInfoCnvTool > m_xAODCnvTool{
189 this, "xAODCnvTool", "xAODMaker::EventInfoCnvTool/EventInfoCnvTool"};
190};
192#endif /* PILEUPTOOLS_PILEUPMERGESVC_H */
193
Maintain a set of objects, one per slot.
uint32_t CLID
The Class ID type.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
a call-back interface for tools that merge pileup events information An IPileUpTool is called back fo...
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition IPileUpTool.h:22
an interface to SG::Folder with an attached bunch crossing interval
Define macros for attributes used to control the static checker.
interface to a tool that returns the time offset of the current trigger.
the active crossing range for a data object (CLID/key combination)
Range(const Range &rhs)
bool doRefresh(float random) const
Range(int first, int last, double cacheRefreshFrequency)
Range & operator=(const Range &rhs)
bool contains(int xing) const
StatusCode retrieveSubSetEvtData(const KEY &dataKey, TIMEDDATA &timedData, int bunchXing, SubEventIterator bSubEvents, SubEventIterator eSubEvents)
ToolHandle< ITriggerTime > m_pITriggerTime
controls PileUpTimedEventIndex for TimedData returned by retrieveSubEvts
void decodeIntervals()
setup PileUpIntervals
ToolHandleArray< IPileUpXingFolder > m_intervals
bool isLive(const KEY &key, int iXing)
is iXing live for DATA/key?
StatusCode clearDataCaches()
clear bkg event caches from unneeded data objects (as configured using PileUpXingFolder CacheRefreshF...
RangeContainer m_ranges
StatusCode retrieveSubEvtsData(const KEY &dataKey, TIMEDDATA &timedData, unsigned int &numberOfSimHits)
retrieve keyed DATA objs for all sub-events and attach a time to them
std::map< std::pair< CLID, std::string >, Range > RangeContainer
virtual StatusCode initialize() override
Service initialisation.
StringProperty m_EventInfoKeyName
bool doRefresh(const Range &r, int iXing)
ToolHandle< xAODMaker::IEventInfoCnvTool > m_xAODCnvTool
property: Handle to the EventInfo -> xAOD::EventInfo converter tool
virtual ~PileUpMergeSvc()
PileUpMergeSvc(const std::string &name, ISvcLocator *svc)
Standard Gaudi Constructor.
StatusCode retrieveSubEvtsData(const KEY &dataKey, TIMEDDATA &timedData)
retrieve keyed DATA objs for all sub-events and attach a time to them
SG::SlotSpecificObj< std::mutex > m_slotMutex ATLAS_THREAD_SAFE
BooleanProperty m_returnTimedData
ServiceHandle< StoreGateSvc > p_overStore
overlaid SG (default)
const xAOD::EventInfo * getPileUpEvent(StoreGateSvc *sg, const std::string &einame) const
get EventInfo from SG, by default using p_overStore
StatusCode retrieveSingleSubEvtData(const KEY &dataKey, const DATA *&data, int bunchXing, SubEventIterator iEvt)
StatusCode retrieveOriginal(const KEY &dataKey, const DATA *&data)
retrieve keyed DATA objs for the original event only
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Maintain a set of objects, one per slot.
The Athena Transient Store API.
int r
Definition globals.cxx:22
EventInfo_v1 EventInfo
Definition of the latest event info version.
generate the types of the timed data objects
std::list< value_t > type
type of the collection of timed data object
std::pair< PileUpTimeEventIndex, DataLink< DATA > > value_t
type of timed data object