ATLAS Offline Software
ReadMeta.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "ReadMeta.h"
12 
13 // the user data-class defintions
15 
16 #include "GaudiKernel/IIncidentSvc.h"
17 #include "GaudiKernel/FileIncident.h"
18 
19 #include "StoreGate/StoreGateSvc.h"
20 
21 using namespace AthPoolEx;
22 
23 //___________________________________________________________________________
24 ReadMeta::ReadMeta(const std::string& type, const std::string& name, const IInterface* parent) :
26  m_pMetaDataStore ("StoreGateSvc/MetaDataStore", name),
27  m_pInputStore ("StoreGateSvc/InputMetaDataStore", name) {
28  declareInterface<IMetaDataTool>(this);
29 }
30 //___________________________________________________________________________
32 }
33 //___________________________________________________________________________
35  ATH_MSG_INFO("in initialize()");
36 
37  // locate the DetectorStore and initialize our local ptr
38  if (!m_pMetaDataStore.retrieve().isSuccess()) {
39  ATH_MSG_ERROR("Could not find MetaDataStore");
40  return StatusCode::FAILURE;
41  }
42  if (!m_pInputStore.retrieve().isSuccess()) {
43  ATH_MSG_ERROR("Could not find InputMetaDataStore");
44  return StatusCode::FAILURE;
45  }
46  // Set to be listener for end of event
47  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", this->name());
48  if (!incSvc.retrieve().isSuccess()) {
49  ATH_MSG_ERROR("Unable to get the IncidentSvc");
50  return StatusCode::FAILURE;
51  }
52  incSvc->addListener(this, "BeginInputFile", 60); // pri has to be < 100 to be after MetaDataSvc.
53  incSvc->addListener(this, "EndInputFile", 50); // pri has to be > 10 to be before MetaDataSvc.
54  return StatusCode::SUCCESS;
55 }
56 //___________________________________________________________________________
58  ATH_MSG_INFO("in finalize()");
59  return StatusCode::SUCCESS;
60 }
61 //__________________________________________________________________________
62 void ReadMeta::handle(const Incident& inc) {
63  ATH_MSG_DEBUG("handle() " << inc.type());
64  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
65  if (fileInc == 0) {
66  ATH_MSG_ERROR(" Unable to get FileName from BeginInputFile/EndInputFile incident");
67  return;
68  }
69  const std::string fileName = fileInc->fileName();
70  ATH_MSG_DEBUG("handle() " << inc.type() << " for " << fileName);
71 
72 }
73 //__________________________________________________________________________
75 {
76  ATH_MSG_DEBUG("saw BeginInputFile incident.");
77  if (m_pInputStore->contains<ExampleHitContainer>("PedestalWriteData")) {
78  std::list<SG::ObjectWithVersion<ExampleHitContainer> > allVersions;
79  if (m_pInputStore->retrieveAllVersions(allVersions, "PedestalWriteData").isFailure()) {
80  ATH_MSG_ERROR("Could not retrieve all versions for PedestalWriteData");
81  return StatusCode::FAILURE;
82  }
83  //const ExampleHitContainer* ep;
84  ExampleHitContainer* ep_out = 0;
85  for (SG::ObjectWithVersion<ExampleHitContainer>& obj : allVersions) {
86  const ExampleHitContainer* ep = obj.dataObject.cptr();
87  if (!m_pMetaDataStore->contains<ExampleHitContainer>("PedestalWriteData")) {
88  ep_out = new ExampleHitContainer();
89  const ExampleHit* entry = *ep->begin();
90  ExampleHit* entry_out = new ExampleHit();
91  entry_out->setX(entry->getX());
92  entry_out->setY(entry->getY());
93  entry_out->setZ(entry->getZ());
94  entry_out->setDetector(entry->getDetector());
95  ep_out->push_back(entry_out);
96  if (m_pMetaDataStore->record(ep_out, "PedestalWriteData").isFailure()) {
97  ATH_MSG_ERROR("Could not record DataObject: PedestalWriteData");
98  return StatusCode::FAILURE;
99  }
100  } else {
101  if (m_pMetaDataStore->retrieve(ep_out, "PedestalWriteData").isFailure()) {
102  ATH_MSG_ERROR("Could not find DataObject in output: PedestalWriteData");
103  return StatusCode::FAILURE;
104  }
105  const ExampleHit* entry = *ep->begin();
106  ExampleHit* entry_out = *ep_out->begin();
107  int weight = entry->getDetector().size() - 2;
108  int weight_out = entry_out->getDetector().size() - 2;
109  entry_out->setX((entry->getX() * weight + entry_out->getX() * weight_out) / (weight + weight_out));
110  entry_out->setY((entry->getY() * weight + entry_out->getY() * weight_out) / (weight + weight_out));
111  entry_out->setZ((entry->getZ() * weight + entry_out->getZ() * weight_out) / (weight + weight_out));
112  entry_out->setDetector(entry->getDetector().substr(0, entry->getDetector().size() - 1) + entry_out->getDetector().substr(1));
113  }
114  }
115  if (ep_out != 0) {
116  for (const ExampleHit* obj : *ep_out) {
117  ATH_MSG_INFO("Pedestal x = " << obj->getX() << " y = " << obj->getY() << " z = " << obj->getZ() << " string = " << obj->getDetector());
118  }
119  }
120  }
121 
122  return StatusCode::SUCCESS;
123 }
124 //__________________________________________________________________________
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthPoolEx::ReadMeta::initialize
StatusCode initialize()
Gaudi Service Interface method implementations:
Definition: ReadMeta.cxx:34
ExampleHit::setY
void setY(double y)
Set the Y coordinate.
Definition: ExampleHit.h:51
AthPoolEx::ReadMeta::m_pMetaDataStore
ServiceHandle< StoreGateSvc > m_pMetaDataStore
Definition: ReadMeta.h:61
ExampleHit::getY
double getY() const
Definition: ExampleHit.h:37
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthPoolEx::ReadMeta::~ReadMeta
virtual ~ReadMeta()
Destructor.
Definition: ReadMeta.cxx:31
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ExampleHit::getX
double getX() const
Definition: ExampleHit.h:34
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthPoolEx::ReadMeta::ReadMeta
ReadMeta(const std::string &type, const std::string &name, const IInterface *parent)
Standard Service Constructor.
Definition: ReadMeta.cxx:24
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ExampleHit
This class provides a dummy hit data object for AthenaPool.
Definition: ExampleHit.h:24
ExampleHit::getZ
double getZ() const
Definition: ExampleHit.h:40
ReadMeta.h
This file contains the class definition for the ReadMeta class.
ExampleHit::setX
void setX(double x)
Set the X coordinate.
Definition: ExampleHit.h:47
ExampleHit::getDetector
const std::string & getDetector() const
Definition: ExampleHit.h:43
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
AthPoolEx::ReadMeta::m_pInputStore
ServiceHandle< StoreGateSvc > m_pInputStore
Definition: ReadMeta.h:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
AthPoolEx::ReadMeta::finalize
StatusCode finalize()
Definition: ReadMeta.cxx:57
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthPoolEx::ReadMeta::handle
void handle(const Incident &incident)
Incident service handle listening for BeginInputFile and EndInputFile.
Definition: ReadMeta.cxx:62
AthPoolEx
Definition: PassNoneFilter.h:16
ExampleHitContainer.h
This file contains the class definition for the ExampleHitContainer class.
AthAlgTool
Definition: AthAlgTool.h:26
SG::ObjectWithVersion
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
Definition: SGVersionedKey.h:17
python.PyAthena.obj
obj
Definition: PyAthena.py:132
ExampleHitContainer
This class provides a data vector for ExampleHit objects in AthenaPool.
Definition: ExampleHitContainer.h:20
StoreGateSvc.h
ExampleHit::setZ
void setZ(double z)
Set the Z coordinate.
Definition: ExampleHit.h:55
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
ServiceHandle< IIncidentSvc >
AthPoolEx::ReadMeta::beginInputFile
virtual StatusCode beginInputFile()
Function called when a new input file is opened.
Definition: ReadMeta.cxx:74
ExampleHit::setDetector
void setDetector(const std::string &detector)
Set the detector string.
Definition: ExampleHit.h:59