ATLAS Offline Software
PileUpMergeSvc.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
13 #ifndef PILEUPTOOLS_PILEUPMERGESVC_H
14 #define PILEUPTOOLS_PILEUPMERGESVC_H
15 
18 #include "PileUpTools/IPileUpTool.h" /* subEventIterator*/
20 
22 #include "GaudiKernel/ClassID.h"
23 #include "Gaudi/Property.h" /*StringArrayProperty*/
24 #include "GaudiKernel/StatusCode.h"
25 #include "GaudiKernel/ServiceHandle.h"
26 #include "GaudiKernel/ToolHandle.h"
27 
28 #include "AthLinks/DataLink.h"
30 
33 
34 #include <cassert>
35 
36 #include <list>
37 #include <map>
38 #include <utility> /*std::pair*/
39 #include <mutex>
40 
41 class ISvcLocator;
42 class StoreGateSvc;
43 class ITriggerTime;
44 class IToolSvc;
45 
46 
58 class PileUpMergeSvc : public AthService {
59 
60 public:
62  PileUpMergeSvc(const std::string& name, ISvcLocator* svc);
63 
64  virtual ~PileUpMergeSvc() {}
65 
66  virtual StatusCode initialize();
67 
69  template <typename DATA>
70  struct TimedList {
71  typedef DATA data_t;
73  typedef std::pair<PileUpTimeEventIndex, DataLink<DATA> > value_t;
75  typedef std::list<value_t> type;
76  };
77 
79  template <typename KEY, typename DATA>
80  StatusCode
81  retrieveOriginal(const KEY& dataKey, const DATA*& data);
82 
83  template <typename KEY, typename DATA>
85  retrieveSingleSubEvtData(const KEY& dataKey, const DATA*& data, int bunchXing, SubEventIterator iEvt);
86 
88  template <typename KEY, typename TIMEDDATA>
89  StatusCode
90  retrieveSubEvtsData(const KEY& dataKey, //orig evt key
91  TIMEDDATA& timedData);
92 
93  template <typename KEY, typename TIMEDDATA>
94  StatusCode
95  retrieveSubSetEvtData(const KEY& dataKey, //orig evt key
96  TIMEDDATA& timedData, int bunchXing,
97  SubEventIterator bSubEvents, SubEventIterator eSubEvents);
98 
100  template <typename KEY, typename TIMEDDATA>
101  StatusCode
102  retrieveSubEvtsData(const KEY& dataKey, //orig evt key
103  TIMEDDATA& timedData, unsigned int& numberOfSimHits);
104 
105 
106 // ///retrieve default DATA objs for all sub-events and attach a time to them
107 // template <typename TIMEDDATA>
108 // StatusCode
109 // retrieveSubEvtsData(TIMEDDATA& timedData);
110 
114 
116  static const InterfaceID& interfaceID();
117  virtual StatusCode queryInterface( const InterfaceID& riid, void** ppvInterface );
118 
121  const std::string& einame ) const;
122 
123 private:
125  ToolHandleArray<IPileUpXingFolder> m_intervals;
126 
127  // Protect against multiple threads trying to make EventInfo
128  // for the same slot.
130 
131  template <typename DATA, typename KEY>
132  bool isLive(const KEY& key, int iXing);
133  bool isLive(CLID id, const std::string& dataKey, int iXing);
134 
135  void decodeIntervals();
136 
138  class Range {
139  public:
141  Range(int first, int last, double cacheRefreshFrequency) :
142  m_noLimits(false), m_first(first), m_last(last),
143  m_cacheRefreshFrequency(cacheRefreshFrequency) {
145  }
146  Range(const Range& rhs) :
147  m_noLimits(rhs.m_noLimits),
148  m_first(rhs.m_first), m_last(rhs.m_last),
150  Range& operator =(const Range& rhs)
151  {
152  if (this == &rhs) {return *this;} // Handle self assignment
153  m_noLimits = rhs.m_noLimits;
154  m_first = rhs.m_first;
155  m_last = rhs.m_last;
157  return *this;
158  }
159  bool contains(int xing) const {
160  return m_noLimits || (m_first<=xing && xing<=m_last);
161  }
162  bool doRefresh(float random) const {
163  assert(0.0 <= random && random <= 1.0);
164  // bool result(random < m_cacheRefreshFrequency);
165  // std::cerr << "Range::doRefresh: random " << random
166  // << " frequency " << m_cacheRefreshFrequency
167  // << " result " << result << std::endl;
168  return ( random < m_cacheRefreshFrequency );
169  }
170  private:
174  };
175  typedef std::map<std::pair<CLID, std::string>, Range> RangeContainer;
177 
178  ToolHandle<ITriggerTime> m_pITriggerTime;
179  BooleanProperty m_returnTimedData;
181 
182  bool doRefresh(const Range& r, int iXing);
183 
184  //Default name for EventInfo
185  std::string m_EventInfoKeyName;
186 
188  ToolHandle< xAODMaker::IEventInfoCnvTool > m_xAODCnvTool;
189 };
191 #endif /* PILEUPTOOLS_PILEUPMERGESVC_H */
192 
beamspotman.r
def r
Definition: beamspotman.py:676
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
PileUpMergeSvc::interfaceID
static const InterfaceID & interfaceID()
Retrieve interface ID.
Definition: PileUpMergeSvc.cxx:257
PileUpMergeSvc::getPileUpEvent
const xAOD::EventInfo * getPileUpEvent(StoreGateSvc *sg, const std::string &einame) const
get EventInfo from SG, by default using p_overStore
Definition: PileUpMergeSvc.cxx:122
PileUpMergeSvc::Range::operator=
Range & operator=(const Range &rhs)
Definition: PileUpMergeSvc.h:150
PileUpMergeSvc::ATLAS_THREAD_SAFE
SG::SlotSpecificObj< std::mutex > m_slotMutex ATLAS_THREAD_SAFE
Definition: PileUpMergeSvc.h:129
PileUpMergeSvc::TimedList
generate the types of the timed data objects
Definition: PileUpMergeSvc.h:70
PileUpMergeSvc::Range::contains
bool contains(int xing) const
Definition: PileUpMergeSvc.h:159
PileUpMergeSvc::isLive
bool isLive(const KEY &key, int iXing)
is iXing live for DATA/key?
PileUpMergeSvc::retrieveSingleSubEvtData
StatusCode retrieveSingleSubEvtData(const KEY &dataKey, const DATA *&data, int bunchXing, SubEventIterator iEvt)
PileUpMergeSvc::doRefresh
bool doRefresh(const Range &r, int iXing)
Definition: PileUpMergeSvc.cxx:288
PileUpMergeSvc::Range::m_last
int m_last
Definition: PileUpMergeSvc.h:172
PileUpMergeSvc::retrieveOriginal
StatusCode retrieveOriginal(const KEY &dataKey, const DATA *&data)
retrieve keyed DATA objs for the original event only
PileUpMergeSvc::initialize
virtual StatusCode initialize()
Service initialisation.
Definition: PileUpMergeSvc.cxx:89
PileUpMergeSvc::m_EventInfoKeyName
std::string m_EventInfoKeyName
Definition: PileUpMergeSvc.h:185
PileUpMergeSvc
the preferred mechanism to access information from the different event stores in a pileup job.
Definition: PileUpMergeSvc.h:58
PileUpTimeEventIndex.h
PileUpMergeSvc::TimedList::type
std::list< value_t > type
type of the collection of timed data object
Definition: PileUpMergeSvc.h:75
PileUpMergeSvc::retrieveSubEvtsData
StatusCode retrieveSubEvtsData(const KEY &dataKey, TIMEDDATA &timedData, unsigned int &numberOfSimHits)
retrieve keyed DATA objs for all sub-events and attach a time to them
PileUpMergeSvc::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Definition: PileUpMergeSvc.cxx:268
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
SG::SlotSpecificObj< std::mutex >
PileUpMergeSvc::Range::doRefresh
bool doRefresh(float random) const
Definition: PileUpMergeSvc.h:162
PileUpMergeSvc::p_overStore
ServiceHandle< StoreGateSvc > p_overStore
overlaid SG (default)
Definition: PileUpMergeSvc.h:124
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PileUpMergeSvc::Range::Range
Range(int first, int last, double cacheRefreshFrequency)
Definition: PileUpMergeSvc.h:141
AthService
Definition: AthService.h:32
PileUpMergeSvc::Range::Range
Range(const Range &rhs)
Definition: PileUpMergeSvc.h:146
IPileUpTool.h
a call-back interface for tools that merge pileup events information An IPileUpTool is called back fo...
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
PileUpMergeSvc::decodeIntervals
void decodeIntervals()
setup PileUpIntervals
Definition: PileUpMergeSvc.cxx:56
PileUpMergeSvc::clearDataCaches
StatusCode clearDataCaches()
clear bkg event caches from unneeded data objects (as configured using PileUpXingFolder CacheRefreshF...
Definition: PileUpMergeSvc.cxx:296
PileUpMergeSvc::~PileUpMergeSvc
virtual ~PileUpMergeSvc()
Definition: PileUpMergeSvc.h:64
PileUpMergeSvc::retrieveSubSetEvtData
StatusCode retrieveSubSetEvtData(const KEY &dataKey, TIMEDDATA &timedData, int bunchXing, SubEventIterator bSubEvents, SubEventIterator eSubEvents)
PileUpMergeSvc::m_intervals
ToolHandleArray< IPileUpXingFolder > m_intervals
Property: bunch xing intervals.
Definition: PileUpMergeSvc.h:125
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ITriggerTime
interface to a tool that returns the time offset of the current trigger. Used by PileUpMergeSvc
Definition: ITriggerTime.h:19
PileUpMergeSvc::RangeContainer
std::map< std::pair< CLID, std::string >, Range > RangeContainer
Definition: PileUpMergeSvc.h:175
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
PileUpMergeSvc::TimedList::value_t
std::pair< PileUpTimeEventIndex, DataLink< DATA > > value_t
type of timed data object
Definition: PileUpMergeSvc.h:73
IEventInfoCnvTool.h
PileUpMergeSvc::Range::m_noLimits
bool m_noLimits
Definition: PileUpMergeSvc.h:171
PileUpMergeSvc.icc
PileUpMergeSvc::TimedList::data_t
DATA data_t
Definition: PileUpMergeSvc.h:71
PileUpMergeSvc::m_ranges
RangeContainer m_ranges
Definition: PileUpMergeSvc.h:176
DeMoScan.first
bool first
Definition: DeMoScan.py:536
PileUpMergeSvc::Range::m_cacheRefreshFrequency
double m_cacheRefreshFrequency
Definition: PileUpMergeSvc.h:173
PileUpMergeSvc::PileUpMergeSvc
PileUpMergeSvc(const std::string &name, ISvcLocator *svc)
Standard Gaudi Constructor.
Definition: PileUpMergeSvc.cxx:38
AthService.h
SlotSpecificObj.h
Maintain a set of objects, one per slot.
IPileUpXingFolder.h
an interface to SG::Folder with an attached bunch crossing interval
SubEventIterator
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition: IPileUpTool.h:22
PileUpMergeSvc::Range::m_first
int m_first
Definition: PileUpMergeSvc.h:172
checker_macros.h
Define macros for attributes used to control the static checker.
PileUpMergeSvc::m_xAODCnvTool
ToolHandle< xAODMaker::IEventInfoCnvTool > m_xAODCnvTool
property: Handle to the EventInfo -> xAOD::EventInfo converter tool
Definition: PileUpMergeSvc.h:188
PileUpMergeSvc::m_pITriggerTime
ToolHandle< ITriggerTime > m_pITriggerTime
allows to apply a trigger time offset
Definition: PileUpMergeSvc.h:178
PileUpMergeSvc::Range
the active crossing range for a data object (CLID/key combination)
Definition: PileUpMergeSvc.h:138
PileUpMergeSvc::Range::Range
Range()
Definition: PileUpMergeSvc.h:140
PileUpMergeSvc::m_returnTimedData
BooleanProperty m_returnTimedData
Definition: PileUpMergeSvc.h:180
PileUpMergeSvc::retrieveSubEvtsData
StatusCode retrieveSubEvtsData(const KEY &dataKey, TIMEDDATA &timedData)
retrieve keyed DATA objs for all sub-events and attach a time to them
ServiceHandle< StoreGateSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37