]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDAnalysisTask.C
Coverity fixes.
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDAnalysisTask.C
1 void AliHMPIDAnalysisTask()
2 {
3
4   //
5   // Macro to run the AliHMPIDAnalysisTask
6   // To use: copy this macro to your work directory, modify the global
7   // part to match your needs, then run root.
8   // root[0] .x AliHMPIDAnalysisTask.C
9   //
10
11   //______ Input settings
12   Int_t nEvents = 650000;           //on Proof
13   Int_t nOffset = 0;               //on Proof
14   Int_t nFile2Xml = 10;         //on Grid - how many ESD files to chain in xml
15   TString xmlName="HmpidCheckRun122080_test.xml";//new.xml";       //name of the xml collection created
16   Char_t *indataset = "/alice/sim/LHC10b4_114932";
17 //   char *indataset = "$HOME/HMPID/data/AliESDs.root";
18
19   //______ Select Local, Proof or Intercative Grid Analysis (but just only one :-))
20   Bool_t bLOCAL        = kFALSE;
21   Bool_t bPROOF        = kTRUE;
22   Bool_t bGRIDINT      = kFALSE;
23
24 //  AliLog::SetGlobalDebugLevel(2);
25 //  AliLog::SetGlobalLogLevel(0);
26
27
28   //______ Init data set chain
29   TString dataset(indataset);
30   TChain *chain = new TChain("esdTree");
31
32   //______ Define settings for PROOF
33   const char* proofNode = "alice-caf";
34   gEnv->SetValue("XSec.GSI.DelegProxy","2");
35   gSystem->SetIncludePath("-I. -I$HOME/HMPID -I$ALICE_ROOT/include -I$ROOTSYS/include");
36   gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
37   gSystem->Load("libTree.so");
38   gSystem->Load("libGeom.so");
39   gSystem->Load("libVMC.so");
40   gSystem->Load("libPhysics.so");
41   gSystem->Load("libSTEERBase");
42   gSystem->Load("libESD");
43   gSystem->Load("libAOD");
44   gSystem->Load("libANALYSIS");
45   gSystem->Load("libANALYSISalice");
46
47  //______ Create analysis manager
48    AliAnalysisManager *mgr  = new AliAnalysisManager("HMPID Analysis Train", "HMPID Analysis Train");
49    mgr->SetDebugLevel(0);
50
51    //______ Create input handler, default ESD
52    AliESDInputHandler *esdHandler = new AliESDInputHandler();
53    mgr->SetInputEventHandler(esdHandler);
54
55    //______ Create MC input handler
56    AliMCEventHandler* mcHandler = new AliMCEventHandler();
57    mgr->SetMCtruthEventHandler(mcHandler);
58
59    //______ Create default input container
60    AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
61    AliAnalysisDataContainer *hmpoutput= mgr->CreateContainer("hmpoutput", TList::Class(),AliAnalysisManager::kOutputContainer,"HmpidOutput.root");
62
63    if(bLOCAL)
64   {
65
66    Printf("========> Running LOCAL HMPID Analysis <=========");
67    gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
68    gSystem->Load("libSTEERBase");
69    gSystem->Load("libESD");
70    gSystem->Load("libAOD");
71    gSystem->Load("libANALYSIS");
72    gSystem->Load("libANALYSISalice");
73    //chain = CreateESDChain(dataset.Data());//,1,0,kFALSE,kFALSE,0);
74    chain->Add(indataset);
75    gROOT->LoadMacro("AliHMPIDAnalysisTask.cxx++g");//"AliHMPIDAnalysisTask.cxx++");
76    AliHMPIDAnalysisTask *hmpTask = new AliHMPIDAnalysisTask("HMPIDAnalysisTask");
77    mgr->AddTask(hmpTask);
78   }
79   else if(bPROOF)
80   {
81     Printf("========> Running PROOF HMPID Analysis <=========");
82     TProof::Open(proofNode);
83 //    gProof->SetParallel(2);
84     gProof->EnablePackage("VO_ALICE@AliRoot::v4-19-14-AN");   
85     gProof->Load(Form("%s/HMPID/AliHMPIDAnalysisTask.cxx++g",gSystem->Getenv("ALICE_ROOT")));
86 //    gProof->Load("AliHMPIDAnalysisTask.cxx++g");//"AliHMPIDAnalysisTask.cxx++");
87     AliHMPIDAnalysisTask *hmpTask = new AliHMPIDAnalysisTask("HMPIDAnalysisTask");
88     mgr->AddTask(hmpTask);
89   }
90   else if(bGRIDINT)
91   {
92     Printf("========> Running INTERCATIVE GRID HMPID Analysis <=========");
93     gSystem->Load("libSTEERBase");
94     gSystem->Load("libESD");
95     gSystem->Load("libANALYSIS");
96     gSystem->Load("libANALYSISalice");
97     //______ Add HMPID task
98     gSystem->SetIncludePath("-I. -I$HOME/HMPID -I$ALICE_ROOT/include -I$ROOTSYS/include");
99     gROOT->LoadMacro("$ALICE_ROOT/HMPID/AliHMPIDAnalysisTask.cxx++");
100
101
102     TGrid::Connect("alien://");
103     chain = CreateChainFromCollection(xmlName.Data(),"esdTree",nFile2Xml);
104     //gROOT->LoadMacro(Form("%s/HMPID/AliHMPIDAnalysisTask.cxx++g",gSystem->Getenv("ALICE_ROOT")));//"AliHMPIDAnalysisTask.cxx++");
105     //gROOT->LoadMacro("$ALICE_ROOT/HMPID/AliHMPIDAnalysisTask.cxx++");
106     AliHMPIDAnalysisTask *hmpTask = new AliHMPIDAnalysisTask("HMPIDAnalysisTask");
107     mgr->AddTask(hmpTask);
108      
109   }
110
111
112   if(bLOCAL)
113   {
114     //______ Add HMPID task
115     gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
116     gSystem->Load("libSTEERBase");
117     gSystem->Load("libESD");
118     gSystem->Load("libAOD");
119     gSystem->Load("libANALYSIS");
120     gSystem->Load("libANALYSISalice");
121   }
122   if ( bPROOF ) 
123   {
124     
125   }
126
127   mgr->ConnectInput(hmpTask,0,cinput);
128   mgr->ConnectOutput(hmpTask,0,hmpoutput);
129
130
131   if (mgr->InitAnalysis()) {
132     mgr->PrintStatus();
133     if(bLOCAL || bGRIDINT) mgr->StartAnalysis("local",chain);
134     else if(bPROOF) mgr->StartAnalysis("proof",dataset.Data(), nEvents,nOffset);
135   }
136 }   
137
138 //__________________________________________________________________________________
139 TChain *CreateChainFromCollection(const char* xmlfile, const char *treeName="esdTree",Int_t nFiles = 0)
140 {
141 // Create a chain from an alien collection.
142    TAlienCollection * myCollection  = TAlienCollection::Open(xmlfile);
143
144    if (!myCollection) {
145       ::Error("CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile);
146      return NULL ;
147    }
148
149   TChain* chain = new TChain(treeName);
150   myCollection->Reset();
151   Int_t iCount = 0;
152   while ( myCollection->Next() ){
153     if(nFiles!=0)iCount++;
154     if(iCount > nFiles)break;
155     chain->Add(myCollection->GetTURL("")) ;
156     Printf("Adding %s",myCollection->GetTURL(""));
157   }
158   chain->ls();
159   return chain;
160 }
161
162 //__________________________________________________________________________________
163 void SetupPar(char* pararchivename)
164 {
165   //Load par files, create analysis libraries
166   //For testing, if par file already decompressed and modified
167   //classes then do not decompress.
168
169   TString cdir(Form("%s", gSystem->WorkingDirectory() ));
170   TString parpar(Form("%s.par", pararchivename));
171
172   if (!gSystem->AccessPathName(pararchivename) ) {
173     TString processline = Form(".! tar xvzf %s",parpar.Data());
174     gROOT->ProcessLine(processline.Data());
175   }
176
177   TString ocwd = gSystem->WorkingDirectory();
178   gSystem->ChangeDirectory(pararchivename);
179
180   // check for BUILD.sh and execute
181   if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
182     printf("*******************************\n");
183     printf("*** Building PAR archive    ***\n");
184     cout<<pararchivename<<endl;
185     printf("*******************************\n");
186
187     if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
188       Error("runProcess","Cannot Build the PAR Archive! - Abort!");
189       return -1;
190     }
191   }
192   // check for SETUP.C and execute
193   if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
194     printf("*******************************\n");
195     printf("*** Setup PAR archive       ***\n");
196     cout<<pararchivename<<endl;
197     printf("*******************************\n");
198     gROOT->Macro("PROOF-INF/SETUP.C");
199   }
200
201   gSystem->ChangeDirectory(ocwd.Data());
202   printf("Current dir: %s\n", ocwd.Data());
203 }