+ if (output->GetData() && !output->IsSpecialOutput()) {
+ if (output->GetProducer()->IsPostEventLoop()) continue;
+
+ const char *filename = output->GetFileName();
+ if (!(strcmp(filename, "default"))) {
+ if (fOutputEventHandler) filename = fOutputEventHandler->GetOutputFileName();
+ }
+ if (strlen(filename)) {
+ TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+ TDirectory *opwd = gDirectory;
+ if (file) file->cd();
+ else file = new TFile(filename, "RECREATE");
+ if (file->IsZombie()) continue;
+ // Clear file list to release object ownership to user.
+ // Save data to file, then close.
+ file->Clear();
+ output->GetData()->Write();
+ file->Close();
+ // Set null directory to histograms and trees.
+ TMethodCall callEnv;
+ if (output->GetData()->IsA())
+ callEnv.InitWithPrototype(output->GetData()->IsA(), "SetDirectory", "TDirectory*");
+ if (callEnv.IsValid()) {
+ callEnv.SetParam(Long_t(0));
+ callEnv.Execute(output->GetData());
+ }
+ // Restore current directory
+ if (opwd) opwd->cd();
+ }
+ AliAnalysisDataWrapper *wrap = output->ExportData();
+ // Output wrappers must delete data after merging (AG 13/11/07)
+ wrap->SetDeleteData(kTRUE);
+ if (fDebug > 1) printf(" Packing container %s...\n", output->GetName());
+ target->Add(wrap);
+ }
+ // Special outputs files are closed and copied on the remote location
+ if (output->IsSpecialOutput() && strlen(output->GetFileName())) {
+ TDirectory *opwd = gDirectory;
+ TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(output->GetFileName());
+ if (!file) continue;
+ file->cd();
+ if (output->GetData()) output->GetData()->Write();
+ file->Close();
+ if (opwd) opwd->cd();
+ if (strlen(fSpecialOutputLocation.Data())) {
+ TString remote = fSpecialOutputLocation;
+ remote += "/";
+ Int_t gid = gROOT->ProcessLine("gProofServ->GetGroupId();");
+ remote += Form("%s_%d_", gSystem->HostName(), gid);
+ remote += output->GetFileName();
+ TFile::Cp(output->GetFileName(), remote.Data());
+ } else {
+ // No special location specified-> use TProofFile as merging utility
+ char line[256];
+ sprintf(line, "((TList*)0x%lx)->Add(new TProofFile(\"%s\"));",
+ (ULong_t)target, output->GetFileName());
+ gROOT->ProcessLine(line);
+ }
+ }