1 //--------------------------------------------------------------------------
2 // Macro for QA monitoring.
4 // In case it is not run with full aliroot, it needs the following libraries to compile:
9 // - libANALYSISalice.so
13 // TString includePath = "-I${ALICE_ROOT}/PWG3/base/ "; gSystem->SetIncludePath(includePath.Data());
16 // The macro reads the PWG1 QA train output, produces a merged root files for the full period
17 // for event and track counters as well as separate root files run per run with all MUON_TRK related histograms.
18 // The results is stored under the directory "results". Then use PlotMUONQA.C, to draw QA histograms.
20 // Author: Cynthia Hadjidakis - IPN Orsay
21 //--------------------------------------------------------------------------
23 #if !defined(__CINT__) || defined(__MAKECINT__)
25 #include <Riostream.h>
31 #include "TGridCollection.h"
32 #include "TGridResult.h"
41 #include "AliCounterCollection.h"
45 TObjArray * GetListOfFiles(const char* baseDir, const char * trainName, const char* inFile);
46 TObjArray * GetListOfRuns(const char* runList, TObjArray *&listoffiles);
48 // .x TransferMuonQATrain.C("alien:///alice/data/2010/LHC10e","QA50","/Users/cynthia/Documents/alice/data/MuonQA/LHC10e/pass2/runlist_period3_test3.txt")
49 // .x TransferMuonQATrain.C("alien:///alice/cern.ch/user/s/suire/LHC10hV2116/output","","mylist.txt","AnalysisResults.root")
50 //--------------------------------------------------------------------------
51 Bool_t TransferMuonQATrain_v4(const char* baseDir, const char * trainName, const char* runList,char* inputFile = "QAresults.root")
53 #if defined(__CINT__) && !defined(__MAKECINT__)
54 gSystem->Load("libTree");
55 gSystem->Load("libGeom");
56 gSystem->Load("libVMC");
57 gSystem->Load("libPhysics");
58 gSystem->Load("libSTEERBase");
59 gSystem->Load("libESD");
60 gSystem->Load("libAOD");
61 gSystem->Load("libANALYSIS");
62 gSystem->Load("libANALYSISalice");
63 gSystem->Load("libCORRFW");
64 gSystem->Load("libPWG3base");
65 gSystem->Load("libPWG3muon");
68 TString sbaseDir = baseDir;
69 if (sbaseDir.Contains("alien:") && !TGrid::Connect("alien://")) {
70 Error("MuonQATrain","cannot connect to grid");
74 //----------------------------------------------------------- //
75 // Build the list of files, the list of runs //
77 //----------------------------------------------------------- //
79 TObjArray *listoffiles = (TObjArray*) GetListOfFiles(baseDir,trainName,inputFile);
80 if(!listoffiles) return kFALSE;
81 TObjArray *runs = (TObjArray*) GetListOfRuns(runList,listoffiles);
82 if(!runs||!listoffiles){
83 Error("TransferMuonQATrain","cannot get a list of selected runs or files");
86 printf("TransferMuonQATrain: Files found to be processed = %d\n",runs->GetEntriesFast());
87 if(runs->GetEntriesFast()==0) return kFALSE;
89 //-------------------------------------//
90 // Loop over the files on grid //
91 //-------------------------------------//
94 TIter next0(listoffiles);
98 AliCounterCollection *trackCounters = 0;
99 AliCounterCollection *eventCounters = 0;
100 AliCounterCollection *mergedTrackCounters = 0;
101 AliCounterCollection *mergedEventCounters = 0;
102 TObjArray* outputList;
103 TObjArray* outputListExpert;
104 TObjArray* outputListNorm;
105 TFile outputHistoFile;
108 TString command = "mkdir results";
109 cout<<"Shell command = "<<command<<endl;
110 gSystem->Exec(command.Data());
112 while ((nextfile=next0())) {
115 snextfile = nextfile->GetName();
117 file = TFile::Open(snextfile.Data());
120 outputList = (TObjArray *)file->Get("MUON_QA/general1");
121 outputListExpert = (TObjArray *)file->Get("MUON_QA/expert");
122 outputListNorm = (TObjArray *)file->Get("MUON_QA/general2");
124 trackCounters = (AliCounterCollection *) file->Get("MUON_QA/trackCounters");
125 eventCounters = (AliCounterCollection *) file->Get("MUON_QA/eventCounters");
127 if(!trackCounters || !eventCounters){
128 Error("TransferMuonQATrain","Objects not found for that file");
132 //-------------------------------------//
133 // Merge the AliCounterCollection
134 //-------------------------------------//
136 mergedTrackCounters = (AliCounterCollection*) trackCounters->Clone();
137 mergedEventCounters = (AliCounterCollection*) eventCounters->Clone();
140 mergedTrackCounters->Add(trackCounters);
141 mergedEventCounters->Add(eventCounters);
145 //-------------------------------------//
146 // Save the MUONQA histos in AnalysisResults.root for each run number
147 //-------------------------------------//
148 fileName = "AnalysisResults.root";
149 outputHistoFile.Open(fileName,"recreate");
150 new TDirectoryFile("MUON_QA","MUON_QA");
151 outputHistoFile.Cd("MUON_QA");
153 TDirectory *dir0 = (TDirectory*) file->GetDirectory("MUON_QA");
154 TObjArray* general1 = static_cast<TObjArray*>(dir0->FindObjectAny("general1"));
155 TObjArray* expert = static_cast<TObjArray*>(dir0->FindObjectAny("expert"));
156 TObjArray* general2 = static_cast<TObjArray*>(dir0->FindObjectAny("general2"));
158 if(general1) general1->Write("general1",TObject::kSingleKey);
159 if(general2) general2->Write("general2",TObject::kSingleKey);
160 if(expert) expert->Write("expert",TObject::kSingleKey);
161 outputHistoFile.Close();
163 command = "mkdir -p results/";
164 command+=((TObjString*)runs->UncheckedAt(nFiles))->GetString();
165 cout<<"Shell command = "<<command<<endl;
166 gSystem->Exec(command.Data());
167 command=" mv AnalysisResults.root results/";
168 command+=((TObjString*)runs->UncheckedAt(nFiles))->GetString();
170 cout<<"Shell command = "<<command<<endl;
171 gSystem->Exec(command.Data());
172 } //end of loop over files
174 //-------------------------------------//
175 // Save the AliCounterCollection in MergedAnalysisResults.root
176 //-------------------------------------//
178 TFile outputFile("MergedAnalysisResults.root","recreate");
179 new TDirectoryFile("MUON_QA","MUON_QA");
180 outputFile.Cd("MUON_QA");
182 mergedTrackCounters->Write();
183 mergedEventCounters->Write();
186 command = "mv MergedAnalysisResults.root results/.";
187 cout<<"Shell command = "<<command<<endl;
188 gSystem->Exec(command.Data());
193 TObjArray * GetListOfRuns(const char* runList, TObjArray *&listoffiles)
196 TObjArray * runs = new TObjArray();
200 Error("GetListOfruns","runList is not defined... exit");
204 // only the ones in the runList
205 ifstream inFile(runList);
206 if (!inFile.is_open()) {
207 Error("GetListOfRuns",Form("unable to open file %s", runList));
212 while (!inFile.eof()) {
213 currRun.ReadLine(inFile, kTRUE);
214 if (currRun.IsNull()) continue;
215 if (!currRun.IsDigit()) {
216 Error("GetListOfRuns","invalid run number: %s", currRun.Data());
219 runs->AddLast(new TObjString(Form("%09d", currRun.Atoi())));
225 printf("GetListOfRuns: Nr of runs in the runlist = %d and in the list of files = %d\n",runs->GetEntriesFast(),listoffiles->GetEntriesFast());
227 if(runList && listoffiles){
228 //Filter the selected runs and modify listoffiles
229 TObjArray* runsFound = new TObjArray();
230 runsFound->SetOwner();
232 //filter the selected runs
233 TIter next0(listoffiles);
238 TObjArray *listoffilestmp = new TObjArray();
239 listoffilestmp->SetOwner();
240 while ((nextfile=next0())) {//loop over files found on alien
241 snextfile = nextfile->GetName();
243 for ( Int_t irun=0; irun<runs->GetEntriesFast(); irun++ ) { //loop over selected runs
244 TString run = ((TObjString*)runs->UncheckedAt(irun))->GetString();
245 if(snextfile.Contains(run)){
246 listoffilestmp->Add(nextfile);
247 runsFound->AddLast(new TObjString(Form("%09d", run.Atoi())));
251 if(isFound==0) printf("GetListOfRuns: run = %s not found in the list of files.... continue....\n",snextfile.Data());
255 listoffiles->Clear();
256 listoffiles = (TObjArray*) listoffilestmp->Clone();
258 printf("GetListOfRuns Nr of selected runs corresponding to the list of files = %d \n",runs->GetEntriesFast());
265 TObjArray* GetListOfFiles(const char* baseDir, const char * trainName, const char* inFile)
268 TString sbaseDir = baseDir;
269 TString strainName = trainName;
270 TString inputFile = inFile;
273 if(!sbaseDir.Contains("alien://")){
274 Error("GetListOfFiles","Not implemented for files not on alien-->exit");
278 sbaseDir.ReplaceAll("alien://", "");
280 TObjArray *listoffiles = new TObjArray();
282 if (sbaseDir.Contains(".xml")) {
283 // Read files pointed by the xml
284 TGridCollection *coll = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\");", sbaseDir.Data()));
286 ::Error("GetListOfFiles", "Input XML collection empty.");
289 // Iterate grid collection
290 while (coll->Next()) {
291 TString fname = gSystem->DirName(coll->GetTURL());
294 listoffiles->Add(new TNamed(fname.Data(),""));
298 command = Form("find %s/ *%s/%s", sbaseDir.Data(), strainName.Data(), inputFile.Data());
299 printf("command: %s\n", command.Data());
300 TGridResult *res = gGrid->Command(command);
302 ::Error("GetListOfFiles","No result for the find command\n");
303 cout << sbaseDir.Data() << " " << strainName.Data() << endl ;
309 while ((map=(TMap*)nextmap())) {
310 TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("turl"));
311 if (!objs || !objs->GetString().Length()) {
312 // Nothing found - skip this output
317 listoffiles->Add(new TNamed(objs->GetName(),""));
321 if (!listoffiles->GetEntries()) {
322 ::Error("GetListOfFiles","No files from the find command=%s\n",command.Data());
326 else printf("GetListOfFiles: Number of files found %d\n",listoffiles->GetEntries());