ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
AthenaPOOL
AthenaPoolExample
AthenaPoolExampleAlgorithms
src
ReadMeta.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
9
10
#include "
ReadMeta.h
"
11
12
// the user data-class definitions
13
#include "
AthenaPoolExampleData/ExampleHitContainer.h
"
14
15
#include "GaudiKernel/IIncidentSvc.h"
16
#include "GaudiKernel/FileIncident.h"
17
18
#include "
StoreGate/StoreGateSvc.h
"
19
20
using namespace
AthPoolEx
;
21
22
//___________________________________________________________________________
23
ReadMeta::ReadMeta
(
const
std::string&
type
,
const
std::string& name,
const
IInterface* parent) :
24
base_class(
type
, name, parent),
25
m_pMetaDataStore
(
"StoreGateSvc/MetaDataStore"
, name),
26
m_pInputStore
(
"StoreGateSvc/InputMetaDataStore"
, name) {
27
}
28
//___________________________________________________________________________
29
StatusCode
ReadMeta::initialize
() {
30
ATH_MSG_INFO
(
"in initialize()"
);
31
32
// locate the DetectorStore and initialize our local ptr
33
ATH_CHECK
(
m_pMetaDataStore
.retrieve() );
34
ATH_CHECK
(
m_pInputStore
.retrieve() );
35
36
// Set to be listener for end of event
37
ServiceHandle<IIncidentSvc>
incSvc(
"IncidentSvc"
, this->name());
38
ATH_CHECK
( incSvc.retrieve() );
39
incSvc->addListener(
this
,
"BeginInputFile"
, 60);
// pri has to be < 100 to be after MetaDataSvc.
40
incSvc->addListener(
this
,
"EndInputFile"
, 50);
// pri has to be > 10 to be before MetaDataSvc.
41
return
StatusCode::SUCCESS;
42
}
43
//__________________________________________________________________________
44
void
ReadMeta::handle
(
const
Incident& inc) {
45
ATH_MSG_DEBUG
(
"handle() "
<< inc.type());
46
const
FileIncident* fileInc =
dynamic_cast<
const
FileIncident*
>
(&inc);
47
if
(fileInc ==
nullptr
) {
48
ATH_MSG_ERROR
(
" Unable to get FileName from BeginInputFile/EndInputFile incident"
);
49
return
;
50
}
51
ATH_MSG_DEBUG
(
"handle() "
<< inc.type() <<
" for "
<< fileInc->fileName());
52
}
53
//__________________________________________________________________________
54
StatusCode
ReadMeta::beginInputFile
(
const
SG::SourceID
&)
55
{
56
ATH_MSG_DEBUG
(
"saw BeginInputFile incident."
);
57
if
(
m_pInputStore
->contains<
ExampleHitContainer
>(
"PedestalWriteData"
)) {
58
std::list<SG::ObjectWithVersion<ExampleHitContainer> > allVersions;
59
ATH_CHECK
(
m_pInputStore
->retrieveAllVersions(allVersions,
"PedestalWriteData"
) );
60
//const ExampleHitContainer* ep;
61
ExampleHitContainer
* ep_out =
nullptr
;
62
for
(
SG::ObjectWithVersion<ExampleHitContainer>
& obj : allVersions) {
63
const
ExampleHitContainer
* ep = obj.dataObject.cptr();
64
if
(!
m_pMetaDataStore
->contains<
ExampleHitContainer
>(
"PedestalWriteData"
)) {
65
auto
ep_out_unique = std::make_unique<ExampleHitContainer>();
66
const
ExampleHit
* entry = *ep->
begin
();
67
auto
entry_out = std::make_unique<ExampleHit>();
68
entry_out->setX(entry->getX());
69
entry_out->setY(entry->getY());
70
entry_out->setZ(entry->getZ());
71
entry_out->setDetector(entry->getDetector());
72
ep_out_unique->push_back(std::move(entry_out));
73
ep_out = ep_out_unique.
get
();
74
ATH_CHECK
(
m_pMetaDataStore
->record(std::move(ep_out_unique),
"PedestalWriteData"
) );
75
}
else
{
76
ATH_CHECK
(
m_pMetaDataStore
->retrieve(ep_out,
"PedestalWriteData"
) );
77
const
ExampleHit
* entry = *ep->
begin
();
78
ExampleHit
* entry_out = *ep_out->
begin
();
79
int
weight = entry->getDetector().size() - 2;
80
int
weight_out = entry_out->
getDetector
().size() - 2;
81
entry_out->
setX
((entry->getX() * weight + entry_out->
getX
() * weight_out) / (weight + weight_out));
82
entry_out->
setY
((entry->getY() * weight + entry_out->
getY
() * weight_out) / (weight + weight_out));
83
entry_out->
setZ
((entry->getZ() * weight + entry_out->
getZ
() * weight_out) / (weight + weight_out));
84
entry_out->
setDetector
(entry->getDetector().substr(0, entry->getDetector().size() - 1) + entry_out->
getDetector
().substr(1));
85
}
86
}
87
if
(ep_out !=
nullptr
) {
88
for
(
const
ExampleHit
* obj : *ep_out) {
89
ATH_MSG_INFO
(
"Pedestal x = "
<< obj->getX() <<
" y = "
<< obj->getY() <<
" z = "
<< obj->getZ() <<
" string = "
<< obj->getDetector());
90
}
91
}
92
}
93
94
return
StatusCode::SUCCESS;
95
}
96
//__________________________________________________________________________
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
ExampleHitContainer.h
This file contains the class definition for the ExampleHitContainer class.
ReadMeta.h
This file contains the class definition for the ReadMeta class.
StoreGateSvc.h
AthPoolEx::ReadMeta::beginInputFile
virtual StatusCode beginInputFile(const SG::SourceID &) override final
Function called when a new input file is opened.
Definition
ReadMeta.cxx:54
AthPoolEx::ReadMeta::m_pMetaDataStore
ServiceHandle< StoreGateSvc > m_pMetaDataStore
Definition
ReadMeta.h:48
AthPoolEx::ReadMeta::ReadMeta
ReadMeta(const std::string &type, const std::string &name, const IInterface *parent)
Definition
ReadMeta.cxx:23
AthPoolEx::ReadMeta::handle
virtual void handle(const Incident &incident) override final
Incident service handle listening for BeginInputFile and EndInputFile.
Definition
ReadMeta.cxx:44
AthPoolEx::ReadMeta::m_pInputStore
ServiceHandle< StoreGateSvc > m_pInputStore
Definition
ReadMeta.h:49
AthPoolEx::ReadMeta::initialize
virtual StatusCode initialize() override final
Gaudi AlgTool Interface method implementations:
Definition
ReadMeta.cxx:29
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
ExampleHitContainer
This class provides a data vector for ExampleHit objects in AthenaPool.
Definition
ExampleHitContainer.h:20
ExampleHit
This class provides a dummy hit data object for AthenaPool.
Definition
ExampleHit.h:24
ExampleHit::setZ
void setZ(double z)
Set the Z coordinate.
Definition
ExampleHit.h:55
ExampleHit::setX
void setX(double x)
Set the X coordinate.
Definition
ExampleHit.h:47
ExampleHit::getZ
double getZ() const
Definition
ExampleHit.h:40
ExampleHit::setDetector
void setDetector(const std::string &detector)
Set the detector string.
Definition
ExampleHit.h:59
ExampleHit::getX
double getX() const
Definition
ExampleHit.h:34
ExampleHit::setY
void setY(double y)
Set the Y coordinate.
Definition
ExampleHit.h:51
ExampleHit::getY
double getY() const
Definition
ExampleHit.h:37
ExampleHit::getDetector
const std::string & getDetector() const
Definition
ExampleHit.h:43
SG::ObjectWithVersion
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
Definition
SGObjectWithVersion.h:20
ServiceHandle
Definition
ClusterMakerTool.h:36
AthPoolEx
Definition
PassNoneFilter.h:16
SG::SourceID
std::string SourceID
Definition
AthenaKernel/AthenaKernel/SourceID.h:25
type
Generated on
for ATLAS Offline Software by
1.17.0