From 145f45a231d1d33a2e646d8fd531d7fcf040bb23 Mon Sep 17 00:00:00 2001 From: acolla Date: Thu, 14 Jun 2007 14:59:41 +0000 Subject: [PATCH] Added functionality to get TTree's from the OCDB. The tree is loaded in memory before closing the root file. --- STEER/AliCDBGrid.cxx | 19 ++++++++++++------- STEER/AliCDBLocal.cxx | 5 +++++ STEER/AliCDBStorage.cxx | 41 +++++++++++++++++++++++++++++++++++++++++ STEER/AliCDBStorage.h | 3 +++ 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/STEER/AliCDBGrid.cxx b/STEER/AliCDBGrid.cxx index 7cd3766a098..3725967ccf8 100644 --- a/STEER/AliCDBGrid.cxx +++ b/STEER/AliCDBGrid.cxx @@ -392,6 +392,9 @@ AliCDBEntry* AliCDBGrid::GetEntryFromFile(TString& filename, AliCDBId* dataId){ anEntry->SetLastStorage("grid"); + // Check whether entry contains a TTree. In case load the tree in memory! + LoadTreeFromFile(anEntry); + // close file, return retieved entry file->Close(); delete file; file=0; @@ -530,19 +533,21 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { if (fSE != "default") fullFilename += Form("?se=%s",fSE.Data()); // open file - TFile *file = TFile::Open(fullFilename,"CREATE"); - if(!file || !file->IsWritable()){ - AliError(Form("Can't open file <%s>!", filename.Data())); - if(file && !file->IsWritable()) file->Close(); delete file; file=0; - return kFALSE; - } + TFile *file = TFile::Open(fullFilename,"CREATE"); + if(!file || !file->IsWritable()){ + AliError(Form("Can't open file <%s>!", filename.Data())); + if(file && !file->IsWritable()) file->Close(); delete file; file=0; + return kFALSE; + } file->cd(); + SetTreeToFile(entry, file); + entry->SetVersion(id.GetVersion()); // write object (key name: "AliCDBEntry") - Bool_t result = (entry->Write("AliCDBEntry") != 0); + Bool_t result = (file->WriteTObject(entry, "AliCDBEntry") != 0); if (!result) AliError(Form("Can't write entry to file <%s>!", filename.Data())); diff --git a/STEER/AliCDBLocal.cxx b/STEER/AliCDBLocal.cxx index aae166900d9..5a489b0e363 100644 --- a/STEER/AliCDBLocal.cxx +++ b/STEER/AliCDBLocal.cxx @@ -417,6 +417,9 @@ AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) { AliWarning(Form("Object's Id: %s", entryId.ToString().Data())); } + // Check whether entry contains a TTree. In case load the tree in memory! + LoadTreeFromFile(anEntry); + // close file, return retieved entry file.Close(); return anEntry; @@ -547,6 +550,8 @@ Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) { return kFALSE; } + SetTreeToFile(entry, &file); + entry->SetVersion(id.GetVersion()); entry->SetSubVersion(id.GetSubVersion()); diff --git a/STEER/AliCDBStorage.cxx b/STEER/AliCDBStorage.cxx index 9ddbf14e1a3..7fcebf01e4b 100644 --- a/STEER/AliCDBStorage.cxx +++ b/STEER/AliCDBStorage.cxx @@ -15,6 +15,8 @@ #include #include +#include +#include #include "AliCDBStorage.h" #include "AliCDBGrid.h" @@ -440,3 +442,42 @@ AliCDBManager::DataType AliCDBStorage::GetDataType() const { return AliCDBManager::kPrivate; } + +//_____________________________________________________________________________ +void AliCDBStorage::LoadTreeFromFile(AliCDBEntry *entry) const { +// Checks whether entry contains a TTree and in case loads it into memory + + AliCDBMetaData *md = dynamic_cast (entry->GetMetaData()); + if(!md) return; + TString objStr = md->GetObjectClassName(); + if(objStr != "TTree") return; + AliWarning("Entry contains a TTree! Loading baskets..."); + + TTree* tree = dynamic_cast (entry->GetObject()); + + if(!tree) return; + + tree->LoadBaskets(); + tree->SetDirectory(0); + + return; +} + +//_____________________________________________________________________________ +void AliCDBStorage::SetTreeToFile(AliCDBEntry *entry, TFile* file) const { +// Checks whether entry contains a TTree and in case assigns it to memory + + AliCDBMetaData *md = dynamic_cast (entry->GetMetaData()); + if(!md) return; + TString objStr = md->GetObjectClassName(); + if(objStr != "TTree") return; + AliWarning("Entry contains a TTree! Setting file..."); + + TTree* tree = dynamic_cast (entry->GetObject()); + + if(!tree) return; + + tree->SetDirectory(file); + + return; +} diff --git a/STEER/AliCDBStorage.h b/STEER/AliCDBStorage.h index 26beac8452f..7a7f3fb216a 100644 --- a/STEER/AliCDBStorage.h +++ b/STEER/AliCDBStorage.h @@ -22,6 +22,7 @@ class AliCDBEntry; class AliCDBPath; class AliCDBParam; +class TFile; class AliCDBStorage: public TObject { @@ -103,6 +104,8 @@ protected: virtual Bool_t PutEntry(AliCDBEntry* entry) = 0; virtual TList *GetIdListFromFile(const char* fileName)=0; virtual void QueryValidFiles() = 0; + void LoadTreeFromFile(AliCDBEntry* entry) const; + void SetTreeToFile(AliCDBEntry* entry, TFile* file) const; TObjArray fValidFileIds; // list of Id's of the files valid for a given run (cached as fRun) Int_t fRun; // run number, used to manage list of valid files -- 2.43.0