279 {
280
281
282
283
284 if (obj==0) {
285 REPORT_MESSAGE (MSG::ERROR) <<
"Attempt to write null pointer metadata";
286 return StatusCode::FAILURE;
287 }
288
289 std::abort();
290#if 0
291
292 std::string metaname;
294 if (m_tree != 0) {
295 dir = m_tree->GetDirectory();
296 }
297 else {
299 dir = m_file->CurrentDirectory();
300 if (dir == 0) {
301 REPORT_MESSAGE (MSG::ERROR) <<
"No file directory to navigate from";
302 return StatusCode::FAILURE;
303 }
304 }
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);
309
310 if (m_tree != 0) {
311
312 while (dynamic_cast<TDirectoryFile*> (dir) != 0 &&
314 dir =
dir->GetMotherDir();
315 thekey = m_tree->GetName();
316 }
317 }
318 else {
319 if (m_tree != 0) {
320 metaname = m_tree->GetName();
321 }
322 else {
323 metaname = "eventless";
324 }
325 metaname += "Meta";
326 }
327
328 TDirectory::TContext ctx (dir);
329 TDirectory* metadir =
dir->GetDirectory (metaname.c_str());
330 if (!metadir) {
331 metadir =
dir->mkdir (metaname.c_str());
332 if (!metadir) {
334 << "Can't create metadata dir " << metaname
335 <<
"in dir " <<
dir->GetName();
336 return StatusCode::RECOVERABLE;
337 }
338 }
339
340
341 TClass*
cls = gROOT->GetClass(ti);
342 if (!cls)
343 return StatusCode::RECOVERABLE;
344
345
346 if (ti == typeid(TString) || ti == typeid(std::string)) {
347 TObjString ostmp;
348 if (ti == typeid(TString)) {
349 ostmp.String() = *
reinterpret_cast<const TString*
> (
obj);
351 cls = gROOT->GetClass (
"TObjString");
352 }
353 else if (ti == typeid(std::string)) {
354 ostmp.String() = *
reinterpret_cast<const std::string*
> (
obj);
356 cls = gROOT->GetClass (
"TObjString");
357 }
358 if (
key.size() > 0 && key[
key.size()-1] ==
'/') {
360 while (metadir->FindObject (thekey.c_str())) {
362 std::ostringstream
ss;
363 if (m_tree)
364 ss << m_tree->GetName();
365 else
366 ss <<
dir->GetName();
369 }
370 }
371
372
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;
378 }
379 }
380 else if (ti == typeid(TTree)) {
381 TTree*
readTree = ((
const TTree*)obj)->GetTree();
382 metadir->cd();
383
384
385 if (
key.size() > 0) {
386 TTree* outTree = (TTree*)metadir->FindObject (thekey.c_str());
387 if (outTree == 0) {
389 }
390 else {
393 Long64_t temp = outTree->Merge((TCollection*)&
tc);
394 if (temp==0) {
395 REPORT_MESSAGE (MSG::ERROR) <<
"Unable to merge with existing tree in file";
396 return StatusCode::RECOVERABLE;
397 }
398 }
399 outTree->Write();
400 }
401 else {
402 REPORT_MESSAGE (MSG::ERROR) <<
"Did not use proper key for metadata tree ";
403 return StatusCode::RECOVERABLE;
404 }
405 }
406 else {
407 REPORT_MESSAGE (MSG::ERROR) <<
"addMetadata typeid not supported";
408 return StatusCode::FAILURE;
409 }
410 return(StatusCode::SUCCESS);
411#endif
412}
#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.