AliPhysics  vAN-20150822 (d56cf94)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
terminateQA.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 // ROOT includes
3 #include "TFile.h"
4 #include "TGrid.h"
5 #include "TString.h"
6 #include "TObjArray.h"
7 #include "TObjString.h"
8 #include "TSystem.h"
9 #include "TROOT.h"
10 
11 // Aliroot includes
12 #include "AliAnalysisManager.h"
13 #include "AliAnalysisAlien.h"
14 #include "AliESDInputHandler.h"
15 
16 #define COMPILEMACRO
17 
18 #endif
19 
20 
21 //_____________________________________________________________________________
22 Int_t GetRunNumber(TString filePath)
23 {
24  TObjArray* array = filePath.Tokenize("/");
25  array->SetOwner();
26  TString auxString = "";
27  Int_t runNum = -1;
28  for ( Int_t ientry=0; ientry<array->GetEntries(); ientry++ ) {
29  auxString = array->At(ientry)->GetName();
30  if ( auxString.Length() == 9 && auxString.IsDigit() ) {
31  runNum = auxString.Atoi();
32  break;
33  }
34  }
35  delete array;
36 
37  if ( runNum < 0 ) {
38  array = auxString.Tokenize("_");
39  array->SetOwner();
40  auxString = array->Last()->GetName();
41  auxString.ReplaceAll(".root","");
42  if ( auxString.IsDigit() )
43  runNum = auxString.Atoi();
44  delete array;
45  }
46 
47  return runNum;
48 }
49 
50 //_____________________________________________________________________________
51 void CopyFile(TString inFilename, TString baseOutDir=".", Bool_t makeRunDir=kTRUE, TString changeFilename="")
52 {
53  if ( inFilename.Contains("alien://") && ! gGrid )
54  TGrid::Connect("alien://");
55 
56  TObjArray* array = inFilename.Tokenize("/");
57  array->SetOwner();
58  TString outFilename = changeFilename.IsNull() ? array->Last()->GetName() : changeFilename.Data();
59  delete array;
60 
61  if ( makeRunDir ) {
62  Int_t runNumber = GetRunNumber(inFilename);
63  if ( runNumber >= 0 ) {
64  baseOutDir = Form("%s/%i", baseOutDir.Data(), runNumber);
65  if ( gSystem->AccessPathName(baseOutDir.Data()) )
66  gSystem->mkdir(baseOutDir.Data());
67  }
68  else printf("Warning: run number not found!\n");
69  }
70  //outFilename.ReplaceAll(".root", Form("_%i.root", runNumber));
71  outFilename.Prepend(Form("%s/", baseOutDir.Data()));
72  Bool_t showProgressBar = ! gROOT->IsBatch();
73  TFile::Cp(inFilename.Data(), outFilename.Data(), showProgressBar);
74  printf("outDir: %s\n", baseOutDir.Data());
75  printf("outFile: %s\n", outFilename.Data());
76 }
77 
78 
79 
80 //_____________________________________________________________________________
81 AliAnalysisAlien* CreateAlienHandler()
82 {
83  AliAnalysisAlien *plugin = new AliAnalysisAlien();
84 
85  // Set the run mode
86  plugin->SetRunMode("terminate");
87 
88  // Declare all libraries
89  plugin->SetAdditionalLibs("libCORRFW.so libPWGHFbase.so libPWGmuon.so libPWGPPMUONlite.so");
90 
91  plugin->SetAdditionalRootLibs("libXMLParser.so libGui.so libProofPlayer.so");
92 
93  plugin->AddIncludePath("-I.");
94  plugin->AddIncludePath("-I$ALICE_PHYSICS/PWGPP/MUON/lite");
95 
96  return plugin;
97 }
98 
99 
100 //_____________________________________________________________________________
101 void terminateQA(TString outfilename = "QAresults.root", Bool_t force = kFALSE, Bool_t runTrig = kFALSE, Bool_t usePhysicsSelection = kTRUE )
102 {
103  //
104  // Load common libraries
105  //
106  gSystem->Load("libTree");
107  gSystem->Load("libGeom");
108  gSystem->Load("libVMC");
109  gSystem->Load("libPhysics");
110  gSystem->Load("libProof");
111 
112  TString libsList = "libANALYSIS libOADB libANALYSISalice libCORRFW libPWGHFbase libPWGmuon libPWGPPMUONlite";
113 
114  TObjArray* libsArray = libsList.Tokenize(" ");
115  libsArray->SetOwner();
116  TString currLib = "";
117  for ( Int_t ilib=0; ilib<libsArray->GetEntries(); ilib++ ) {
118  currLib = libsArray->At(ilib)->GetName();
119  gSystem->Load(currLib.Data());
120  }
121 
122  AliAnalysisAlien* alienHandler = CreateAlienHandler();
123 
124  AliAnalysisManager* mgr = new AliAnalysisManager("testAnalysis");
125  mgr->SetCommonFileName(outfilename.Data());
126  mgr->SetGridHandler(alienHandler);
127 
128  // Needed to the manager (but not used in terminate mode)
129  AliESDInputHandler* esdH = new AliESDInputHandler();
130  esdH->SetReadFriends(kFALSE);
131  mgr->SetInputEventHandler(esdH);
132 
133 #ifndef COMPILEMACRO
134 
135  TString physSelPattern = "PhysSelPass";
136  if ( ! usePhysicsSelection ) physSelPattern.Append(",PhysSelReject");
137 
138  if ( runTrig ) {
139  gROOT->LoadMacro("$ALICE_PHYSICS/PWGPP/macros/AddTaskMTRchamberEfficiency.C");
140  AliAnalysisTaskTrigChEff* trigChEffTask = AddTaskMTRchamberEfficiency(kFALSE);
141  trigChEffTask->SetTerminateOptions(physSelPattern.Data(),"ANY","-5_105",Form("FORCEBATCH trigChEff_ANY_Apt_allTrig.root?%s?ANY?-5_105?NoSelMatchAptFromTrg",physSelPattern.Data()));
142  }
143  else {
144  gROOT->LoadMacro("$ALICE_PHYSICS/PWGPP/PilotTrain/AddTaskMuonQA.C");
145  AliAnalysisTaskMuonQA* muonQATask = AddTaskMuonQA(usePhysicsSelection);
146  }
147 
148 #endif
149 
150  // Check if terminate was already performed
151  if ( ! force ) {
152  TObject* paramContainer = mgr->GetParamOutputs()->At(0);
153  if ( paramContainer ) {
154  TFile* file = TFile::Open(outfilename);
155  if ( file->FindObjectAny(paramContainer->GetName() ) ) {
156  printf("\nTerminate was already executed!\n");
157  printf("Nothing to be done\n");
158  file->Close();
159  return;
160  }
161  file->Close();
162  }
163  }
164 
165 
166  if ( ! mgr->InitAnalysis()) {
167  printf("Fatal: Cannot initialize analysis\n");
168  return;
169  }
170  mgr->PrintStatus();
171  mgr->StartAnalysis("grid terminate");
172 }
TSystem * gSystem
Quality assurance of MUON ESDs.
Int_t GetRunNumber(TString filePath)
Definition: terminateQA.C:22
void CopyFile(TString inFilename, TString baseOutDir=".", Bool_t makeRunDir=kTRUE, TString changeFilename="")
Definition: terminateQA.C:51
AliAnalysisAlien * CreateAlienHandler()
Definition: terminateQA.C:81
TFile * file
void terminateQA(TString outfilename="QAresults.root", Bool_t force=kFALSE, Bool_t runTrig=kFALSE, Bool_t usePhysicsSelection=kTRUE)
Definition: terminateQA.C:101