#include <TSystemDirectory.h>
#include <TString.h>
#include <TObjString.h>
+#include <TObjArray.h>
#include <TProcessID.h>
+#include <TSystem.h>
#include "AliESDInputHandlerRP.h"
#include "AliESDEvent.h"
//______________________________________________________________________________
AliESDInputHandlerRP::AliESDInputHandlerRP() :
AliESDInputHandler(),
- fRTrees( new TList()),
+ fRTrees( new TObjArray()),
+ fRDirs ( new TObjArray()),
fRFiles( new TList()),
fDetectors(new TList()),
fDirR(0),
fEventNumber(-1),
- fNEvent(-1),
fFileNumber(0),
fEventsPerFile(0),
fExtension(""),
//______________________________________________________________________________
AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title):
AliESDInputHandler(name, title),
- fRTrees( new TList()),
+ fRTrees( new TObjArray()),
+ fRDirs ( new TObjArray()),
fRFiles( new TList()),
fDetectors(new TList()),
fDirR(0),
fEventNumber(-1),
- fNEvent(-1),
fFileNumber(0),
fEventsPerFile(0),
fExtension(""),
} else {
file = TFile::Open(Form("%s#%s.RecPoints.root", fPathName->Data(), det->GetName()));
}
- if (!file) AliFatal(Form("AliESDInputHandlerRP: %s.RecPoints.root not found in %s ! \n", det->GetName(), fPathName->Data()));
+ if (!file) {
+ AliError(Form("AliESDInputHandlerRP: %s.RecPoints.root not found in %s ! \n", det->GetName(), fPathName->Data()));
+ return kFALSE;
+ }
fRFiles->Add(file);
}
+
if (file) {
fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
} else {
- AliFatal(Form("AliESDInputHandlerRP: No file with RecPoints found in %s ! \n", fPathName->Data()));
+ AliError(Form("AliESDInputHandlerRP: No file with RecPoints found in %s ! \n", fPathName->Data()));
+ return kFALSE;
}
-
+
// Reset the event number
fEventNumber = -1;
fFileNumber = 0;
// Get number of events from esd tree
- fNEvent = fTree->GetEntries();
-
- printf("AliESDInputHandler::Init() %d\n",__LINE__);
+ printf("AliESDInputHandlerRP::Init() %d %d\n",__LINE__, fNEvents);
+ //
+ AliESDInputHandler::Init(opt);
+ //
return kTRUE;
}
Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
{
// Begin the next event
- // Delegate first to base class
- AliESDInputHandler::BeginEvent(entry);
-//
+ //
if (entry == -1) {
fEventNumber++;
entry = fEventNumber;
fEventNumber = entry;
}
- if (entry >= fNEvent) {
- AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvent));
+ if (entry >= fNEvents) {
+ AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5lld %5d\n", entry, fNEvents));
return kFALSE;
}
- return LoadEvent(entry);
+
+ LoadEvent(entry);
+
+ // Delegate to base class
+ return AliESDInputHandler::BeginEvent(entry);
+
}
Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
// Load the event number iev
//
// Calculate the file number
+ if (fEventsPerFile<=0) return kFALSE;
Int_t inew = iev / fEventsPerFile;
if (inew != fFileNumber) {
fFileNumber = inew;
char folder[20];
sprintf(folder, "Event%d", iev);
// Tree R
- fRTrees->Clear();
-
TIter next(fRFiles);
TFile* file;
+ Int_t idx = 0;
+
while ((file = (TFile*) next()))
{
file->GetObject(folder, fDirR);
+
if (!fDirR) {
AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
return kFALSE;
}
- TTree* tree;
- fDirR ->GetObject("TreeR", tree);
- fRTrees->Add(tree);
- tree->ls();
+ TTree* tree = 0;
+ fDirR->GetObject("TreeR", tree);
+ fRDirs ->AddAt(fDirR, idx );
+ fRTrees->AddAt(tree, idx++);
}
return kTRUE;
}
// Notify about directory change
// The directory is taken from the 'path' argument
//
+
// Get path to directory
TString fileName(path);
- if(fileName.Contains("AliESDs.root")){
- fileName.ReplaceAll("AliESDs.root", "");
- }
- // If this is an archive it will contain a #
+ if (fileName.IsNull()) return kFALSE;
+ AliInfo(Form("Directory change %s \n", path));
+
if(fileName.Contains("#")){
- fileName.ReplaceAll("#", "");
+ // If this is an archive it will contain a #
+ fIsArchive = kTRUE;
+ } else if(fileName.Contains("AliESDs.root")){
+ fileName.ReplaceAll("AliESDs.root", "");
}
+
//
- // At this point we have a path to the directory or to the archive
+ // At this point we have a path to the directory or to the archive anchor
*fPathName = fileName;
//
// Now filter the files containing RecPoints *.RecPoints.*
- fIsArchive = kFALSE;
- if (fPathName->Contains(".zip")) fIsArchive = kTRUE;
TSeqCollection* members;
+
if (fIsArchive) {
// Archive
- TFile* file = TFile::Open(fPathName->Data());
- TArchiveFile* arch = file->GetArchive();
- members = arch->GetMembers();
+ TFile* file = TFile::Open(fPathName->Data());
+ TArchiveFile* arch = file->GetArchive();
+ members = arch->GetMembers();
+ fPathName->ReplaceAll("#AliESDs.root", "");
} else {
- // Directory
- TSystemDirectory dir(".", fPathName->Data());
- members = dir.GetListOfFiles();
+ // Directory or alien archive
+ if (fileName.BeginsWith("alien:")) {
+ TFile* file = TFile::Open(Form("%s/root_archive.zip", fPathName->Data()));
+ TArchiveFile* arch = file->GetArchive();
+ members = arch->GetMembers();
+ } else {
+ TString wd = gSystem->WorkingDirectory();
+ TSystemDirectory dir(".", fPathName->Data());
+ members = dir.GetListOfFiles();
+ gSystem->cd(wd);
+ }
}
-
+
TIter next(members);
TFile* entry;
Int_t ien = 0;
+ fDetectors->Delete();
+
while ( (entry = (TFile*) next()) )
{
- printf("File %s \n", entry->GetName());
TString name(entry->GetName());
TObjArray* tokens = name.Tokenize(".");
- Int_t ntok = tokens->GetEntries();
+ Int_t ntok = 0;
+ if (tokens) {
+ ntok = tokens->GetEntries();
+ } else {
+ continue;
+ }
if (ntok <= 1) continue;
TString str = ((TObjString*) tokens->At(1))->GetString();
if (!(strcmp(str.Data(), "RecPoints"))){
TString det = ((TObjString*) tokens->At(0))->GetString();
- printf("Name %s \n", det.Data());
+ printf("Found file with RecPoints for %s \n", det.Data());
TNamed* ent = new TNamed(det.Data(), det.Data());
+ fRTrees->AddAt(0, ien);
ent->SetUniqueID(ien++);
fDetectors->Add(ent);
}
+ if(tokens) delete tokens;
} // loop over files
-
+
// Now we have the path and the list of detectors
ResetIO();
InitIO("");
// Some clean-up
- members->Delete();
- //
+ if (members) members->Delete();
+
+ AliESDInputHandler::Notify(path);
+
return kTRUE;
}
Bool_t AliESDInputHandlerRP::FinishEvent()
{
// Clean-up after each event
- delete fDirR; fDirR = 0;
+ fRDirs->Delete();
AliESDInputHandler::FinishEvent();
return kTRUE;
}
void AliESDInputHandlerRP::ResetIO()
{
// Delete trees and files
- fRTrees->Delete();
- fRFiles->Delete();
+ fRFiles->Clear("nodelete");
fExtension="";
}
-TTree* AliESDInputHandlerRP::GetTreeR(char* det)
+TTree* AliESDInputHandlerRP::GetTreeR(const char* det)
{
// Return pointer to RecPoint tree for detector det
TNamed* entry = (TNamed*) (fDetectors->FindObject(det));