17#include "GaudiKernel/IClassIDSvc.h"
18#include "GaudiKernel/IConversionSvc.h"
19#include "GaudiKernel/IOpaqueAddress.h"
20#include "GaudiKernel/IRegistry.h"
21#include "GaudiKernel/DataObject.h"
40 const std::string& name,
41 const IInterface* parent) :
42 base_class(
type, name, parent),
49 declareProperty(
"InputStore",
51 "Input metadata store");
52 declareProperty(
"OutputStore",
54 "Output metadata store");
55 declareProperty(
"StreamName",
57 "Name of the output stream tool associated with FIXME");
58 declareProperty(
"TupleName",
60 "Name of the output n-tuple FIXME");
61 declareProperty(
"OutputFile",
63 "Name of the output file FIXME");
74 if (!::AthAlgTool::initialize().isSuccess()) {
76 return(StatusCode::FAILURE);
80 ATH_MSG_FATAL(
"Cannot get ClassID service via IClassIDSvc interface.");
81 return(StatusCode::FAILURE);
88 return(StatusCode::FAILURE);
94 return(StatusCode::FAILURE);
99 if (!incSvc.retrieve().isSuccess()) {
101 return StatusCode::FAILURE;
105 incSvc->addListener(
this,
"BeginInputFile", 50);
106 incSvc->addListener(
this,
"EndInputFile", 50);
109 return(StatusCode::SUCCESS);
119 return StatusCode::RECOVERABLE;
122 return StatusCode::SUCCESS;
143 return(::AthAlgTool::finalize());
156 if (inc.type()==
"BeginInputFile") {
161 if (pc.isSuccess()) {
162 for (; titer != tend; ++titer) {
163 if (
m_ometaStore->removeDataAndProxy(&*titer).isFailure()) {
164 ATH_MSG_ERROR(
"Unable to remove TransferTree after writing");
170 else if (inc.type()==
"EndInputFile") {
179 ATH_MSG_INFO(
"RootNtupleOutputMetadataTool::writeMetadata outputName = ["
183 if (!iosvc.retrieve().isSuccess()) {
185 return StatusCode::FAILURE;
190 return StatusCode::FAILURE;
197 bool failure =
false;
198 if (pc.isSuccess()) {
199 for (; iter != end; ++iter) {
200 std::string key = iter.key();
201 if (this->
addMetadata(key,&(*iter),
typeid(std::string)).isFailure()) failure=
true;
206 return StatusCode::FAILURE;
213 bool failure =
false;
214 if (pc.isSuccess()) {
215 for (; titer != tend; ++titer) {
216 std::string key = titer.
key();
219 const TTree*
x = (TTree*)titer->tree();
221 if (this->
addMetadata(key,
x,
typeid(TTree)).isFailure()) failure=
true;
224 ATH_MSG_INFO(
"Error adding metadata for TTree " << key);
232 return StatusCode::FAILURE;
235 return(StatusCode::SUCCESS);
244 bool failure =
false;
245 if (pc.isSuccess()) {
246 for (; iter != end; ++iter) {
248 std::string* toCopy =
new std::string(*iter);
249 if (
m_ometaStore->record(toCopy,iter.key()).isFailure()) failure=
true;
255 return StatusCode::FAILURE;
261 if (pc.isSuccess()) {
262 for (; titer != tend; ++titer) {
263 auto toCopy = std::make_unique<TransferTree>(*titer);
265 if (
m_ometaStore->record(std::move(toCopy),titer.
key()).isFailure()) failure=
true;
267 else ATH_MSG_INFO(
"Retrieve TTree with null pointer from input metadata store");
272 return StatusCode::FAILURE;
275 return(StatusCode::SUCCESS);
285 REPORT_MESSAGE (MSG::ERROR) <<
"Attempt to write null pointer metadata";
286 return StatusCode::FAILURE;
292 std::string metaname;
295 dir = m_tree->GetDirectory();
299 dir = m_file->CurrentDirectory();
301 REPORT_MESSAGE (MSG::ERROR) <<
"No file directory to navigate from";
302 return StatusCode::FAILURE;
305 std::string thekey = key;
306 std::string::size_type sep = key.find(
'/');
307 if (sep != std::string::npos) {
308 metaname = key.substr (0, sep);
312 while (
dynamic_cast<TDirectoryFile*
> (dir) != 0 &&
314 dir = dir->GetMotherDir();
315 thekey = m_tree->GetName();
320 metaname = m_tree->GetName();
323 metaname =
"eventless";
328 TDirectory::TContext ctx (dir);
329 TDirectory* metadir = dir->GetDirectory (metaname.c_str());
331 metadir = dir->mkdir (metaname.c_str());
334 <<
"Can't create metadata dir " << metaname
335 <<
"in dir " << dir->GetName();
336 return StatusCode::RECOVERABLE;
341 TClass* cls = gROOT->GetClass(ti);
343 return StatusCode::RECOVERABLE;
346 if (ti ==
typeid(TString) || ti ==
typeid(std::string)) {
348 if (ti ==
typeid(TString)) {
349 ostmp.String() = *
reinterpret_cast<const TString*
> (obj);
351 cls = gROOT->GetClass (
"TObjString");
353 else if (ti ==
typeid(std::string)) {
354 ostmp.String() = *
reinterpret_cast<const std::string*
> (obj);
356 cls = gROOT->GetClass (
"TObjString");
358 if (key.size() > 0 && key[key.size()-1] ==
'/') {
360 while (metadir->FindObject (thekey.c_str())) {
362 std::ostringstream
ss;
364 ss << m_tree->GetName();
366 ss << dir->GetName();
373 if (metadir->WriteObjectAny (obj, cls, thekey.c_str(),
"new") == 0) {
375 <<
"Can't write metadata object " << thekey
376 <<
" for file " << metadir->GetFile()->GetName();
377 return StatusCode::RECOVERABLE;
380 else if (ti ==
typeid(TTree)) {
381 TTree*
readTree = ((
const TTree*)obj)->GetTree();
385 if (key.size() > 0) {
386 TTree* outTree = (TTree*)metadir->FindObject (thekey.c_str());
393 Long64_t temp = outTree->Merge((TCollection*)&
tc);
395 REPORT_MESSAGE (MSG::ERROR) <<
"Unable to merge with existing tree in file";
396 return StatusCode::RECOVERABLE;
402 REPORT_MESSAGE (MSG::ERROR) <<
"Did not use proper key for metadata tree ";
403 return StatusCode::RECOVERABLE;
407 REPORT_MESSAGE (MSG::ERROR) <<
"addMetadata typeid not supported";
408 return StatusCode::FAILURE;
410 return(StatusCode::SUCCESS);
#define ATH_MSG_WARNING(x)
macros to associate a CLID to a type
#define REPORT_MESSAGE(LVL)
Report a message.
void readTree(AccumulateMap &map, TTree *tree, size_t nLayers, size_t nCoords)
Reads a matrix tree, accumulating its entries into a map.
int Fd
unix-y file descriptor
a const_iterator facade to DataHandle.
const std::string & key() const
Get the key string with which the current object was stored.
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....