command += " ";
command += pattern;
command += conditions;
- Printf("command: %s", command.Data());
+ printf("command: %s\n", command.Data());
TGridResult *res = gGrid->Command(command);
if (res) delete res;
// Write standard output to file
cbase = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"%s\", 1000000);",file.Data()));
} else {
cadd = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"%s\", 1000000);",file.Data()));
- Printf(" Merging collection <%s> into masterjob input...", file.Data());
+ printf(" Merging collection <%s> into masterjob input...\n", file.Data());
cbase->Add(cadd);
delete cadd;
}
Info("CreateDataset", "\n##### Dataset %s exist. Skipping creation...", schunk.Data());
continue;
}
- Printf("Exporting merged collection <%s> and copying to AliEn.", schunk.Data());
+ printf("Exporting merged collection <%s> and copying to AliEn\n", schunk.Data());
cbase->ExportXML(Form("file://%s", schunk.Data()),kFALSE,kFALSE, schunk, "Merged runs");
TFile::Cp(Form("file:%s",schunk.Data()), Form("alien://%s/%s",workdir.Data(), schunk.Data()));
if (!FileExists(schunk)) {
// Check if the collection for the chunk exist locally.
Int_t nchunk = (nruns-1)/fNrunsPerMaster;
if (FileExists(fInputFiles->At(nchunk)->GetName())) continue;
- Printf(" Merging collection <%s> into %d runs chunk...",file.Data(),fNrunsPerMaster);
+ printf(" Merging collection <%s> into %d runs chunk...\n",file.Data(),fNrunsPerMaster);
if (((nruns-1)%fNrunsPerMaster) == 0) {
schunk = Form("%d", irun);
cbase = (TGridCollection*)gROOT->ProcessLine(Form("new TAlienCollection(\"%s\", 1000000);",file.Data()));
Info("CreateDataset", "\n##### Dataset %s exist. Skipping creation...", schunk.Data());
continue;
}
- Printf("Exporting merged collection <%s> and copying to AliEn.", schunk.Data());
+ printf("Exporting merged collection <%s> and copying to AliEn.\n", schunk.Data());
cbase->ExportXML(Form("file://%s", schunk.Data()),kFALSE,kFALSE, schunk, "Merged runs");
if (FileExists(schunk)) {
Info("CreateDataset", "\n##### Dataset %s exist. Skipping copy...", schunk.Data());
void AliAnalysisAlien::Print(Option_t *) const
{
// Print current plugin settings.
- Printf("### AliEn analysis plugin current settings ###");
- Printf("= Production mode:______________________________ %d", fProductionMode);
- Printf("= Version of API requested: ____________________ %s", fAPIVersion.Data());
- Printf("= Version of ROOT requested: ___________________ %s", fROOTVersion.Data());
- Printf("= Version of AliRoot requested: ________________ %s", fAliROOTVersion.Data());
+ printf("### AliEn analysis plugin current settings ###\n");
+ printf("= Production mode:______________________________ %d\n", fProductionMode);
+ printf("= Version of API requested: ____________________ %s\n", fAPIVersion.Data());
+ printf("= Version of ROOT requested: ___________________ %s\n", fROOTVersion.Data());
+ printf("= Version of AliRoot requested: ________________ %s\n", fAliROOTVersion.Data());
if (fUser.Length())
- Printf("= User running the plugin: _____________________ %s", fUser.Data());
- Printf("= Grid workdir relative to user $HOME: _________ %s", fGridWorkingDir.Data());
- Printf("= Grid output directory relative to workdir: ___ %s", fGridOutputDir.Data());
- Printf("= Data base directory path requested: __________ %s", fGridDataDir.Data());
- Printf("= Data search pattern: _________________________ %s", fDataPattern.Data());
- Printf("= Input data format: ___________________________ %s", fInputFormat.Data());
+ printf("= User running the plugin: _____________________ %s\n", fUser.Data());
+ printf("= Grid workdir relative to user $HOME: _________ %s\n", fGridWorkingDir.Data());
+ printf("= Grid output directory relative to workdir: ___ %s\n", fGridOutputDir.Data());
+ printf("= Data base directory path requested: __________ %s\n", fGridDataDir.Data());
+ printf("= Data search pattern: _________________________ %s\n", fDataPattern.Data());
+ printf("= Input data format: ___________________________ %s\n", fInputFormat.Data());
if (fRunNumbers.Length())
- Printf("= Run numbers to be processed: _________________ %s", fRunNumbers.Data());
+ printf("= Run numbers to be processed: _________________ %s\n", fRunNumbers.Data());
if (fRunRange[0])
- Printf("= Run range to be processed: ___________________ %d-%d", fRunRange[0], fRunRange[1]);
+ printf("= Run range to be processed: ___________________ %d-%d\n", fRunRange[0], fRunRange[1]);
if (!fRunRange[0] && !fRunNumbers.Length()) {
TIter next(fInputFiles);
TObject *obj;
TString list;
while ((obj=next())) list += obj->GetName();
- Printf("= Input files to be processed: _________________ %s", list.Data());
+ printf("= Input files to be processed: _________________ %s\n", list.Data());
}
if (TestBit(AliAnalysisGrid::kTest))
- Printf("= Number of input files used in test mode: _____ %d", fNtestFiles);
- Printf("= List of output files to be registered: _______ %s", fOutputFiles.Data());
- Printf("= List of outputs going to be archived: ________ %s", fOutputArchive.Data());
- Printf("= List of outputs that should not be merged: ___ %s", fMergeExcludes.Data());
- Printf("=====================================================================");
- Printf("= Job price: ___________________________________ %d", fPrice);
- Printf("= Time to live (TTL): __________________________ %d", fTTL);
- Printf("= Max files per subjob: ________________________ %d", fSplitMaxInputFileNumber);
+ printf("= Number of input files used in test mode: _____ %d\n", fNtestFiles);
+ printf("= List of output files to be registered: _______ %s\n", fOutputFiles.Data());
+ printf("= List of outputs going to be archived: ________ %s\n", fOutputArchive.Data());
+ printf("= List of outputs that should not be merged: ___ %s\n", fMergeExcludes.Data());
+ printf("=====================================================================\n");
+ printf("= Job price: ___________________________________ %d\n", fPrice);
+ printf("= Time to live (TTL): __________________________ %d\n", fTTL);
+ printf("= Max files per subjob: ________________________ %d\n", fSplitMaxInputFileNumber);
if (fMaxInitFailed>0)
- Printf("= Max number of subjob fails to kill: __________ %d", fMaxInitFailed);
+ printf("= Max number of subjob fails to kill: __________ %d\n", fMaxInitFailed);
if (fMasterResubmitThreshold>0)
- Printf("= Resubmit master job if failed subjobs >_______ %d", fMasterResubmitThreshold);
+ printf("= Resubmit master job if failed subjobs >_______ %d\n", fMasterResubmitThreshold);
if (fNrunsPerMaster>0)
- Printf("= Number of runs per master job: _______________ %d", fNrunsPerMaster);
- Printf("= Number of files in one chunk to be merged: ___ %d", fMaxMergeFiles);
- Printf("= Name of the generated execution script: ______ %s",fExecutable.Data());
+ printf("= Number of runs per master job: _______________ %d\n", fNrunsPerMaster);
+ printf("= Number of files in one chunk to be merged: ___ %d\n", fMaxMergeFiles);
+ printf("= Name of the generated execution script: ______ %s\n",fExecutable.Data());
if (fArguments.Length())
- Printf("= Arguments for the execution script: __________ %s",fArguments.Data());
- Printf("= Name of the generated analysis macro: ________ %s",fAnalysisMacro.Data());
- Printf("= User analysis files to be deployed: __________ %s",fAnalysisSource.Data());
- Printf("= Additional libs to be loaded or souces to be compiled runtime: <%s>",fAdditionalLibs.Data());
- Printf("= Master jobs split mode: ______________________ %s",fSplitMode.Data());
+ printf("= Arguments for the execution script: __________ %s\n",fArguments.Data());
+ printf("= Name of the generated analysis macro: ________ %s\n",fAnalysisMacro.Data());
+ printf("= User analysis files to be deployed: __________ %s\n",fAnalysisSource.Data());
+ printf("= Additional libs to be loaded or souces to be compiled runtime: <%s>\n",fAdditionalLibs.Data());
+ printf("= Master jobs split mode: ______________________ %s\n",fSplitMode.Data());
if (fDatasetName)
- Printf("= Custom name for the dataset to be created: ___ %s", fDatasetName.Data());
- Printf("= Name of the generated JDL: ___________________ %s", fJDLName.Data());
+ printf("= Custom name for the dataset to be created: ___ %s\n", fDatasetName.Data());
+ printf("= Name of the generated JDL: ___________________ %s\n", fJDLName.Data());
if (fIncludePath.Data())
- Printf("= Include path for runtime task compilation: ___ %s", fIncludePath.Data());
+ printf("= Include path for runtime task compilation: ___ %s\n", fIncludePath.Data());
if (fCloseSE.Length())
- Printf("= Force job outputs to storage element: ________ %s", fCloseSE.Data());
+ printf("= Force job outputs to storage element: ________ %s\n", fCloseSE.Data());
if (fFriendChainName.Length())
- Printf("= Open friend chain file on worker: ____________ %s", fFriendChainName.Data());
+ printf("= Open friend chain file on worker: ____________ %s\n", fFriendChainName.Data());
if (fPackages) {
TIter next(fPackages);
TObject *obj;
TString list;
while ((obj=next())) list += obj->GetName();
- Printf("= Par files to be used: ________________________ %s", list.Data());
+ printf("= Par files to be used: ________________________ %s\n", list.Data());
}
}
fMergeExcludes.Contains(output_file.Data())) continue;
// Perform a 'find' command in the output directory, looking for registered outputs
command = Form("find %s/ *%s", fGridOutputDir.Data(), output_file.Data());
- Printf("command: %s", command.Data());
+ printf("command: %s\n", command.Data());
TGridResult *res = gGrid->Command(command);
if (!res) continue;
TFileMerger *fm = 0;
}
output_chunk = output_file;
output_chunk.ReplaceAll(".root", Form("_%04d.root", count_chunk));
- Printf("%s", output_chunk.Data());
+ printf("%s\n", output_chunk.Data());
count_chunk++;
if (gSystem->AccessPathName(output_chunk)) continue;
// Merged file with chunks up to <count_chunk> found
- Printf("Resume merging of <%s> from <%s>", output_file.Data(), output_chunk.Data());
+ printf("Resume merging of <%s> from <%s>\n", output_file.Data(), output_chunk.Data());
previous_chunk = output_chunk;
break;
}
if (!mgr->GetOutputEventHandler()) continue;
filename = mgr->GetOutputEventHandler()->GetOutputFileName();
}
+ if (fOutputFiles.Contains(filename)) continue;
if (fOutputFiles.Length()) fOutputFiles += " ";
fOutputFiles += filename;
}
if (mgr->GetExtraFiles().Length()) {
if (fOutputFiles.Length()) fOutputFiles += " ";
fOutputFiles += mgr->GetExtraFiles();
- }
+ }
}
// if (!fCloseSE.Length()) fCloseSE = gSystem->Getenv("alien_CLOSE_SE");
if (TestBit(AliAnalysisGrid::kOffline)) {
if (!fRunNumbers.Length() && !fRunRange[0]) {
// Submit a given xml or a set of runs
res = gGrid->Command(Form("submit %s", fJDLName.Data()));
- Printf("*************************** %s",Form("submit %s", fJDLName.Data()));
+ printf("*************************** %s\n",Form("submit %s", fJDLName.Data()));
if (res) {
const char *cjobId = res->GetKey(0,"jobId");
if (!cjobId) {
if (!fNsubmitted) ntosubmit = 1;
else {
TString status = GetJobStatus(firstmaster, lastmaster, nrunning, nwaiting, nerror, ndone);
- Printf("=== master %d: %s", lastmaster, status.Data());
+ printf("=== master %d: %s\n", lastmaster, status.Data());
// If last master not split, just return
if (status != "SPLIT") {iscalled = kFALSE; return;}
// No more than 100 waiting jobs
if (nwaiting>100) {iscalled = kFALSE; return;}
npermaster = (nrunning+nwaiting+nerror+ndone)/fNsubmitted;
if (npermaster) ntosubmit = (100-nwaiting)/npermaster;
- Printf("=== WAITING(%d) RUNNING(%d) DONE(%d) OTHER(%d) NperMaster=%d => to submit %d jobs",
+ printf("=== WAITING(%d) RUNNING(%d) DONE(%d) OTHER(%d) NperMaster=%d => to submit %d jobs\n",
nwaiting, nrunning, ndone, nerror, npermaster, ntosubmit);
}
Int_t nmasterjobs = fInputFiles->GetEntries();
if (fNsubmitted>=nmasterjobs) {iscalled = kFALSE; return;}
TString query;
query = Form("submit %s %s %03d", fJDLName.Data(), fInputFiles->At(fNsubmitted)->GetName(), fNsubmitted);
- Printf("********* %s",query.Data());
+ printf("********* %s\n",query.Data());
res = gGrid->Command(query);
if (res) {
TString cjobId1 = res->GetKey(0,"jobId");
#include <Riostream.h>
+#include <TError.h>
#include <TClass.h>
#include <TFile.h>
#include <TKey.h>
ClassImp(AliAnalysisManager)
AliAnalysisManager *AliAnalysisManager::fgAnalysisManager = NULL;
+TString AliAnalysisManager::fgCommonFileName = "";
//______________________________________________________________________________
AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
{
// Default constructor.
fgAnalysisManager = this;
+ fgCommonFileName = "AnalysisResults.root";
fTasks = new TObjArray();
fTopTasks = new TObjArray();
fZombies = new TObjArray();
fInputEventHandler(NULL),
fOutputEventHandler(NULL),
fMCtruthEventHandler(NULL),
- fEventPool(NULL),
+ fEventPool(NULL),
fCurrentEntry(-1),
fNSysInfo(0),
fMode(other.fMode),
fContainers = new TObjArray(*other.fContainers);
fInputs = new TObjArray(*other.fInputs);
fOutputs = new TObjArray(*other.fOutputs);
+ fgCommonFileName = "AnalysisResults.root";
fgAnalysisManager = this;
}
fSelector = NULL;
fGridHandler = NULL;
fExtraFiles = other.fExtraFiles;
+ fgCommonFileName = "AnalysisResults.root";
fgAnalysisManager = this;
}
return *this;
Int_t AliAnalysisManager::GetEntry(Long64_t entry, Int_t getall)
{
// Read one entry of the tree or a whole branch.
- if (fDebug > 0) Printf("== AliAnalysisManager::GetEntry(%lld)", entry);
+ if (fDebug > 0) printf("== AliAnalysisManager::GetEntry(%lld)\n", entry);
fCurrentEntry = entry;
return fTree ? fTree->GetTree()->GetEntry(entry, getall) : 0;
}
Bool_t init = kFALSE;
if (!tree) return kFALSE; // Should not happen - protected in selector caller
if (fDebug > 0) {
- Printf("->AliAnalysisManager::Init(%s)", tree->GetName());
+ printf("->AliAnalysisManager::Init(%s)\n", tree->GetName());
}
// Call InitTree of EventHandler
if (fOutputEventHandler) {
}
top->SetData(tree);
if (fDebug > 0) {
- Printf("<-AliAnalysisManager::Init(%s)", tree->GetName());
+ printf("<-AliAnalysisManager::Init(%s)\n", tree->GetName());
}
return kTRUE;
}
// The SlaveBegin() function is called after the Begin() function.
// When running with PROOF SlaveBegin() is called on each slave server.
// The tree argument is deprecated (on PROOF 0 is passed).
- if (fDebug > 0) Printf("->AliAnalysisManager::SlaveBegin()");
+ if (fDebug > 0) printf("->AliAnalysisManager::SlaveBegin()\n");
static Bool_t isCalled = kFALSE;
Bool_t init = kFALSE;
Bool_t initOK = kTRUE;
if (fOutputEventHandler) {
if (fMode == kProofAnalysis) {
// Merging AOD's in PROOF via TProofOutputFile
- if (fDebug > 1) Printf(" Initializing AOD output file %s...", fOutputEventHandler->GetOutputFileName());
+ if (fDebug > 1) printf(" Initializing AOD output file %s...\n", fOutputEventHandler->GetOutputFileName());
init = fOutputEventHandler->Init("proof");
if (!init) msg = "Failed to initialize output handler on worker";
} else {
task->CreateOutputObjects();
if (curdir) curdir->cd();
}
- if (fDebug > 0) Printf("<-AliAnalysisManager::SlaveBegin()");
+ if (fDebug > 0) printf("<-AliAnalysisManager::SlaveBegin()\n");
}
//______________________________________________________________________________
return kFALSE;
}
- if (fDebug > 0) Printf("->AliAnalysisManager::Notify() file: %s", curfile->GetName());
+ if (fDebug > 0) printf("->AliAnalysisManager::Notify() file: %s\n", curfile->GetName());
TIter next(fTasks);
AliAnalysisTask *task;
// Call Notify for all tasks
if (fMCtruthEventHandler) {
fMCtruthEventHandler->Notify(curfile->GetName());
}
- if (fDebug > 0) Printf("<-AliAnalysisManager::Notify()");
+ if (fDebug > 0) printf("<-AliAnalysisManager::Notify()\n");
return kTRUE;
}
// The entry is always the local entry number in the current tree.
// Assuming that fChain is the pointer to the TChain being processed,
// use fChain->GetTree()->GetEntry(entry).
- if (fDebug > 0) Printf("->AliAnalysisManager::Process(%lld)", entry);
+ if (fDebug > 0) printf("->AliAnalysisManager::Process(%lld)\n", entry);
if (fInputEventHandler) fInputEventHandler ->BeginEvent(entry);
if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(entry);
GetEntry(entry);
ExecAnalysis();
- if (fDebug > 0) Printf("<-AliAnalysisManager::Process()");
+ if (fDebug > 0) printf("<-AliAnalysisManager::Process()\n");
return kTRUE;
}
{
// Pack all output data containers in the output list. Called at SlaveTerminate
// stage in PROOF case for each slave.
- if (fDebug > 0) Printf("->AliAnalysisManager::PackOutput()");
+ if (fDebug > 0) printf("->AliAnalysisManager::PackOutput()\n");
if (!target) {
Error("PackOutput", "No target. Aborting.");
return;
AliAnalysisTask *task;
while ((task=(AliAnalysisTask*)nexttask())) {
if (!task->IsPostEventLoop()) {
- if (fDebug > 0) Printf("->FinishTaskOutput: task %s", task->GetName());
+ if (fDebug > 0) printf("->FinishTaskOutput: task %s\n", task->GetName());
task->FinishTaskOutput();
- if (fDebug > 0) Printf("<-FinishTaskOutput: task %s", task->GetName());
+ if (fDebug > 0) printf("<-FinishTaskOutput: task %s\n", task->GetName());
}
}
const char *filename = output->GetFileName();
if (!(strcmp(filename, "default")) && fOutputEventHandler) {
isManagedByHandler = kTRUE;
- Printf("#### Handler output. Extra: %s", fExtraFiles.Data());
+ printf("#### Handler output. Extra: %s\n", fExtraFiles.Data());
filename = fOutputEventHandler->GetOutputFileName();
}
// Check if data was posted to this container. If not, issue an error.
if (!output->IsSpecialOutput()) {
// Normal outputs
if (strlen(filename) && !isManagedByHandler) {
- // File resident outputs
- TFile *file = output->GetFile();
// Backup current folder
TDirectory *opwd = gDirectory;
- // Create file if not existing and register to container.
- if (file) file->cd();
- else file = new TFile(filename, "RECREATE");
- if (file->IsZombie()) {
- Fatal("PackOutput", "Could not recreate file %s", filename);
- return;
- }
- output->SetFile(file);
+ // File resident outputs
+ TFile *file = AliAnalysisManager::OpenFile(output, "RECREATE", kTRUE);
// Clear file list to release object ownership to user.
file->Clear();
// Save data to file, then close.
output->GetData()->Write();
}
}
- if (fDebug > 1) Printf("PackOutput %s: memory merge, file resident output", output->GetName());
+ if (fDebug > 1) printf("PackOutput %s: memory merge, file resident output\n", output->GetName());
if (fDebug > 2) {
- Printf(" file %s listing content:", filename);
+ printf(" file %s listing content:\n", filename);
file->ls();
}
file->Close();
+ output->SetFile(NULL);
// Restore current directory
if (opwd) opwd->cd();
} else {
// Memory-resident outputs
- if (fDebug > 1) Printf("PackOutput %s: memory merge memory resident output", filename);
+ if (fDebug > 1) printf("PackOutput %s: memory merge memory resident output\n", filename);
}
AliAnalysisDataWrapper *wrap = 0;
if (isManagedByHandler) {
TFile *file = output->GetFile();
if (!file) {
AliAnalysisTask *producer = output->GetProducer();
- Error("PackOutput",
+ Fatal("PackOutput",
"File %s for special container %s was NOT opened in %s::CreateOutputObjects !!!",
output->GetFileName(), output->GetName(), producer->ClassName());
continue;
}
TString outFilename = file->GetName();
- if (fDebug > 1) Printf("PackOutput %s: special output", output->GetName());
+ if (fDebug > 1) printf("PackOutput %s: special output\n", output->GetName());
if (isManagedByHandler) {
// Terminate IO for files managed by the output handler
if (file) file->Write();
if (file && fDebug > 2) {
- Printf(" handled file %s listing content:", file->GetName());
+ printf(" handled file %s listing content:\n", file->GetName());
file->ls();
}
fOutputEventHandler->TerminateIO();
}
file->Clear();
if (fDebug > 2) {
- Printf(" file %s listing content:", output->GetFileName());
+ printf(" file %s listing content:\n", output->GetFileName());
file->ls();
}
file->Close();
+ output->SetFile(NULL);
}
// Restore current directory
if (opwd) opwd->cd();
} else {
// No special location specified-> use TProofOutputFile as merging utility
// The file at this output slot must be opened in CreateOutputObjects
- if (fDebug > 1) Printf(" File for container %s to be merged via file merger...", output->GetName());
+ if (fDebug > 1) printf(" File for container %s to be merged via file merger...\n", output->GetName());
}
}
}
}
- if (fDebug > 0) Printf("<-AliAnalysisManager::PackOutput: output list contains %d containers", target->GetSize());
+ if (fDebug > 0) printf("<-AliAnalysisManager::PackOutput: output list contains %d containers\n", target->GetSize());
}
//______________________________________________________________________________
void AliAnalysisManager::ImportWrappers(TList *source)
{
// Import data in output containers from wrappers coming in source.
- if (fDebug > 0) Printf("->AliAnalysisManager::ImportWrappers()");
+ if (fDebug > 0) printf("->AliAnalysisManager::ImportWrappers()\n");
TIter next(fOutputs);
AliAnalysisDataContainer *cont;
AliAnalysisDataWrapper *wrap;
Int_t icont = 0;
Bool_t inGrid = (fMode == kGridAnalysis)?kTRUE:kFALSE;
+ TDirectory *cdir = gDirectory;
while ((cont=(AliAnalysisDataContainer*)next())) {
wrap = 0;
if (cont->GetProducer()->IsPostEventLoop() && !inGrid) continue;
// Normally we should connect data from the copied file to the
// corresponding output container, but it is not obvious how to do this
// automatically if several objects in file...
- TFile *f = TFile::Open(filename, "READ");
+ TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+ if (!f) f = TFile::Open(filename, "READ");
if (!f) {
Error("ImportWrappers", "Cannot open file %s in read-only mode", filename);
continue;
}
TObject *obj = 0;
- // Try to fetch first a list object having the container name.
- obj = f->Get(cont->GetName());
- if (!obj) {
- // Fetch first object from file having the container type.
- TIter nextkey(f->GetListOfKeys());
- TKey *key;
- while ((key=(TKey*)nextkey())) {
- obj = f->Get(key->GetName());
- if (obj && obj->IsA()->InheritsFrom(cont->GetType())) break;
- }
- }
+ // Cd to the directory pointed by the container
+ TString folder = cont->GetFolderName();
+ if (!folder.IsNull()) f->cd(folder);
+ // Try to fetch first an object having the container name.
+ obj = gDirectory->Get(cont->GetName());
if (!obj) {
- Error("ImportWrappers", "Could not find object for container %s in file %s", cont->GetName(), filename);
+ Warning("ImportWrappers", "Could not import object for container %s in file %s:%s.\n Object will not be available in Terminate()",
+ cont->GetName(), filename, cont->GetFolderName());
continue;
}
wrap = new AliAnalysisDataWrapper(obj);
}
icont++;
if (fDebug > 1) {
- Printf(" Importing data for container %s", cont->GetName());
- if (strlen(filename)) Printf(" -> file %s", filename);
- else Printf("");
+ printf(" Importing data for container %s\n", cont->GetName());
+ if (strlen(filename)) printf(" -> file %s\n", filename);
+ else printf("\n");
}
cont->ImportData(wrap);
- }
- if (fDebug > 0) Printf("<-AliAnalysisManager::ImportWrappers(): %d containers imported", icont);
+ }
+ if (cdir) cdir->cd();
+ if (fDebug > 0) printf("<-AliAnalysisManager::ImportWrappers(): %d containers imported\n", icont);
}
//______________________________________________________________________________
void AliAnalysisManager::UnpackOutput(TList *source)
{
// Called by AliAnalysisSelector::Terminate only on the client.
- if (fDebug > 0) Printf("->AliAnalysisManager::UnpackOutput()");
+ if (fDebug > 0) printf("->AliAnalysisManager::UnpackOutput()\n");
if (!source) {
Error("UnpackOutput", "No target. Aborting.");
return;
}
- if (fDebug > 1) Printf(" Source list contains %d containers", source->GetSize());
+ if (fDebug > 1) printf(" Source list contains %d containers\n", source->GetSize());
if (fMode == kProofAnalysis) ImportWrappers(source);
task->CheckNotify(kTRUE);
// If task is active, execute it
if (task->IsPostEventLoop() && task->IsActive()) {
- if (fDebug > 0) Printf("== Executing post event loop task %s", task->GetName());
+ if (fDebug > 0) printf("== Executing post event loop task %s\n", task->GetName());
task->ExecuteTask();
}
}
}
}
- if (fDebug > 0) Printf("<-AliAnalysisManager::UnpackOutput()");
+ if (fDebug > 0) printf("<-AliAnalysisManager::UnpackOutput()\n");
}
//______________________________________________________________________________
// The Terminate() function is the last function to be called during
// a query. It always runs on the client, it can be used to present
// the results graphically.
- if (fDebug > 0) Printf("->AliAnalysisManager::Terminate()");
+ if (fDebug > 0) printf("->AliAnalysisManager::Terminate()\n");
AliAnalysisTask *task;
TIter next(fTasks);
// Call Terminate() for tasks
if (fOutputEventHandler) filename = fOutputEventHandler->GetOutputFileName();
TFile *aodfile = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
if (aodfile) {
- if (fDebug > 1) Printf("Writing output handler file: %s", filename);
+ if (fDebug > 1) printf("Writing output handler file: %s\n", filename);
aodfile->Write();
continue;
}
}
if (!strlen(filename)) continue;
if (!output->GetData()) continue;
- TFile *file = output->GetFile();
TDirectory *opwd = gDirectory;
- file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+ TFile *file = output->GetFile();
+ if (!file) file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
if (!file) file = new TFile(filename, "RECREATE");
- if (file->IsZombie()) continue;
+ if (file->IsZombie()) {
+ Error("Terminate", "Cannot open output file %s", filename);
+ continue;
+ }
output->SetFile(file);
file->cd();
- if (fDebug > 1) Printf(" writing output data %s to file %s", output->GetData()->GetName(), file->GetName());
+ // Check for a folder request
+ TString dir = output->GetFolderName();
+ if (!dir.IsNull()) {
+ if (!file->GetDirectory(dir)) file->mkdir(dir);
+ file->cd(dir);
+ }
+ if (fDebug > 1) printf(" writing output data %s to file %s:%s\n", output->GetData()->GetName(), file->GetName(), output->GetFolderName());
if (output->GetData()->InheritsFrom(TCollection::Class())) {
// If data is a collection, we set the name of the collection
// as the one of the container and we save as a single key.
TDirectory *opwd = gDirectory;
if (output->GetFile()) {
output->GetFile()->Close();
+ output->SetFile(NULL);
// Copy merged outputs in alien if requested
if (fSpecialOutputLocation.Length() &&
fSpecialOutputLocation.BeginsWith("alien://")) {
out.open("outputs_valid", ios::out);
out.close();
}
- if (fDebug > 0) Printf("<-AliAnalysisManager::Terminate()");
+ if (fDebug > 0) printf("<-AliAnalysisManager::Terminate()\n");
}
//______________________________________________________________________________
TClass *datatype, EAliAnalysisContType type, const char *filename)
{
// Create a data container of a certain type. Types can be:
-// kExchangeContainer = 0, used to exchange date between tasks
+// kExchangeContainer = 0, used to exchange data between tasks
// kInputContainer = 1, used to store input data
-// kOutputContainer = 2, used for posting results
+// kOutputContainer = 2, used for writing result to a file
+// filename: composed by file#folder (e.g. results.root#INCLUSIVE) - will write
+// the output object to a folder inside the output file
if (fContainers->FindObject(name)) {
Error("CreateContainer","A container named %s already defined !",name);
return NULL;
Error("StartAnalysis","Analysis manager was not initialized !");
return;
}
- if (fDebug > 0) Printf("StartAnalysis %s",GetName());
+ if (fDebug > 0) printf("StartAnalysis %s\n",GetName());
TString anaType = type;
anaType.ToLower();
fMode = kLocalAnalysis;
Error("StartAnalysis","Analysis manager was not initialized !");
return;
}
- if (fDebug > 0) Printf("StartAnalysis %s",GetName());
+ if (fDebug > 0) printf("StartAnalysis %s\n",GetName());
TString anaType = type;
anaType.ToLower();
if (!anaType.Contains("proof")) {
}
//______________________________________________________________________________
-TFile *AliAnalysisManager::OpenProofFile(const char *filename, const char *option)
+TFile *AliAnalysisManager::OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof)
+{
+// Opens according the option the file specified by cont->GetFileName() and changes
+// current directory to cont->GetFolderName(). If the file was already opened, it
+// checks if the option UPDATE was preserved. File open via TProofOutputFile can
+// be optionally ignored.
+ AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+ TString filename = cont->GetFileName();
+ TFile *f = NULL;
+ if (filename.IsNull()) {
+ ::Error("AliAnalysisManager::OpenFile", "No file name specified for container %s", cont->GetName());
+ return NULL;
+ }
+ if (mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis && cont->IsSpecialOutput()
+ && !ignoreProof)
+ f = mgr->OpenProofFile(cont,option);
+ else {
+ // Check first if the file is already opened
+ TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+ if (f) {
+ // Check if option "UPDATE" was preserved
+ TString opt(option);
+ opt.ToUpper();
+ if ((opt=="UPDATE") && (opt!=f->GetOption()))
+ ::Fatal("AliAnalysisManager::OpenFile", "File %s already opened, but not in UPDATE mode!", cont->GetFileName());
+ } else {
+ f = new TFile(filename, option);
+ }
+ }
+ if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
+ cont->SetFile(f);
+ // Cd to file
+ f->cd();
+ // Check for a folder request
+ TString dir = cont->GetFolderName();
+ if (!dir.IsNull()) {
+ if (!f->GetDirectory(dir)) f->mkdir(dir);
+ f->cd(dir);
+ }
+ return f;
+ }
+ ::Fatal("AliAnalysisManager::OpenFile", "File %s could not be opened", filename.Data());
+ cont->SetFile(NULL);
+ return NULL;
+}
+
+//______________________________________________________________________________
+TFile *AliAnalysisManager::OpenProofFile(AliAnalysisDataContainer *cont, const char *option)
{
// Opens a special output file used in PROOF.
- char line[256];
- if (fMode!=kProofAnalysis || !fSelector) {
- Error("OpenProofFile","Cannot open PROOF file %s",filename);
- return NULL;
- }
- if (fSpecialOutputLocation.Length()) {
- TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
- if (!f) f = new TFile(filename, option);
+ TString line;
+ TString filename = cont->GetFileName();
+ TFile *f = NULL;
+ if (fMode!=kProofAnalysis || !fSelector) {
+ Fatal("OpenProofFile","Cannot open PROOF file %s: no PROOF or selector",filename.Data());
+ return NULL;
+ }
+ if (fSpecialOutputLocation.Length()) {
+ f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+ if (f) {
+ // Check if option "UPDATE" was preserved
+ TString opt(option);
+ opt.ToUpper();
+ if ((opt=="UPDATE") && (opt!=f->GetOption()))
+ Fatal("OpenProofFile", "File %s already opened, but not in UPDATE mode!", cont->GetFileName());
+ } else {
+ f = new TFile(filename, option);
+ }
+ if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
+ cont->SetFile(f);
+ // Cd to file
+ f->cd();
+ // Check for a folder request
+ TString dir = cont->GetFolderName();
+ if (dir.Length()) {
+ if (!f->GetDirectory(dir)) f->mkdir(dir);
+ f->cd(dir);
+ }
return f;
- }
- sprintf(line, "TProofOutputFile *pf = new TProofOutputFile(\"%s\");", filename);
- if (fDebug > 1) Printf("=== %s", line);
- gROOT->ProcessLine(line);
- sprintf(line, "pf->OpenFile(\"%s\");", option);
- gROOT->ProcessLine(line);
- if (fDebug > 1) {
+ }
+ Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
+ cont->SetFile(NULL);
+ return NULL;
+ }
+ // Check if there is already a proof output file in the output list
+ TObject *pof = fSelector->GetOutputList()->FindObject(filename);
+ if (pof) {
+ // Get the actual file
+ line = Form("((TProofOutputFile*)0x%lx)->GetFileName();", (ULong_t)pof);
+ filename = (const char*)gROOT->ProcessLine(line);
+ f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+ if (!f) Fatal("OpenProofFile", "Proof output file found but no file opened for %s", filename.Data());
+ // Check if option "UPDATE" was preserved
+ TString opt(option);
+ opt.ToUpper();
+ if ((opt=="UPDATE") && (opt!=f->GetOption()))
+ Fatal("OpenProofFile", "File %s already opened, but not in UPDATE mode!", cont->GetFileName());
+ } else {
+ line = Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\");", filename.Data());
+ if (fDebug > 1) printf("=== %s\n", line.Data());
+ gROOT->ProcessLine(line);
+ line = Form("pf->OpenFile(\"%s\");", option);
+ gROOT->ProcessLine(line);
+ f = gFile;
+ if (fDebug > 1) {
gROOT->ProcessLine("pf->Print()");
- Printf(" == proof file name: %s", gFile->GetName());
- }
- sprintf(line, "((TList*)0x%lx)->Add(pf);",(ULong_t)fSelector->GetOutputList());
- if (fDebug > 1) Printf("=== %s", line);
- gROOT->ProcessLine(line);
- return gFile;
+ printf(" == proof file name: %s", f->GetName());
+ }
+ // Add to proof output list
+ line = Form("((TList*)0x%lx)->Add(pf);",(ULong_t)fSelector->GetOutputList());
+ if (fDebug > 1) printf("=== %s", line.Data());
+ gROOT->ProcessLine(line);
+ }
+ if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
+ cont->SetFile(f);
+ // Cd to file
+ f->cd();
+ // Check for a folder request
+ TString dir = cont->GetFolderName();
+ if (!dir.IsNull()) {
+ if (!f->GetDirectory(dir)) f->mkdir(dir);
+ f->cd(dir);
+ }
+ return f;
+ }
+ Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
+ cont->SetFile(NULL);
+ return NULL;
}
//______________________________________________________________________________
TIter next(fOutputs);
AliAnalysisDataContainer *output;
TDirectory *cdir = gDirectory;
+ TString openedFiles;
while ((output=(AliAnalysisDataContainer*)next())) {
TString filename = output->GetFileName();
if (filename == "default") {
filename = fOutputEventHandler->GetOutputFileName();
}
// Check if the file is closed
+ if (openedFiles.Contains(filename)) continue;;
TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
if (file) {
Warning("ValidateOutputs", "File %s was not closed. Closing.", filename.Data());
return kFALSE;
}
file->Close();
+ openedFiles += filename;
+ openedFiles += " ";
}
cdir->cd();
return kTRUE;