ROOT logo
void Load(const char* taskName, Bool_t debug)
{
	TString compileTaskName;
	compileTaskName.Form("%s.cxx++", taskName);
	if (debug)
		compileTaskName += "g";
	
	if (gProof) {
		gProof->Load(compileTaskName);
	} else
		gROOT->Macro(compileTaskName);
	
	// Enable debug printouts
	if (debug)
		{
			AliLog::SetClassDebugLevel(taskName, AliLog::kDebug+2);
		}
	else
		AliLog::SetClassDebugLevel(taskName, AliLog::kWarning);
}

void runTrackletsTaskOnProof(const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool_t aDebug = kFALSE, Int_t aProof = kFALSE, Bool_t mcFlag = kFALSE)
{
	// 
	// aProof option: 0 no proof
	//                1 proof with chain
	//                2 proof with dataset
	//
	
	if (nRuns < 0)
		nRuns = 1234567890;
	
	if (aProof)
		{
			gEnv->SetValue("XSec.GSI.DelegProxy","2");
			TProof::Open("alicecaf"); 
			gProof->Exec("TGrid::Connect\(\"alien://\"\), kTRUE");
			
			// Enable the needed package
			gProof->UploadPackage("$ALICE_ROOT/STEERBase");
			gProof->EnablePackage("$ALICE_ROOT/STEERBase");
			gProof->UploadPackage("$ALICE_ROOT/ESD");
			gProof->EnablePackage("$ALICE_ROOT/ESD");
			gProof->UploadPackage("$ALICE_ROOT/AOD");
			gProof->EnablePackage("$ALICE_ROOT/AOD");
			gProof->UploadPackage("$ALICE_ROOT/ANALYSIS");
			gProof->EnablePackage("$ALICE_ROOT/ANALYSIS");
			gProof->UploadPackage("$ALICE_ROOT/ANALYSISalice");
			gProof->EnablePackage("$ALICE_ROOT/ANALYSISalice");
		}
	else
		{
			gSystem->AddIncludePath("-I${ALICE_ROOT}/include/"); 
			gSystem->Load("libVMC");
			gSystem->Load("libTree");
			gSystem->Load("libProof");
			gSystem->Load("libSTEERBase");
			gSystem->Load("libESD");
			gSystem->Load("libAOD");
			gSystem->Load("libANALYSIS");
			gSystem->Load("libANALYSISalice");
		}
	
	// Create the analysis manager
	mgr = new AliAnalysisManager;
	
	// Add ESD handler
	AliESDInputHandler* esdH = new AliESDInputHandler;
	esdH->SetInactiveBranches("AliESDACORDE AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks Kinks Cascades MuonTracks TrdTracks CaloClusters");
	mgr->SetInputEventHandler(esdH);
	
	cInput = mgr->GetCommonInputContainer();
	
	Load("../AliTrackletsTask", aDebug);
	task = new AliTrackletsTask();
	gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
	printf("The flag for the Physics selection is set to %d\n",(Int_t)mcFlag);
	AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(mcFlag);
		
	mgr->AddTask(task);
	
	// Attach input
	mgr->ConnectInput(task, 0, cInput);
	
	// Attach output
	cOutput = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer,"output.root");
	mgr->ConnectOutput(task, 0, cOutput);
	
	// Enable debug printouts
	if (aDebug)
		mgr->SetDebugLevel(2);
	
	// graphical settings 
	gROOT->SetStyle("Plain");
	gStyle->SetPalette(1);
	gStyle->SetOptStat(111);
	gStyle->SetPalette(1);
	gStyle->SetCanvasColor(0);
	gStyle->SetFrameFillColor(0);
	gStyle->SetOptTitle(0);
	
	// Run analysis
	mgr->InitAnalysis();
	mgr->PrintStatus();
	
	if (aProof == 2){
		// process dataset			
		mgr->StartAnalysis("proof", data, nRuns, offset);
	}
	else if (aProof == 3){
		gROOT->ProcessLine(".L CreateChainFromDataSet.C");
		ds = gProof->GetDataSet(data)->GetStagedSubset();
		chain = CreateChainFromDataSet(ds);
		mgr->StartAnalysis("local", chain, nRuns, offset);
	}
	else{
		// Create chain of input files
		TGrid::Connect("alien://");
		gROOT->LoadMacro("../PWG0/CreateESDChain.C");
		chain = CreateESDChain(data, nRuns, offset,kTRUE);			
		mgr->StartAnalysis((aProof > 0) ? "proof" : "local", chain);
	}
}
 runTrackletsTaskOnProof.C:1
 runTrackletsTaskOnProof.C:2
 runTrackletsTaskOnProof.C:3
 runTrackletsTaskOnProof.C:4
 runTrackletsTaskOnProof.C:5
 runTrackletsTaskOnProof.C:6
 runTrackletsTaskOnProof.C:7
 runTrackletsTaskOnProof.C:8
 runTrackletsTaskOnProof.C:9
 runTrackletsTaskOnProof.C:10
 runTrackletsTaskOnProof.C:11
 runTrackletsTaskOnProof.C:12
 runTrackletsTaskOnProof.C:13
 runTrackletsTaskOnProof.C:14
 runTrackletsTaskOnProof.C:15
 runTrackletsTaskOnProof.C:16
 runTrackletsTaskOnProof.C:17
 runTrackletsTaskOnProof.C:18
 runTrackletsTaskOnProof.C:19
 runTrackletsTaskOnProof.C:20
 runTrackletsTaskOnProof.C:21
 runTrackletsTaskOnProof.C:22
 runTrackletsTaskOnProof.C:23
 runTrackletsTaskOnProof.C:24
 runTrackletsTaskOnProof.C:25
 runTrackletsTaskOnProof.C:26
 runTrackletsTaskOnProof.C:27
 runTrackletsTaskOnProof.C:28
 runTrackletsTaskOnProof.C:29
 runTrackletsTaskOnProof.C:30
 runTrackletsTaskOnProof.C:31
 runTrackletsTaskOnProof.C:32
 runTrackletsTaskOnProof.C:33
 runTrackletsTaskOnProof.C:34
 runTrackletsTaskOnProof.C:35
 runTrackletsTaskOnProof.C:36
 runTrackletsTaskOnProof.C:37
 runTrackletsTaskOnProof.C:38
 runTrackletsTaskOnProof.C:39
 runTrackletsTaskOnProof.C:40
 runTrackletsTaskOnProof.C:41
 runTrackletsTaskOnProof.C:42
 runTrackletsTaskOnProof.C:43
 runTrackletsTaskOnProof.C:44
 runTrackletsTaskOnProof.C:45
 runTrackletsTaskOnProof.C:46
 runTrackletsTaskOnProof.C:47
 runTrackletsTaskOnProof.C:48
 runTrackletsTaskOnProof.C:49
 runTrackletsTaskOnProof.C:50
 runTrackletsTaskOnProof.C:51
 runTrackletsTaskOnProof.C:52
 runTrackletsTaskOnProof.C:53
 runTrackletsTaskOnProof.C:54
 runTrackletsTaskOnProof.C:55
 runTrackletsTaskOnProof.C:56
 runTrackletsTaskOnProof.C:57
 runTrackletsTaskOnProof.C:58
 runTrackletsTaskOnProof.C:59
 runTrackletsTaskOnProof.C:60
 runTrackletsTaskOnProof.C:61
 runTrackletsTaskOnProof.C:62
 runTrackletsTaskOnProof.C:63
 runTrackletsTaskOnProof.C:64
 runTrackletsTaskOnProof.C:65
 runTrackletsTaskOnProof.C:66
 runTrackletsTaskOnProof.C:67
 runTrackletsTaskOnProof.C:68
 runTrackletsTaskOnProof.C:69
 runTrackletsTaskOnProof.C:70
 runTrackletsTaskOnProof.C:71
 runTrackletsTaskOnProof.C:72
 runTrackletsTaskOnProof.C:73
 runTrackletsTaskOnProof.C:74
 runTrackletsTaskOnProof.C:75
 runTrackletsTaskOnProof.C:76
 runTrackletsTaskOnProof.C:77
 runTrackletsTaskOnProof.C:78
 runTrackletsTaskOnProof.C:79
 runTrackletsTaskOnProof.C:80
 runTrackletsTaskOnProof.C:81
 runTrackletsTaskOnProof.C:82
 runTrackletsTaskOnProof.C:83
 runTrackletsTaskOnProof.C:84
 runTrackletsTaskOnProof.C:85
 runTrackletsTaskOnProof.C:86
 runTrackletsTaskOnProof.C:87
 runTrackletsTaskOnProof.C:88
 runTrackletsTaskOnProof.C:89
 runTrackletsTaskOnProof.C:90
 runTrackletsTaskOnProof.C:91
 runTrackletsTaskOnProof.C:92
 runTrackletsTaskOnProof.C:93
 runTrackletsTaskOnProof.C:94
 runTrackletsTaskOnProof.C:95
 runTrackletsTaskOnProof.C:96
 runTrackletsTaskOnProof.C:97
 runTrackletsTaskOnProof.C:98
 runTrackletsTaskOnProof.C:99
 runTrackletsTaskOnProof.C:100
 runTrackletsTaskOnProof.C:101
 runTrackletsTaskOnProof.C:102
 runTrackletsTaskOnProof.C:103
 runTrackletsTaskOnProof.C:104
 runTrackletsTaskOnProof.C:105
 runTrackletsTaskOnProof.C:106
 runTrackletsTaskOnProof.C:107
 runTrackletsTaskOnProof.C:108
 runTrackletsTaskOnProof.C:109
 runTrackletsTaskOnProof.C:110
 runTrackletsTaskOnProof.C:111
 runTrackletsTaskOnProof.C:112
 runTrackletsTaskOnProof.C:113
 runTrackletsTaskOnProof.C:114
 runTrackletsTaskOnProof.C:115
 runTrackletsTaskOnProof.C:116
 runTrackletsTaskOnProof.C:117
 runTrackletsTaskOnProof.C:118
 runTrackletsTaskOnProof.C:119
 runTrackletsTaskOnProof.C:120
 runTrackletsTaskOnProof.C:121
 runTrackletsTaskOnProof.C:122
 runTrackletsTaskOnProof.C:123
 runTrackletsTaskOnProof.C:124