ATLAS Offline Software
Loading...
Searching...
No Matches
PileUpMergeSvc Class Reference

the preferred mechanism to access information from the different event stores in a pileup job. More...

#include <PileUpMergeSvc.h>

Inheritance diagram for PileUpMergeSvc:
Collaboration diagram for PileUpMergeSvc:

Classes

struct  TimedList
 generate the types of the timed data objects More...
class  Range
 the active crossing range for a data object (CLID/key combination) More...

Public Member Functions

 PileUpMergeSvc (const std::string &name, ISvcLocator *svc)
 Standard Gaudi Constructor.
virtual ~PileUpMergeSvc ()
virtual StatusCode initialize () override
 Service initialisation.
template<typename KEY, typename DATA>
StatusCode retrieveOriginal (const KEY &dataKey, const DATA *&data)
 retrieve keyed DATA objs for the original event only
template<typename KEY, typename DATA>
StatusCode retrieveSingleSubEvtData (const KEY &dataKey, const DATA *&data, int bunchXing, SubEventIterator iEvt)
template<typename KEY, typename TIMEDDATA>
StatusCode retrieveSubEvtsData (const KEY &dataKey, TIMEDDATA &timedData)
 retrieve keyed DATA objs for all sub-events and attach a time to them
template<typename KEY, typename TIMEDDATA>
StatusCode retrieveSubSetEvtData (const KEY &dataKey, TIMEDDATA &timedData, int bunchXing, SubEventIterator bSubEvents, SubEventIterator eSubEvents)
template<typename KEY, typename TIMEDDATA>
StatusCode retrieveSubEvtsData (const KEY &dataKey, TIMEDDATA &timedData, unsigned int &numberOfSimHits)
 retrieve keyed DATA objs for all sub-events and attach a time to them
StatusCode clearDataCaches ()
 clear bkg event caches from unneeded data objects (as configured using PileUpXingFolder CacheRefreshFrequency property)
const xAOD::EventInfogetPileUpEvent (StoreGateSvc *sg, const std::string &einame)
 get EventInfo from SG, by default using p_overStore
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Private Types

typedef std::map< std::pair< CLID, std::string >, RangeRangeContainer

Private Member Functions

template<typename DATA, typename KEY>
bool isLive (const KEY &key, int iXing)
 is iXing live for DATA/key?
bool isLive (CLID id, const std::string &dataKey, int iXing)
void decodeIntervals ()
 setup PileUpIntervals
bool doRefresh (const Range &r, int iXing)

Private Attributes

ServiceHandle< StoreGateSvcp_overStore
 overlaid SG (default)
ToolHandleArray< IPileUpXingFolderm_intervals
SG::SlotSpecificObj< std::mutex > m_slotMutex ATLAS_THREAD_SAFE
RangeContainer m_ranges
ToolHandle< ITriggerTimem_pITriggerTime
 controls PileUpTimedEventIndex for TimedData returned by retrieveSubEvts
BooleanProperty m_returnTimedData
StringProperty m_EventInfoKeyName
ToolHandle< xAODMaker::IEventInfoCnvToolm_xAODCnvTool
 property: Handle to the EventInfo -> xAOD::EventInfo converter tool

Detailed Description

the preferred mechanism to access information from the different event stores in a pileup job.

access PileUpEventInfo to locate data objects (typically hit collections) to be merged attaching sub-evt time offsets

Author
Paolo Calafiura

Definition at line 56 of file PileUpMergeSvc.h.

Member Typedef Documentation

◆ RangeContainer

typedef std::map<std::pair<CLID, std::string>, Range> PileUpMergeSvc::RangeContainer
private

Definition at line 170 of file PileUpMergeSvc.h.

Constructor & Destructor Documentation

◆ PileUpMergeSvc()

PileUpMergeSvc::PileUpMergeSvc ( const std::string & name,
ISvcLocator * svc )

Standard Gaudi Constructor.

Standard Constructor.

Definition at line 38 of file PileUpMergeSvc.cxx.

39 : AthService(name,svc),
40 p_overStore("StoreGateSvc", "StoreGateSvc")
41{
42}
ServiceHandle< StoreGateSvc > p_overStore
overlaid SG (default)

◆ ~PileUpMergeSvc()

virtual PileUpMergeSvc::~PileUpMergeSvc ( )
inlinevirtual

Definition at line 62 of file PileUpMergeSvc.h.

62{}

Member Function Documentation

◆ clearDataCaches()

StatusCode PileUpMergeSvc::clearDataCaches ( )

clear bkg event caches from unneeded data objects (as configured using PileUpXingFolder CacheRefreshFrequency property)

Definition at line 262 of file PileUpMergeSvc.cxx.

262 {
263 StatusCode sc(StatusCode::FAILURE);
264 const xAOD::EventInfo* pEvent;
265 if (0 != (pEvent=getPileUpEvent(nullptr,m_EventInfoKeyName))) {
266 // access the sub events DATA objects...
267 for( const xAOD::EventInfo::SubEvent& subEv : pEvent->subEvents() ) {
268 StoreGateSvc* pSubEvtSG( subEv.ptr()->evtStore() );
269 assert(pSubEvtSG);
270 //go object-by-object (driven by PileUpXingFolder settings)
271 for (const auto& item : m_ranges) {
272 SG::sgkey_t sgkey = pSubEvtSG->stringToKey (item.first.second,
273 item.first.first);
274 SG::DataProxy* proxy = pSubEvtSG->proxy_exact (sgkey);
275 //FIXME turning the double iEvt->time is fraught with peril. Luckily
276 //FIXME it just works, but we should have the beam xing in iEvt
277 if (proxy && doRefresh (item.second, int(subEv.time()))) {
278 proxy->setObject ((DataObject*)0);
279 if (msg().level() <= MSG::DEBUG) {
280 msg() << MSG::DEBUG
281 << "clearDataCachesByFolder: object with clid "
282 << item.first.first << " and key " << item.first.second
283 << " removed from cache "
284 << pSubEvtSG->name() << endmsg;
285 }
286 }
287 }
288 //even if we don't clear the store we need to empty the trash...
289 pSubEvtSG->emptyTrash();
290#ifndef NDEBUG
291 if (msg().level() <= MSG::VERBOSE) {
292 msg() << MSG::VERBOSE
293 << "clearDataCachesByFolder: done with store " << pSubEvtSG->name()
294 << endmsg;
295 }
296#endif
297 } //stores loop
298 sc=StatusCode::SUCCESS;
299 } //NO PILEUP EVENT?!?
300 return sc;
301}
#define endmsg
static Double_t sc
MsgStream & msg() const
RangeContainer m_ranges
StringProperty m_EventInfoKeyName
bool doRefresh(const Range &r, int iXing)
const xAOD::EventInfo * getPileUpEvent(StoreGateSvc *sg, const std::string &einame)
get EventInfo from SG, by default using p_overStore
const std::vector< SubEvent > & subEvents() const
Get the pileup events that were used in the simulation.
::StatusCode StatusCode
StatusCode definition for legacy code.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
sgkey(tool)
Definition common.py:1027
EventInfo_v1 EventInfo
Definition of the latest event info version.

◆ decodeIntervals()

void PileUpMergeSvc::decodeIntervals ( )
private

setup PileUpIntervals

Definition at line 45 of file PileUpMergeSvc.cxx.

45 {
46 if (m_intervals.retrieve().isSuccess()) {
47 ToolHandleArray<IPileUpXingFolder>::const_iterator
48 iXing(m_intervals.begin()), iEnd(m_intervals.end());
49 while (iXing != iEnd) {
50 const IPileUpXingFolder& xing(**iXing);
51 if (msg().level() <= MSG::DEBUG) {
52 msg() << MSG::DEBUG << "decodeIntervals: adding IPileUpXingFolder "
53 << xing.name() << endmsg;
54 }
56 item(xing.begin()), endItem(xing.end());
57 while(item != endItem) {
58 m_ranges[make_pair(item->id(), item->key())]=
59 Range(xing.firstXing(), xing.lastXing(), xing.cacheRefreshFrequency());
60 if (msg().level() <= MSG::VERBOSE) {
61 msg() << MSG::VERBOSE
62 << "decodeInterval: accepting objects of CLID " << item->id()
63 << " key " << item->key() << " in the Xing range ["
64 << xing.firstXing() << ", " << xing.lastXing() << ']'
65 << " with cache refresh frequency "
66 << xing.cacheRefreshFrequency() << endmsg;
67 }
68 ++item;
69 }
70 ++iXing;
71 }
72 }
73}
SG::IFolder::const_iterator const_iterator
the active crossing range for a data object (CLID/key combination)
ToolHandleArray< IPileUpXingFolder > m_intervals

◆ doRefresh()

bool PileUpMergeSvc::doRefresh ( const Range & r,
int iXing )
private

Definition at line 254 of file PileUpMergeSvc.cxx.

254 {
255 // bool result(r.contains(iXing) && r.doRefresh(double(random())/RAND_MAX));
256 // std::cerr << "doRefresh: id " << id << " key " << dataKey
257 // << " xing " << iXing << " result " << result << std::endl;
258 return (r.contains(iXing) && r.doRefresh(double(random())*(1./RAND_MAX)));
259}
int r
Definition globals.cxx:22

◆ getPileUpEvent()

const xAOD::EventInfo * PileUpMergeSvc::getPileUpEvent ( StoreGateSvc * sg,
const std::string & einame )

get EventInfo from SG, by default using p_overStore

Definition at line 111 of file PileUpMergeSvc.cxx.

112{
113 const EventContext& ctx = Gaudi::Hive::currentContext();
114
115 if( !sg ) sg = p_overStore.get();
116 const xAOD::EventInfo* xAODEventInfo = einame.empty()?
118 : sg->tryConstRetrieve<xAOD::EventInfo>( einame );
119 if( xAODEventInfo ) {
120 ATH_MSG_DEBUG("Found xAOD::EventInfo="<<xAODEventInfo<<" SG="<<sg<<" : "<<*xAODEventInfo);
121 ATH_MSG_DEBUG(" EventInfo has " << xAODEventInfo->subEvents().size() << " subevents" );
122 // recreate subevent links cache
123 xAODEventInfo->subEvents();
124 } else {
125 // Don't allow more than one thread per slot through here.
126 // Otherwise, we can get errors with multiple threads trying
127 // to record the EventInfo object.
128 std::lock_guard<std::mutex> lock (*m_slotMutex);
129
130 // Try reading old EventInfo
131 const EventInfo* pEvent = einame.empty()?
132 sg->tryConstRetrieve< ::EventInfo >()
133 : sg->tryConstRetrieve< ::EventInfo >( einame );
134 if( pEvent ) {
135 ATH_MSG_DEBUG("Converting (PileUp)EventInfo "<<pEvent<<" SG="<<sg<<" to xAOD::EventInfo");
136 // Create the xAOD object(s):
137 std::unique_ptr< xAOD::EventInfo > pxAODEventInfo( new xAOD::EventInfo() );
138 std::unique_ptr< xAOD::EventAuxInfo > pxAODEventAuxInfo(new xAOD::EventAuxInfo());
139 pxAODEventInfo->setStore( pxAODEventAuxInfo.get() );
140 pxAODEventInfo->setEvtStore( sg );
141 if( !m_xAODCnvTool->convert( ctx, pEvent, pxAODEventInfo.get(), true, false ).isSuccess() ) {
142 ATH_MSG_ERROR("Failed to convert xAOD::EventInfo in SG");
143 return nullptr;
144 }
145
146 const PileUpEventInfo* pileupEvent(dynamic_cast<const PileUpEventInfo*>(pEvent));
147 if( pileupEvent ) {
148 // Create an EventInfoContainer for the pileup events:
149 std::unique_ptr< xAOD::EventInfoContainer > puei(new xAOD::EventInfoContainer());
150 std::unique_ptr< xAOD::EventInfoAuxContainer > puaux(new xAOD::EventInfoAuxContainer());
151 puei->setStore( puaux.get() );
152
153 // Sub-events for the main EventInfo object:
154 std::vector< xAOD::EventInfo::SubEvent > subEvents;
155
156 // A map translating between the AOD and xAOD pileup event types:
157 static const std::map< PileUpEventInfo::SubEvent::pileup_type,
158 xAOD::EventInfo::PileUpType > pileupTypeMap = {
159#define DECLARE_SE_TYPE( TYPE ) \
160 { PileUpTimeEventIndex::TYPE, xAOD::EventInfo::TYPE },
161
163 DECLARE_SE_TYPE( Signal )
164 DECLARE_SE_TYPE( MinimumBias )
165 DECLARE_SE_TYPE( Cavern )
166 DECLARE_SE_TYPE( HaloGas )
167 DECLARE_SE_TYPE( ZeroBias )
168
169#undef DECLARE_SE_TYPE
170 };
171
172 // A convenience type declaration:
174
175 // Create xAOD::EventInfo objects for each pileup EventInfo object:
176 auto pu_itr = pileupEvent->beginSubEvt();
177 auto pu_end = pileupEvent->endSubEvt();
178 const unsigned int countEvents = std::distance(pu_itr,pu_end);
179 ATH_MSG_VERBOSE( "CHECKING: There are " << countEvents << " subevents in this Event." );
180 for( ; pu_itr != pu_end; ++pu_itr ) {
181 // Create a new xAOD::EventInfo object:
182 std::unique_ptr< xAOD::EventInfo > ei( new xAOD::EventInfo() );
183 // Fill it with information:
184 if( ! m_xAODCnvTool->convert( ctx, pu_itr->pSubEvt, ei.get(), true, false ).isSuccess() ) {
185 ATH_MSG_ERROR("Failed to convert EventInfo to xAOD::EventInfo");
186 continue;
187 }
188
189 StoreGateSvc* tmpSG = pu_itr->pSubEvtSG;
190 if(tmpSG) {
191 ei->setEvtStore(tmpSG);
192 ATH_MSG_VERBOSE("FOUND A STOREGATE");
193 } else {
194 ATH_MSG_ERROR("FAILED TO FIND A STOREGATE");
195 }
196 // Store new EI into the container
197 puei->push_back( ei.release() );
198
199 // And now add a sub-event to the temporary list:
200 auto typeItr = pileupTypeMap.find( pu_itr->type() );
202 if( typeItr == pileupTypeMap.end() ) {
203 ATH_MSG_WARNING( "PileUpType not recognised: " << pu_itr->type() );
204 } else {
205 type = typeItr->second;
206 }
207 ATH_MSG_VERBOSE("PileUpEventInfo: time = " << pu_itr->time() << ", index = " << pu_itr->index());
208 subEvents.push_back( xAOD::EventInfo::SubEvent( pu_itr->time(),
209 pu_itr->index(),
210 type,
211 EiLink( "PileUpEventInfo", puei->size()-1, sg ))); // p_SG?
212 ATH_MSG_VERBOSE("PileUpEventInfo: time = " << subEvents.back().time() << ", index = " << subEvents.back().index());
213 }
214
215 if( subEvents.size() ) {
216 // And now update the main EventInfo object with the sub-events:
217 pxAODEventInfo->setSubEvents( subEvents );
218
219 // Record the xAOD object(s):
220 if( !sg->record( std::move( puaux ), "PileUpEventInfoAux." ).isSuccess()
221 || !sg->record( std::move( puei ), "PileUpEventInfo" ).isSuccess() ) { //MN: FIX - make keys configurable
222 ATH_MSG_ERROR("Failed to record xAOD::EventInfoContainer in SG");
223 }
224 }
225 }
226 // remember pointer to return the new EventInfo
227 // the std::launder avoids a cppcheck warning by breaking
228 // the lifetime connection between the pointer and the unique_ptr.
229 xAODEventInfo = std::launder(pxAODEventInfo.get());
230 // Record the xAOD object(s):
231 const auto ptrVal = pxAODEventInfo.get();//for use in dbg message
232 if( ! sg->record( std::move( pxAODEventAuxInfo ), "EventInfoAux." ).isSuccess() //MN: FIX? key
233 || ! sg->record( std::move( pxAODEventInfo ), "EventInfo" ).isSuccess() ) {
234 ATH_MSG_ERROR("Failed to record the new xAOD::EventInfo in SG");
235 xAODEventInfo = nullptr;
236 }
237 ATH_MSG_DEBUG("Record the new xAOD::EventInfo "<<ptrVal<<" in SG="<<sg);
238 }
239 }
240
241 if( !xAODEventInfo ) {
242 ATH_MSG_DEBUG("Could not find EventInfo '" << einame << "' in store " << sg->name());
243 }
244 return xAODEventInfo;
245}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Old PileUpEventInfo
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
#define DECLARE_SE_TYPE(TYPE)
@ Unknown
Definition TruthClasses.h:9
ToolHandle< xAODMaker::IEventInfoCnvTool > m_xAODCnvTool
property: Handle to the EventInfo -> xAOD::EventInfo converter tool
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
const T * tryConstRetrieve() const
PileUpType
Enumerator describing the types of pileup events.
@ Unknown
Type not known/specified.
EventInfoContainer_v1 EventInfoContainer
Define the latest version of the container.
EventInfoAuxContainer_v1 EventInfoAuxContainer
Define the latest version of the auxiliary container.
EventAuxInfo_v3 EventAuxInfo
Definition of the latest event auxiliary info version.
PileUpTimeEventIndex::PileUpType pileup_type

◆ initialize()

StatusCode PileUpMergeSvc::initialize ( )
overridevirtual

Service initialisation.

Definition at line 78 of file PileUpMergeSvc.cxx.

78 {
79
80 msg() << MSG::INFO << "Initializing " << name() << ", using (xAOD::)EventInfo " << m_EventInfoKeyName << endmsg;
81
82 m_autoRetrieveTools = false;
83 m_checkToolDeps = false;
84
85 // set up the SG service:
86 if ( !(p_overStore.retrieve()).isSuccess() )
87 {
88 msg() << MSG::FATAL
89 << "Could not locate default store"
90 << endmsg;
91 return StatusCode::FAILURE;
92 }
93 if (!m_pITriggerTime.empty() && !(m_pITriggerTime.retrieve()).isSuccess() )
94 {
95 msg() << MSG::FATAL
96 << "Could not locate ITriggerTime tool"
97 << endmsg;
98 return StatusCode::FAILURE;
99 }
100 // Retrieve the converter tool:
101 CHECK(m_xAODCnvTool.retrieve());
102
104
105 // Initialize service:
106 return StatusCode::SUCCESS;
107
108}
#define CHECK(...)
Evaluate an expression and check for errors.
ToolHandle< ITriggerTime > m_pITriggerTime
controls PileUpTimedEventIndex for TimedData returned by retrieveSubEvts
void decodeIntervals()
setup PileUpIntervals

◆ isLive() [1/2]

bool PileUpMergeSvc::isLive ( CLID id,
const std::string & dataKey,
int iXing )
private

Definition at line 249 of file PileUpMergeSvc.cxx.

249 {
250 return m_ranges[make_pair(id, dataKey)].contains(iXing);
251}

◆ isLive() [2/2]

template<typename DATA, typename KEY>
bool PileUpMergeSvc::isLive ( const KEY & key,
int iXing )
private

is iXing live for DATA/key?

◆ msg()

MsgStream & AthCommonMsg< Service >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< Service >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ retrieveOriginal()

template<typename KEY, typename DATA>
StatusCode PileUpMergeSvc::retrieveOriginal ( const KEY & dataKey,
const DATA *& data )

retrieve keyed DATA objs for the original event only

◆ retrieveSingleSubEvtData()

template<typename KEY, typename DATA>
StatusCode PileUpMergeSvc::retrieveSingleSubEvtData ( const KEY & dataKey,
const DATA *& data,
int bunchXing,
SubEventIterator iEvt )

◆ retrieveSubEvtsData() [1/2]

template<typename KEY, typename TIMEDDATA>
StatusCode PileUpMergeSvc::retrieveSubEvtsData ( const KEY & dataKey,
TIMEDDATA & timedData )

retrieve keyed DATA objs for all sub-events and attach a time to them

◆ retrieveSubEvtsData() [2/2]

template<typename KEY, typename TIMEDDATA>
StatusCode PileUpMergeSvc::retrieveSubEvtsData ( const KEY & dataKey,
TIMEDDATA & timedData,
unsigned int & numberOfSimHits )

retrieve keyed DATA objs for all sub-events and attach a time to them

◆ retrieveSubSetEvtData()

template<typename KEY, typename TIMEDDATA>
StatusCode PileUpMergeSvc::retrieveSubSetEvtData ( const KEY & dataKey,
TIMEDDATA & timedData,
int bunchXing,
SubEventIterator bSubEvents,
SubEventIterator eSubEvents )

Member Data Documentation

◆ ATLAS_THREAD_SAFE

SG::SlotSpecificObj<std::mutex> m_slotMutex PileUpMergeSvc::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 124 of file PileUpMergeSvc.h.

◆ m_EventInfoKeyName

StringProperty PileUpMergeSvc::m_EventInfoKeyName
private
Initial value:
{this, "EventInfoKeyName", "OverlayEvent",
"default name for EventInfo"}

Definition at line 184 of file PileUpMergeSvc.h.

184 {this, "EventInfoKeyName", "OverlayEvent",
185 "default name for EventInfo"};

◆ m_intervals

ToolHandleArray<IPileUpXingFolder> PileUpMergeSvc::m_intervals
private
Initial value:
{this, "Intervals", {},
"Folders specifying bunch xing intervals for different data objects"}

Definition at line 119 of file PileUpMergeSvc.h.

119 {this, "Intervals", {},
120 "Folders specifying bunch xing intervals for different data objects"};

◆ m_pITriggerTime

ToolHandle<ITriggerTime> PileUpMergeSvc::m_pITriggerTime
private
Initial value:
{this, "TriggerTimeTool", "",
"allows to apply a trigger time offset"}

controls PileUpTimedEventIndex for TimedData returned by retrieveSubEvts

Definition at line 173 of file PileUpMergeSvc.h.

173 {this, "TriggerTimeTool", "",
174 "allows to apply a trigger time offset"};

◆ m_ranges

RangeContainer PileUpMergeSvc::m_ranges
private

Definition at line 171 of file PileUpMergeSvc.h.

◆ m_returnTimedData

BooleanProperty PileUpMergeSvc::m_returnTimedData
private
Initial value:
{this, "ReturnTimedData", true,
"determine whether the TimedData returned by retrieveSubEvts have non trivial "
"PileUpTimeEventIndex. May be set to false for overlay with real events"}

Definition at line 177 of file PileUpMergeSvc.h.

177 {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"};

◆ m_xAODCnvTool

ToolHandle< xAODMaker::IEventInfoCnvTool > PileUpMergeSvc::m_xAODCnvTool
private
Initial value:
{
this, "xAODCnvTool", "xAODMaker::EventInfoCnvTool/EventInfoCnvTool"}

property: Handle to the EventInfo -> xAOD::EventInfo converter tool

Definition at line 188 of file PileUpMergeSvc.h.

188 {
189 this, "xAODCnvTool", "xAODMaker::EventInfoCnvTool/EventInfoCnvTool"};

◆ p_overStore

ServiceHandle<StoreGateSvc> PileUpMergeSvc::p_overStore
private

overlaid SG (default)

Definition at line 118 of file PileUpMergeSvc.h.


The documentation for this class was generated from the following files: