+ if (fInputEventHandler) fInputEventHandler ->TerminateIO();
+ if (fOutputEventHandler) fOutputEventHandler ->TerminateIO();
+ if (fMCtruthEventHandler) fMCtruthEventHandler->TerminateIO();
+ TObjArray *allOutputs = new TObjArray();
+ Int_t icont;
+ for (icont=0; icont<fOutputs->GetEntriesFast(); icont++) allOutputs->Add(fOutputs->At(icont));
+ if (!IsSkipTerminate())
+ for (icont=0; icont<fParamCont->GetEntriesFast(); icont++) allOutputs->Add(fParamCont->At(icont));
+ TIter next1(allOutputs);
+ TString handlerFile = "";
+ if (fOutputEventHandler) {
+ handlerFile = fOutputEventHandler->GetOutputFileName();
+ }
+ while ((output=(AliAnalysisDataContainer*)next1())) {
+ // Special outputs or grid files have the files already closed and written.
+ if (fMode == kGridAnalysis) continue;
+ if (fMode == kProofAnalysis) {
+ if (output->IsSpecialOutput() || output->IsRegisterDataset()) continue;
+ }
+ const char *filename = output->GetFileName();
+ TString openoption = "RECREATE";
+ if (!(strcmp(filename, "default"))) continue;
+ if (!strlen(filename)) continue;
+ if (!output->GetData()) continue;
+ TDirectory *opwd = gDirectory;
+ TFile *file = output->GetFile();
+ if (!file) file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+ if (!file) {
+ //if (handlerFile == filename && !gSystem->AccessPathName(filename)) openoption = "UPDATE";
+ if (!gSystem->AccessPathName(filename)) openoption = "UPDATE";
+ if (fDebug>0) printf("Opening file: %s option=%s\n",filename, openoption.Data());
+ file = new TFile(filename, openoption);
+ } else {
+ if (fDebug>0) printf("File already opened: %s\n", filename);
+ }
+ if (file->IsZombie()) {
+ Error("Terminate", "Cannot open output file %s", filename);
+ continue;
+ }
+ output->SetFile(file);
+ file->cd();
+ // Check for a folder request
+ TString dir = output->GetFolderName();
+ if (!dir.IsNull()) {
+ if (!file->GetDirectory(dir)) file->mkdir(dir);
+ file->cd(dir);
+ }
+ if (fDebug > 0) printf("...writing container %s to file %s:%s\n", output->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.
+ TCollection *coll = (TCollection*)output->GetData();
+ coll->SetName(output->GetName());
+ coll->Write(output->GetName(), TObject::kSingleKey);
+ } else {
+ if (output->GetData()->InheritsFrom(TTree::Class())) {
+ TTree *tree = (TTree*)output->GetData();
+ tree->SetDirectory(file);
+ tree->AutoSave();
+ } else {
+ output->GetData()->Write();
+ }
+ }
+ if (opwd) opwd->cd();
+ }
+ next1.Reset();
+ while ((output=(AliAnalysisDataContainer*)next1())) {
+ // Close all files at output
+ 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://")) {
+ Info("Terminate", "Copy file %s to %s", output->GetFile()->GetName(),fSpecialOutputLocation.Data());
+ TFile::Cp(output->GetFile()->GetName(),
+ Form("%s/%s", fSpecialOutputLocation.Data(), output->GetFile()->GetName()));
+ }
+ }
+ if (opwd) opwd->cd();
+ }
+ delete allOutputs;
+
+ if (getsysInfo) {
+ TDirectory *cdir = gDirectory;
+ TFile f("syswatch.root", "RECREATE");
+ TH1 *hist;
+ TString cut;
+ if (!f.IsZombie()) {
+ TTree *tree = AliSysInfo::MakeTree("syswatch.log");
+ tree->SetName("syswatch");
+ tree->SetMarkerStyle(kCircle);
+ tree->SetMarkerColor(kBlue);
+ tree->SetMarkerSize(0.5);
+ if (!gROOT->IsBatch()) {
+ tree->SetAlias("event", "id0");
+ tree->SetAlias("task", "id1");
+ tree->SetAlias("stage", "id2");
+ // Already defined aliases
+ // tree->SetAlias("deltaT","stampSec-stampOldSec");
+ // tree->SetAlias("T","stampSec-first");
+ // tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)");
+ // tree->SetAlias("VM","pI.fMemVirtual");
+ TCanvas *canvas = new TCanvas("SysInfo","SysInfo",10,10,1200,800);
+ Int_t npads = 1 /*COO plot for all tasks*/ +
+ fTopTasks->GetEntries() /*Exec plot per task*/ +
+ 1 /*Terminate plot for all tasks*/ +
+ 1; /*vm plot*/
+
+ Int_t iopt = (Int_t)TMath::Sqrt((Double_t)npads);
+ if (npads<iopt*(iopt+1))
+ canvas->Divide(iopt, iopt+1, 0.01, 0.01);
+ else
+ canvas->Divide(iopt+1, iopt+1, 0.01, 0.01);
+ Int_t ipad = 1;
+ // draw the plot of deltaVM for Exec for each task
+ for (itask=0; itask<fTopTasks->GetEntriesFast(); itask++) {
+ task = (AliAnalysisTask*)fTopTasks->At(itask);
+ canvas->cd(ipad++);
+ cut = Form("task==%d && stage==1", itask);
+ tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
+ hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
+ if (hist) {
+ hist->SetTitle(Form("%s: Exec dVM[kB]/event", task->GetName()));
+ hist->GetYaxis()->SetTitle("deltaVM [kB]");
+ }
+ }
+ // Draw the plot of deltaVM for CreateOutputObjects for all tasks
+ canvas->cd(ipad++);
+ tree->SetMarkerStyle(kFullTriangleUp);
+ tree->SetMarkerColor(kRed);
+ tree->SetMarkerSize(0.8);
+ cut = "task>=0 && task<1000 && stage==0";
+ tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
+ hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
+ if (hist) {
+ hist->SetTitle("Memory in CreateOutputObjects()");
+ hist->GetYaxis()->SetTitle("deltaVM [kB]");
+ hist->GetXaxis()->SetTitle("task");
+ }
+ // draw the plot of deltaVM for Terminate for all tasks
+ canvas->cd(ipad++);
+ tree->SetMarkerStyle(kOpenSquare);
+ tree->SetMarkerColor(kMagenta);
+ cut = "task>=0 && task<1000 && stage==2";
+ tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
+ hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
+ if (hist) {
+ hist->SetTitle("Memory in Terminate()");
+ hist->GetYaxis()->SetTitle("deltaVM [kB]");
+ hist->GetXaxis()->SetTitle("task");
+ }
+ // Full VM profile
+ canvas->cd(ipad++);
+ tree->SetMarkerStyle(kFullCircle);
+ tree->SetMarkerColor(kGreen);
+ cut = Form("task==%d && stage==1",fTopTasks->GetEntriesFast()-1);
+ tree->Draw("VM:event",cut,"", 1234567890, 0);
+ hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
+ if (hist) {
+ hist->SetTitle("Virtual memory");
+ hist->GetYaxis()->SetTitle("VM [kB]");
+ }
+ canvas->Modified();
+ }
+ tree->SetMarkerStyle(kCircle);
+ tree->SetMarkerColor(kBlue);
+ tree->SetMarkerSize(0.5);
+ tree->Write();
+ f.Close();
+ delete tree;
+ }
+ if (cdir) cdir->cd();
+ }
+ // Validate the output files
+ if (ValidateOutputFiles()) {
+ ofstream out;
+ out.open("outputs_valid", ios::out);
+ out.close();
+ }
+ if (fDebug > 0) printf("<-AliAnalysisManager::Terminate()\n");