]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/qa/RunFinalQA.C
AliMCAuxHandler: A class to handle auxillary input (such as hits or digits)
[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 pwglf_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  * @param pattern    Pattern filenames must match
18  * 
19  * @return true on success
20  * 
21  * @ingroup pwglf_forward_qa_scripts
22  */
23 Bool_t ScanDirectory(TSystemDirectory* dir, 
24                      TList* list, 
25                      const char* pattern, 
26                      bool recursive=false)
27 {
28   TString fnPattern = pattern;
29
30   // Assume failure 
31   Bool_t ret = false;
32
33   // Get list of files, and go back to old working directory
34   TString oldDir(gSystem->WorkingDirectory());
35   TList*  files = dir->GetListOfFiles();
36   if (!gSystem->ChangeDirectory(oldDir)) { 
37     Error("ScanDirectory", "Failed to go back to %s", oldDir.Data());
38     return false;
39   }
40   if (!files) {
41     Warning("ScanDirectory", "No files found in %s", dir->GetName());
42     return false;
43   }
44   // files->ls();
45
46   TList toAdd;
47     
48   // Sort list of files and check if we should add it 
49   // files->Sort();
50   TIter next(files);
51   TSystemFile* file = 0;
52   while ((file = static_cast<TSystemFile*>(next()))) {
53     TString name(file->GetName());
54     TString title(file->GetTitle());
55     TString full(gSystem->ConcatFileName(file->GetTitle(), name.Data()));
56     if (file->IsA() == TSystemDirectory::Class()) full = title;
57     if (name == "." || name == "..") { 
58       continue;
59     }
60
61     FileStat_t fs;
62     if (gSystem->GetPathInfo(full.Data(), fs)) {
63       Warning("ScanDirectory", "Cannot stat %s (%s)", full.Data(),
64               gSystem->WorkingDirectory());
65       continue;
66     }
67     // Check if this is a directory 
68     if (file->IsDirectory(full)) { 
69       if (recursive) {
70         TSystemDirectory* d = new TSystemDirectory(file->GetName(),
71                                                    full.Data());
72         if (ScanDirectory(d,list,pattern,recursive))
73           ret = true;
74         delete d;
75       }
76       continue;
77     }
78     
79     // If this is not a root file, ignore 
80     if (!name.EndsWith(".root")) {
81       continue;
82     }
83
84     // If this file does not contain AliESDs, ignore 
85     if (!name.Contains(fnPattern)) { 
86       continue;
87     }
88     
89     // Add 
90     toAdd.Add(new TObjString(full));
91   }
92
93   TIter nextAdd(&toAdd);
94   TObjString* s = 0;
95   while ((s = static_cast<TObjString*>(nextAdd()))) {
96     list->Add(s);
97   }
98   if (toAdd.GetEntries() > 0) ret = true;
99
100   gSystem->ChangeDirectory(oldDir);
101   return ret;
102 }
103 //____________________________________________________________________
104 /** 
105  * Get the list of trending files
106  * 
107  * @param input Start directory 
108  * 
109  * @return List of files 
110  * 
111  * @ingroup pwglf_forward_qa_scripts
112  */
113 TList*
114 GetListOfFiles(const char* input=".")
115 {
116   TList* ret = new TList;
117   TString dir(input);
118   // if (dir == ".") dir = "";
119
120   TString savdir(gSystem->WorkingDirectory());
121   TSystemDirectory d(gSystem->BaseName(dir.Data()), dir.Data());
122   if (!ScanDirectory(&d, ret, "tree_", false)) { 
123     delete ret;
124     ret = 0;
125   }
126   gSystem->ChangeDirectory(savdir);  
127   if (ret) ret->Sort();
128   return ret;
129 }
130
131 //____________________________________________________________________
132 /** 
133  * 
134  * 
135  * @param dir Input directory
136  * @param prodYear Production year 
137  * @param prodLetter Production letter
138  * 
139  * @ingroup pwglf_forward_qa_scripts
140  */
141 void 
142 RunFinalQA(const char* dir, Int_t prodYear=0, const char* prodLetter="",
143            Bool_t useVar=false)
144 {
145    int ret = 0;
146    gROOT->SetMacroPath(Form(".:%s",gROOT->GetMacroPath()));
147    gSystem->Load("libGpad");
148    gSystem->Load("libTree");
149
150    gROOT->LoadMacro("QABase.h+g");
151    gROOT->LoadMacro("QAPlotter.C+g");
152
153    Info("RunFinalQA", "Final QA: %d%c (variance: %s)", 
154         prodYear, prodLetter[0], (useVar ? "true" : "false"));
155    QAPlotter p(prodYear, prodLetter[0], useVar);
156   
157    TList* l = GetListOfFiles(dir);
158    TIter next(l);
159    TObject* o = 0;
160    while ((o = next())) {
161      p.AddFile(o->GetName());
162    }
163
164    p.Run();
165 }
166 //
167 // EOF
168 //