]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/qa/RunFinalQA.C
Transition PWG2/FORWARD -> PWGLF
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / qa / RunFinalQA.C
1 /**
2  * @file   RunFinalQA.C
3  * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4  * @date   Fri Jan  6 11:46:30 2012
5  * 
6  * @brief  
7  * 
8  * @ingroup pwg2_forward_qa_scripts
9  */
10 //____________________________________________________________________
11 /** 
12  * Scan directory (and possibly sub-directories) for trending files
13  * 
14  * @param dir        Start directory
15  * @param list       List to add file names to
16  * @param recursive  Whether to scan recursively
17  * 
18  * @return true on success
19  * 
20  * @ingroup pwg2_forward_qa_scripts
21  */
22 Bool_t ScanDirectory(TSystemDirectory* dir, 
23                      TList* list, 
24                      const char* pattern, 
25                      bool recursive=false)
26 {
27   TString fnPattern = pattern;
28
29   // Assume failure 
30   Bool_t ret = false;
31
32   // Get list of files, and go back to old working directory
33   TString oldDir(gSystem->WorkingDirectory());
34   TList*  files = dir->GetListOfFiles();
35   if (!gSystem->ChangeDirectory(oldDir)) { 
36     Error("ScanDirectory", "Failed to go back to %s", oldDir.Data());
37     return false;
38   }
39   if (!files) {
40     Warning("ScanDirectory", "No files found in %s", dir->GetName());
41     return false;
42   }
43   // files->ls();
44
45   TList toAdd;
46     
47   // Sort list of files and check if we should add it 
48   // files->Sort();
49   TIter next(files);
50   TSystemFile* file = 0;
51   while ((file = static_cast<TSystemFile*>(next()))) {
52     TString name(file->GetName());
53     TString title(file->GetTitle());
54     TString full(gSystem->ConcatFileName(file->GetTitle(), name.Data()));
55     if (file->IsA() == TSystemDirectory::Class()) full = title;
56     if (name == "." || name == "..") { 
57       continue;
58     }
59
60     FileStat_t fs;
61     if (gSystem->GetPathInfo(full.Data(), fs)) {
62       Warning("ScanDirectory", "Cannot stat %s (%s)", full.Data(),
63               gSystem->WorkingDirectory());
64       continue;
65     }
66     // Check if this is a directory 
67     if (file->IsDirectory(full)) { 
68       if (recursive) {
69         TSystemDirectory* d = new TSystemDirectory(file->GetName(),
70                                                    full.Data());
71         if (ScanDirectory(d,list,pattern,recursive))
72           ret = true;
73         delete d;
74       }
75       continue;
76     }
77     
78     // If this is not a root file, ignore 
79     if (!name.EndsWith(".root")) {
80       continue;
81     }
82
83     // If this file does not contain AliESDs, ignore 
84     if (!name.Contains(fnPattern)) { 
85       continue;
86     }
87     
88     // Add 
89     toAdd.Add(new TObjString(full));
90   }
91
92   TIter nextAdd(&toAdd);
93   TObjString* s = 0;
94   while ((s = static_cast<TObjString*>(nextAdd()))) {
95     list->Add(s);
96   }
97   if (toAdd.GetEntries() > 0) ret = true;
98
99   gSystem->ChangeDirectory(oldDir);
100   return ret;
101 }
102 //____________________________________________________________________
103 /** 
104  * Get the list of trending files
105  * 
106  * @param input Start directory 
107  * 
108  * @return List of files 
109  * 
110  * @ingroup pwg2_forward_qa_scripts
111  */
112 TList*
113 GetListOfFiles(const char* input=".")
114 {
115   TList* ret = new TList;
116   TString dir(input);
117   // if (dir == ".") dir = "";
118
119   TString savdir(gSystem->WorkingDirectory());
120   TSystemDirectory d(gSystem->BaseName(dir.Data()), dir.Data());
121   if (!ScanDirectory(&d, ret, "tree_", false)) { 
122     delete ret;
123     ret = 0;
124   }
125   gSystem->ChangeDirectory(savdir);  
126   if (ret) ret->Sort();
127   return ret;
128 }
129
130 //____________________________________________________________________
131 /** 
132  * 
133  * 
134  * @param dir 
135  * 
136  * @ingroup pwg2_forward_qa_scripts
137  */
138 void 
139 RunFinalQA(const char* dir)
140 {
141    int ret = 0;
142    gROOT->SetMacroPath(Form(".:$(ALICE_ROOT)/PWG2/FORWARD/analysis2/qa:"
143                             "$(ALICE_ROOT)/PWG2/FORWARD/analysis2/corrs:%s",
144                             gROOT->GetMacroPath()));
145    gSystem->AddIncludePath("-I${ALICE_ROOT}/PWG2/FORWARD/analysis2/qa");
146    gSystem->Load("libGpad");
147    gSystem->Load("libTree");
148
149    gROOT->LoadMacro("QABase.h+g");
150    gROOT->LoadMacro("QAPlotter.C+g");
151
152    QAPlotter p;
153   
154    TList* l = GetListOfFiles(dir);
155    TIter next(l);
156    TObject* o = 0;
157    while ((o = next())) {
158      p.AddFile(o->GetName());
159    }
160
161    p.Run();
162 }
163 //
164 // EOF
165 //