ATLAS Offline Software
ByteStreamMetadataTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3  */
4 
10 #include "ByteStreamMetadataTool.h"
11 
13 #include "StoreGate/StoreGateSvc.h"
14 
15 
16 /******************************************************************************/
18  const std::string& type,
19  const std::string& name,
20  const IInterface* parent)
22  , m_metadataStore("StoreGateSvc/MetaDataStore", name)
23  , m_inputStore ("StoreGateSvc/InputMetaDataStore", name)
24 {
25  declareInterface<IMetaDataTool>(this);
26 }
27 
28 
29 /******************************************************************************/
31 {}
32 
33 
34 /******************************************************************************/
37 {
38  ATH_MSG_INFO("Initializing");
39 
41  ATH_CHECK(m_metadataStore.retrieve());
42  ATH_CHECK(m_inputStore.retrieve());
43 
44  return(StatusCode::SUCCESS);
45 }
46 
47 
48 /******************************************************************************/
51 {
52  ATH_MSG_INFO("in finalize()");
53  return(::AthAlgTool::finalize());
54 }
55 
56 
57 /******************************************************************************/
60 {
61  return this->beginInputFile();
62 }
63 
64 
65 /******************************************************************************/
68 {
69  std::set<std::string> keys = keysFromInput();
70 
71  std::vector<std::unique_ptr<ByteStreamMetadata> > copy;
72  std::set<std::string> transGuids;
73 
74 
75  for(const auto& key : keys) {
76  ATH_MSG_DEBUG("Processing Input ByteStreamMetadata, key = " << key);
77  copy.clear();
78 
79  if(m_inputStore->contains<ByteStreamMetadata>(key)) {
80 
81  std::list<SG::ObjectWithVersion<ByteStreamMetadata> > allVersions;
82  ATH_CHECK(m_inputStore->retrieveAllVersions(allVersions, key));
83 
85  copy.push_back(std::make_unique<ByteStreamMetadata>(*obj.dataObject));
86 
87  }
88 
89 
91 
92  std::list<SG::ObjectWithVersion<ByteStreamMetadataContainer> > allVersions;
93  ATH_CHECK(m_inputStore->retrieveAllVersions(allVersions, key));
94 
96  for(const ByteStreamMetadata* md : *obj.dataObject)
97  copy.push_back(std::make_unique<ByteStreamMetadata>(*md));
98  }
99 
100 
101  if(!copy.empty()) {
102 
103  transGuids.clear();
104  // Check for existing container
105  ByteStreamMetadataContainer* bsmdc = 0;
106 
108 
109  ATH_MSG_DEBUG("Pre-existing ByteStreamMetadataContainer found");
110  ATH_CHECK(m_metadataStore->retrieve(bsmdc, key));
111 
112  for (const auto bsmd : *bsmdc)
113  transGuids.insert(bsmd->getGuid());
114 
115  } else {
116 
117  bsmdc = new ByteStreamMetadataContainer;
118  ATH_CHECK(m_metadataStore->record(bsmdc, key));
119 
120  }
121 
122  for(auto& pBSMD : copy) {
123  // Only insert new metadata records (with GUID not yet in container)
124  if(transGuids.insert(pBSMD->getGuid()).second)
125  bsmdc->push_back(std::move(pBSMD));
126  }
127  }
128  }
129 
130  return StatusCode::SUCCESS;
131 }
132 
133 
134 
135 /******************************************************************************/
136 inline
137 std::set<std::string>
139 {
140  std::vector<std::string> vKeys;
141  std::set<std::string> keys;
142 
144  keys.insert(vKeys.begin(), vKeys.end());
145 
147  keys.insert(vKeys.begin(), vKeys.end());
148 
149  return keys;
150 }
151 
152 
153 /******************************************************************************/
156 {
157  return StatusCode::SUCCESS;
158 }
159 
160 
163 {
164  return StatusCode::SUCCESS;
165 }
166 
167 
170 {
171  return StatusCode::SUCCESS;
172 }
173 
174 
177 {
178  return StatusCode::SUCCESS;
179 }
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
ByteStreamMetadataTool::ByteStreamMetadataTool
ByteStreamMetadataTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Service Constructor.
Definition: ByteStreamMetadataTool.cxx:17
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ByteStreamMetadataTool.h
This file contains the class definition for the ByteStreamMetadataTool class.
ByteStreamMetadataTool::finalize
StatusCode finalize()
Definition: ByteStreamMetadataTool.cxx:50
initialize
void initialize()
Definition: run_EoverP.cxx:894
ByteStreamMetadataContainer.h
This file contains the class definition for the ByteStreamMetadataContainer class.
ByteStreamMetadataTool::endInputFile
virtual StatusCode endInputFile()
Definition: ByteStreamMetadataTool.cxx:162
ByteStreamMetadata
This class is the StoreGate data object for bytestream metadata.
Definition: ByteStreamMetadata.h:25
ByteStreamMetadataContainer
This class is the StoreGate data object for bytestream metadata.
Definition: ByteStreamMetadataContainer.h:22
ByteStreamMetadataContainer
ByteStreamMetadataContainer
Definition: ByteStreamEventTPCnv.cxx:14
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.compareNtuple.vKeys
vKeys
Definition: compareNtuple.py:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ByteStreamMetadataTool::initialize
StatusCode initialize()
Gaudi Service Interface method implementations:
Definition: ByteStreamMetadataTool.cxx:36
ByteStreamMetadataTool::m_metadataStore
StoreGateSvc_t m_metadataStore
Definition: ByteStreamMetadataTool.h:59
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SG::SourceID
std::string SourceID
Definition: AthenaKernel/AthenaKernel/SourceID.h:23
ByteStreamMetadataTool::m_inputStore
StoreGateSvc_t m_inputStore
Definition: ByteStreamMetadataTool.h:60
ByteStreamMetadataTool::beginInputFile
virtual StatusCode beginInputFile()
Incident service handle listening for BeginInputFile and EndInputFile.
Definition: ByteStreamMetadataTool.cxx:67
ByteStreamMetadataTool::keysFromInput
std::set< std::string > keysFromInput() const
Definition: ByteStreamMetadataTool.cxx:138
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
calibdata.copy
bool copy
Definition: calibdata.py:27
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:135
ByteStreamMetadataTool::~ByteStreamMetadataTool
virtual ~ByteStreamMetadataTool()
Destructor.
Definition: ByteStreamMetadataTool.cxx:30
StoreGateSvc.h
ByteStreamMetadataTool::metaDataStop
virtual StatusCode metaDataStop()
Function called when the tool should prepare to write its metadata.
Definition: ByteStreamMetadataTool.cxx:176
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37