ATLAS Offline Software
PixelOverlay.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 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 
17 // Specialize mergeChannelData() for the Pixel
18 template <>
19 void mergeChannelData(PixelRDORawData & /* baseDatum */,
20  const PixelRDORawData & /* additionalDatum */,
21  const IDC_OverlayBase *algorithm) {
22  algorithm->msg(MSG::DEBUG) << "Overlay::mergeChannelData<PixelRDORawData>(): "
23  << "Merging of data on the same channel is not "
24  "explicitly implemented for PixelRDORawData"
25  << endmsg;
26 }
27 
28 // Specialize copyCollection() for the Pixel
29 template <>
30 std::unique_ptr<PixelRDO_Collection> copyCollection(
31  const IdentifierHash &hashId, const PixelRDO_Collection *collection,
32  DataPool<Pixel1RawData> &dataItems) {
33  auto outputCollection = std::make_unique<PixelRDO_Collection>(hashId);
34  outputCollection->setIdentifier(collection->identify());
36  outputCollection->reserve(collection->size());
37  for (const PixelRDORawData *existingDatum : *collection) {
38  Pixel1RawData *datumCopy = dataItems.nextElementPtr();
39  (*datumCopy) =
40  Pixel1RawData(existingDatum->identify(), existingDatum->getWord());
41  outputCollection->push_back(datumCopy);
42  }
43  return outputCollection;
44 }
45 } // namespace Overlay
46 
47 
48 PixelOverlay::PixelOverlay(const std::string &name, ISvcLocator *pSvcLocator)
49  : IDC_OverlayBase(name, pSvcLocator)
50 {
51 }
52 
54 {
55  ATH_MSG_DEBUG("Initializing...");
56 
57  // Check and initialize keys
58  ATH_CHECK( m_bkgInputKey.initialize(!m_bkgInputKey.key().empty()) );
59  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_bkgInputKey);
60  ATH_CHECK( m_signalInputKey.initialize() );
61  ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_signalInputKey);
62  ATH_CHECK( m_outputKey.initialize() );
63  ATH_MSG_VERBOSE("Initialized WriteHandleKey: " << m_outputKey);
64 
65  return StatusCode::SUCCESS;
66 }
67 
68 StatusCode PixelOverlay::execute(const EventContext& ctx) const
69 {
70  ATH_MSG_DEBUG("execute() begin");
71 
72  // Reading the input RDOs
73  ATH_MSG_VERBOSE("Retrieving input RDO containers");
74 
75  const PixelRDO_Container *bkgContainerPtr = nullptr;
76  if (!m_bkgInputKey.empty()) {
78  if (!bkgContainer.isValid()) {
79  ATH_MSG_ERROR("Could not get background Pixel RDO container " << bkgContainer.name() << " from store " << bkgContainer.store());
80  return StatusCode::FAILURE;
81  }
82  bkgContainerPtr = bkgContainer.cptr();
83 
84  ATH_MSG_DEBUG("Found background Pixel RDO container " << bkgContainer.name() << " in store " << bkgContainer.store());
85  ATH_MSG_DEBUG("Pixel Background = " << Overlay::debugPrint(bkgContainer.cptr()));
86  }
87 
89  if (!signalContainer.isValid()) {
90  ATH_MSG_ERROR("Could not get signal Pixel RDO container " << signalContainer.name() << " from store " << signalContainer.store());
91  return StatusCode::FAILURE;
92  }
93  ATH_MSG_DEBUG("Found signal Pixel RDO container " << signalContainer.name() << " in store " << signalContainer.store());
94  ATH_MSG_DEBUG("Pixel Signal = " << Overlay::debugPrint(signalContainer.cptr()));
95 
96  // Creating output RDO container
98  ATH_CHECK(outputContainer.record(std::make_unique<PixelRDO_Container>(signalContainer->size())));
99  if (!outputContainer.isValid()) {
100  ATH_MSG_ERROR("Could not record output Pixel RDO container " << outputContainer.name() << " to store " << outputContainer.store());
101  return StatusCode::FAILURE;
102  }
103  ATH_MSG_DEBUG("Recorded output Pixel RDO container " << outputContainer.name() << " in store " << outputContainer.store());
104  // The DataPool, this is what will actually own the elements
105  // we create during this algorithm. The containers are views.
106  DataPool<Pixel1RawData> dataItemsPool(ctx);
107  // It resizes but lets reserve already quite a few
108  dataItemsPool.prepareToAdd(100000);
109  ATH_CHECK(overlayContainer(bkgContainerPtr, signalContainer.cptr(), outputContainer.ptr(), dataItemsPool));
110  ATH_MSG_DEBUG("Pixel Result = " << Overlay::debugPrint(outputContainer.ptr()));
111 
112  ATH_MSG_DEBUG("execute() end");
113  return StatusCode::SUCCESS;
114 }
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:70
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:209
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
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
PixelOverlay::initialize
virtual StatusCode initialize() override final
Definition: PixelOverlay.cxx:53
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
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:379
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
IDC_OverlayBase::overlayContainer
StatusCode overlayContainer(const IDC_Container *bkgContainer, const IDC_Container *signalContainer, IDC_Container *outputContainer) const
PixelOverlay::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PixelOverlay.cxx:68
Pixel1RawData
Definition: Pixel1RawData.h:23
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DataPool.h
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:195
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
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:47
IDC_OverlayBase
Definition: IDC_OverlayBase.h:25
PixelRDORawData
Definition: PixelRDORawData.h:23
PixelOverlay::PixelOverlay
PixelOverlay(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelOverlay.cxx:48
DataPool::prepareToAdd
void prepareToAdd(unsigned int size)
Prepare to add cached elements.
ReadHandle.h
Handle class for reading from StoreGate.
IdentifierHash
Definition: IdentifierHash.h:38
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.