ATLAS Offline Software
PixelOverlay.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
9 #include "StoreGate/ReadHandle.h"
10 #include "StoreGate/WriteHandle.h"
11 
12 #include "AthAllocators/DataPool.h"
13 
14 namespace Overlay
15 {
16 
18  bool operator()(PixelRDORawData *digit1, PixelRDORawData *digit2) {
19  return digit1->identify() < digit2->identify();
20  }
22 
23 // Specialize mergeChannelData() for the Pixel
24 template <>
25 void mergeChannelData(PixelRDORawData & /* baseDatum */,
26  const PixelRDORawData & /* additionalDatum */,
27  const IDC_OverlayBase *algorithm) {
28  algorithm->msg(MSG::DEBUG) << "Overlay::mergeChannelData<PixelRDORawData>(): "
29  << "Merging of data on the same channel is not "
30  "explicitly implemented for PixelRDORawData"
31  << endmsg;
32 }
33 
34 // Specialize copyCollection() for the Pixel
35 template <>
36 std::unique_ptr<PixelRDO_Collection> copyCollection(
37  const IdentifierHash &hashId, const PixelRDO_Collection *collection,
38  DataPool<Pixel1RawData> &dataItems) {
39  auto outputCollection = std::make_unique<PixelRDO_Collection>(hashId);
40  outputCollection->setIdentifier(collection->identify());
42  outputCollection->reserve(collection->size());
43  for (const PixelRDORawData *existingDatum : *collection) {
44  Pixel1RawData *datumCopy = dataItems.nextElementPtr();
45  (*datumCopy) =
46  Pixel1RawData(existingDatum->identify(), existingDatum->getWord());
47  outputCollection->push_back(datumCopy);
48  }
49  return outputCollection;
50 }
51 
52 // Specizlize sortCollection() for the Pixel
53 template <>
55  if (!std::is_sorted(collection->begin(), collection->end(), PixelRDOSorterObject)) {
56  std::stable_sort(collection->begin(), collection->end(), PixelRDOSorterObject);
57  }
58 }
59 
60 } // namespace Overlay
61 
62 
63 PixelOverlay::PixelOverlay(const std::string &name, ISvcLocator *pSvcLocator)
64  : IDC_OverlayBase(name, pSvcLocator)
65 {
66 }
67 
69 {
70  ATH_MSG_DEBUG("Initializing...");
71 
72  // Check and initialize keys
74  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey);
76  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey);
78  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
79 
80  return StatusCode::SUCCESS;
81 }
82 
83 StatusCode PixelOverlay::execute(const EventContext& ctx) const
84 {
85  ATH_MSG_DEBUG("execute() begin");
86 
87  // Reading the input RDOs
88  ATH_MSG_VERBOSE("Retrieving input RDO containers");
89 
90  const PixelRDO_Container *bkgContainerPtr = nullptr;
91  if (!m_bkgInputKey.empty()) {
93  if (!bkgContainer.isValid()) {
94  ATH_MSG_ERROR("Could not get background Pixel RDO container " << bkgContainer.name() << " from store " << bkgContainer.store());
95  return StatusCode::FAILURE;
96  }
97  bkgContainerPtr = bkgContainer.cptr();
98 
99  ATH_MSG_DEBUG("Found background Pixel RDO container " << bkgContainer.name() << " in store " << bkgContainer.store());
100  ATH_MSG_DEBUG("Pixel Background = " << Overlay::debugPrint(bkgContainer.cptr()));
101  }
102 
104  if (!signalContainer.isValid()) {
105  ATH_MSG_ERROR("Could not get signal Pixel RDO container " << signalContainer.name() << " from store " << signalContainer.store());
106  return StatusCode::FAILURE;
107  }
108  ATH_MSG_DEBUG("Found signal Pixel RDO container " << signalContainer.name() << " in store " << signalContainer.store());
109  ATH_MSG_DEBUG("Pixel Signal = " << Overlay::debugPrint(signalContainer.cptr()));
110 
111  // Creating output RDO container
112  SG::WriteHandle<PixelRDO_Container> outputContainer(m_outputKey, ctx);
113  ATH_CHECK(outputContainer.record(std::make_unique<PixelRDO_Container>(signalContainer->size())));
114  if (!outputContainer.isValid()) {
115  ATH_MSG_ERROR("Could not record output Pixel RDO container " << outputContainer.name() << " to store " << outputContainer.store());
116  return StatusCode::FAILURE;
117  }
118  ATH_MSG_DEBUG("Recorded output Pixel RDO container " << outputContainer.name() << " in store " << outputContainer.store());
119  // The DataPool, this is what will actually own the elements
120  // we create during this algorithm. The containers are views.
121  DataPool<Pixel1RawData> dataItemsPool(ctx);
122  // It resizes but lets reserve already quite a few
123  dataItemsPool.prepareToAdd(100000);
124  ATH_CHECK(overlayContainerWithSorting(bkgContainerPtr, signalContainer.cptr(), outputContainer.ptr(), dataItemsPool));
125  ATH_MSG_DEBUG("Pixel Result = " << Overlay::debugPrint(outputContainer.ptr()));
126 
127  ATH_MSG_DEBUG("execute() end");
128  return StatusCode::SUCCESS;
129 }
IDC_OverlayHelpers.h
algorithm
std::string algorithm
Definition: hcg.cxx:82
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
InDetRawDataCollection::identify
virtual Identifier identify() const override final
IdentifiableContainerMT::size
size_t size() const
Duplicate of fullSize for backwards compatability.
Definition: IdentifiableContainerMT.h:206
Overlay::sortCollection
void sortCollection(PixelRDO_Collection *collection)
Definition: PixelOverlay.cxx:54
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
Overlay::mergeChannelData
void mergeChannelData(HGTD_RDO &, const HGTD_RDO &, const IDC_OverlayBase *algorithm)
Definition: HGTD_Overlay.cxx:14
WriteHandle.h
Handle class for recording to StoreGate.
PixelOverlay::m_outputKey
SG::WriteHandleKey< PixelRDO_Container > m_outputKey
Definition: PixelOverlay.h:23
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
PixelOverlay::initialize
virtual StatusCode initialize() override final
Definition: PixelOverlay.cxx:68
PixelOverlay::m_signalInputKey
SG::ReadHandleKey< PixelRDO_Container > m_signalInputKey
Definition: PixelOverlay.h:22
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DataPool::prepareToAdd
void prepareToAdd(unsigned int size)
Prepare to add cached elements.
Overlay::copyCollection
std::unique_ptr< HGTD_RDO_Collection > copyCollection(const IdentifierHash &hashId, const HGTD_RDO_Collection *collection)
Definition: HGTD_Overlay.cxx:24
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PixelOverlay::m_bkgInputKey
SG::ReadHandleKey< PixelRDO_Container > m_bkgInputKey
Definition: PixelOverlay.h:21
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:382
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
PixelOverlay::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PixelOverlay.cxx:83
Pixel1RawData
Definition: Pixel1RawData.h:23
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
IDC_OverlayBase::overlayContainerWithSorting
StatusCode overlayContainerWithSorting(const IDC_Container *bkgContainer, const IDC_Container *signalContainer, IDC_Container *outputContainer, DataPool< Type > &dataItems) const
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DataPool.h
Overlay::PixelRDOSorterObject
struct Overlay::PixelRDOSorter PixelRDOSorterObject
postInclude.outputCollection
outputCollection
Definition: postInclude.SortInput.py:27
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
Overlay::PixelRDOSorter::operator()
bool operator()(PixelRDORawData *digit1, PixelRDORawData *digit2)
Definition: PixelOverlay.cxx:18
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DEBUG
#define DEBUG
Definition: page_access.h:11
Overlay
Helpers for overlaying Identifiable Containers.
Definition: HGTD_Overlay.cxx:11
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:63
IDC_OverlayBase
Definition: IDC_OverlayBase.h:25
PixelRDORawData
Definition: PixelRDORawData.h:23
PixelOverlay::PixelOverlay
PixelOverlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelOverlay.cxx:63
InDetRawData::identify
virtual Identifier identify() const override final
Definition: InDetRawData.h:41
ReadHandle.h
Handle class for reading from StoreGate.
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
Overlay::debugPrint
std::string debugPrint(const IDC_Container *container, unsigned numprint=25)
Diagnostic output of Identifiable Containers.
PixelOverlay.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Overlay::PixelRDOSorter
Definition: PixelOverlay.cxx:17