+
+//______________________________________________________________________________
+void AliAnalysisManager::SetInputEventHandler(AliVEventHandler* handler)
+{
+// Set the input event handler and create a container for it.
+ fInputEventHandler = handler;
+ fCommonInput = CreateContainer("cAUTO_INPUT", TChain::Class(), AliAnalysisManager::kInputContainer);
+// Warning("SetInputEventHandler", " An automatic input container for the input chain was created.\nPlease use: mgr->GetCommonInputContainer() to access it.");
+}
+
+//______________________________________________________________________________
+void AliAnalysisManager::SetOutputEventHandler(AliVEventHandler* handler)
+{
+// Set the input event handler and create a container for it.
+ fOutputEventHandler = handler;
+ fCommonOutput = CreateContainer("cAUTO_OUTPUT", TTree::Class(), AliAnalysisManager::kOutputContainer, "default");
+ fCommonOutput->SetSpecialOutput();
+// Warning("SetOutputEventHandler", " An automatic output container for the output tree was created.\nPlease use: mgr->GetCommonOutputContainer() to access it.");
+}
+
+//______________________________________________________________________________
+void AliAnalysisManager::RegisterExtraFile(const char *fname)
+{
+// This method is used externally to register output files which are not
+// connected to any output container, so that the manager can properly register,
+// retrieve or merge them when running in distributed mode. The file names are
+// separated by blancs. The method has to be called in MyAnalysisTask::LocalInit().
+ if (fExtraFiles.Length()) fExtraFiles += " ";
+ fExtraFiles += fname;
+}
+
+//______________________________________________________________________________
+Bool_t AliAnalysisManager::GetFileFromWrapper(const char *filename, TList *source)
+{
+// Copy a file from the location specified ina the wrapper with the same name from the source list.
+ char full_path[512];
+ char ch_url[512];
+ TObject *pof = source->FindObject(filename);
+ if (!pof || !pof->InheritsFrom("TProofOutputFile")) {
+ Error("GetFileFromWrapper", "TProofOutputFile object not found in output list for file %s", filename);
+ return kFALSE;
+ }
+ gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", ((TProofOutputFile*)0x%lx)->GetOutputFileName();)", full_path, pof));
+ gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", gProof->GetUrl();)", ch_url));
+ TString clientUrl(ch_url);
+ TString full_path_str(full_path);
+ if (clientUrl.Contains("localhost")){
+ TObjArray* array = full_path_str.Tokenize ( "//" );
+ TObjString *strobj = ( TObjString *)array->At(1);
+ TObjArray* arrayPort = strobj->GetString().Tokenize ( ":" );
+ TObjString *strobjPort = ( TObjString *) arrayPort->At(1);
+ full_path_str.ReplaceAll(strobj->GetString().Data(),"localhost:PORT");
+ full_path_str.ReplaceAll(":PORT",Form(":%s",strobjPort->GetString().Data()));
+ if (fDebug > 1) Info("GetFileFromWrapper","Using tunnel from %s to %s",full_path_str.Data(),filename);
+ delete arrayPort;
+ delete array;
+ }
+ if (fDebug > 1)
+ Info("GetFileFromWrapper","Copying file %s from PROOF scratch space", full_path_str.Data());
+ Bool_t gotit = TFile::Cp(full_path_str.Data(), filename);
+ if (!gotit)
+ Error("GetFileFromWrapper", "Could not get file %s from proof scratch space", filename);
+ return gotit;
+}
+
+//______________________________________________________________________________
+void AliAnalysisManager::GetAnalysisTypeString(TString &type) const
+{
+// Fill analysis type in the provided string.
+ switch (fMode) {
+ case kLocalAnalysis:
+ type = "local";
+ return;
+ case kProofAnalysis:
+ type = "proof";
+ return;
+ case kGridAnalysis:
+ type = "grid";
+ return;
+ case kMixingAnalysis:
+ type = "mix";
+ }
+}
+
+//______________________________________________________________________________
+Bool_t AliAnalysisManager::ValidateOutputFiles() const
+{
+// Validate all output files.
+ TIter next(fOutputs);
+ AliAnalysisDataContainer *output;
+ TDirectory *cdir = gDirectory;
+ TString openedFiles;
+ while ((output=(AliAnalysisDataContainer*)next())) {
+ if (output->IsRegisterDataset()) continue;
+ TString filename = output->GetFileName();
+ if (filename == "default") {
+ if (!fOutputEventHandler) continue;
+ filename = fOutputEventHandler->GetOutputFileName();
+ // Main AOD may not be there
+ if (gSystem->AccessPathName(filename)) continue;
+ }
+ // 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());
+ file->Close();
+ }
+ file = TFile::Open(filename);
+ if (!file || file->IsZombie() || file->TestBit(TFile::kRecovered)) {
+ Error("ValidateOutputs", "Output file <%s> was not created or invalid", filename.Data());
+ cdir->cd();
+ return kFALSE;
+ }
+ file->Close();
+ openedFiles += filename;
+ openedFiles += " ";
+ }
+ cdir->cd();
+ return kTRUE;
+}
+
+//______________________________________________________________________________
+void AliAnalysisManager::ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch *watch, Bool_t last, Bool_t refresh)
+{
+// Implements a nice text mode progress bar.
+ static Long64_t icount = 0;
+ static TString oname;
+ static TString nname;
+ static Long64_t ocurrent = 0;
+ static Long64_t osize = 0;
+ static Int_t oseconds = 0;
+ static TStopwatch *owatch = 0;
+ static Bool_t oneoftwo = kFALSE;
+ static Int_t nrefresh = 0;
+ static Int_t nchecks = 0;
+ const char symbol[4] = {'=','\\','|','/'};
+ char progress[11] = " ";
+ Int_t ichar = icount%4;
+
+ if (!refresh) {
+ nrefresh = 0;
+ if (!size) return;
+ owatch = watch;
+ oname = opname;
+ ocurrent = TMath::Abs(current);
+ osize = TMath::Abs(size);
+ if (ocurrent > osize) ocurrent=osize;
+ } else {
+ nrefresh++;
+ if (!osize) return;
+ }
+ icount++;
+ Double_t time = 0.;
+ Int_t hours = 0;
+ Int_t minutes = 0;
+ Int_t seconds = 0;
+ if (owatch && !last) {
+ owatch->Stop();
+ time = owatch->RealTime();
+ hours = (Int_t)(time/3600.);
+ time -= 3600*hours;
+ minutes = (Int_t)(time/60.);
+ time -= 60*minutes;
+ seconds = (Int_t)time;
+ if (refresh) {
+ if (oseconds==seconds) {
+ owatch->Continue();
+ return;
+ }
+ oneoftwo = !oneoftwo;
+ }
+ oseconds = seconds;
+ }
+ if (refresh && oneoftwo) {
+ nname = oname;
+ if (nchecks <= 0) nchecks = nrefresh+1;
+ Int_t pctdone = (Int_t)(100.*nrefresh/nchecks);
+ oname = Form(" == %d%% ==", pctdone);
+ }
+ Double_t percent = 100.0*ocurrent/osize;
+ Int_t nchar = Int_t(percent/10);
+ if (nchar>10) nchar=10;
+ Int_t i;
+ for (i=0; i<nchar; i++) progress[i] = '=';
+ progress[nchar] = symbol[ichar];
+ for (i=nchar+1; i<10; i++) progress[i] = ' ';
+ progress[10] = '\0';
+ oname += " ";
+ oname.Remove(20);
+ if(size<10000) fprintf(stderr, "%s [%10s] %4lld ", oname.Data(), progress, ocurrent);
+ else if(size<100000) fprintf(stderr, "%s [%10s] %5lld ",oname.Data(), progress, ocurrent);
+ else fprintf(stderr, "%s [%10s] %7lld ",oname.Data(), progress, ocurrent);
+ if (time>0.) fprintf(stderr, "[%6.2f %%] TIME %.2d:%.2d:%.2d \r", percent, hours, minutes, seconds);
+ else fprintf(stderr, "[%6.2f %%]\r", percent);
+ if (refresh && oneoftwo) oname = nname;
+ if (owatch) owatch->Continue();
+ if (last) {
+ icount = 0;
+ owatch = 0;
+ ocurrent = 0;
+ osize = 0;
+ oseconds = 0;
+ oneoftwo = kFALSE;
+ nrefresh = 0;
+ fprintf(stderr, "\n");
+ }
+}