]> git.uio.no Git - u/mrichter/AliRoot.git/blob - test/cosmic/rawqa.C
d760a6db27315d49fc709b67dd3ff272660872ef
[u/mrichter/AliRoot.git] / test / cosmic / rawqa.C
1 #include <iostream>
2 #include <fstream>
3
4 #include <TAlienCollection.h>
5 #include <TFile.h>
6 #include <TGrid.h>
7 #include <TGridResult.h>
8 #include <TMath.h>
9 #include <TROOT.h>
10 #include <TString.h>
11 #include <TSystem.h>
12
13 #include "AliCDBManager.h"
14 #include "AliDAQ.h"
15 #include "AliLog.h"
16 #include "AliQA.h"
17 #include "AliQADataMakerSteer.h"
18 #include "AliRawReader.h"
19 #include "AliRawReaderRoot.h"
20 #include "AliTRDrawStreamBase.h"
21
22 TString ClassName() { return "rawqa" ; } 
23
24 //________________________________qa______________________________________
25 void rawqa(const Int_t runNumber, Int_t maxFiles = 10, const char* year = "08") 
26 {       
27         char kDefaultOCDBStorage[120] ; 
28         sprintf(kDefaultOCDBStorage, "alien://folder=/alice/data/20%s/LHC%sa/OCDB/", year, year) ; 
29         AliQA::SetQARefStorage(Form("%s%s/", AliQA::GetQARefDefaultStorage(), year)) ;  
30         AliQA::SetQARefDataDirName("Data") ; //Data, Pedestals, BlackEvent, ..... 
31         
32         UInt_t maxEvents = 99999 ;
33         if ( maxFiles < 0 ) {
34                 maxEvents = TMath::Abs(maxFiles) ; 
35                 maxFiles = 99 ; 
36         }
37         AliLog::SetGlobalDebugLevel(0) ; 
38         // connect to the grid 
39         TGrid * grid = 0x0 ; 
40         grid = TGrid::Connect("alien://") ; 
41                 
42         Bool_t detIn[AliDAQ::kNDetectors] = {kFALSE} ;
43         char * detNameOff[AliDAQ::kNDetectors] = {"ITS", "ITS", "ITS", "TPC", "TRD", "TOF", "HMPID", "PHOS", "PHOS", "PMD", "MUON", "MUON", "FMD", "T0", "VZERO", "ZDC", "ACORDE", "TRG", "EMCAL", "DAQ_TEST", "HLT"} ; 
44         // make the file name pattern year and run number
45         TString pattern;
46         pattern.Form("%9d",runNumber);
47         pattern.ReplaceAll(" ", "0") ; 
48         pattern.Prepend(year);
49         pattern.Append("*0.root");
50
51         // find the files associated to this run
52         TGridResult * result = 0x0 ; 
53         Bool_t local = kFALSE ; 
54         if (grid) { // get the list of files from AliEn directly 
55           TString baseDir; 
56           baseDir.Form("/alice/data/20%s/",year);
57           result = grid->Query(baseDir, pattern) ;  
58         } else {
59           TString collectionFile(pattern) ; 
60           collectionFile.Append(".xml") ; 
61           if ( gSystem->AccessPathName(collectionFile) == 0 ) { // get the list of files from an a-priori created collection file
62             TAlienCollection collection(collectionFile.Data(), maxFiles) ; 
63             result = collection.GetGridResult("", 0, 0); 
64           } else { // get the list of files from the local current directory 
65             local = kTRUE ; 
66             char line[100] ; 
67             sprintf(line, ".! ls %s*.root > tempo.txt", pattern.Data()) ; 
68             gROOT->ProcessLine(line) ;
69           }
70         }
71         AliLog::Flush();
72         ifstream in ; 
73         if (local) 
74                 in.open("tempo.txt", ifstream::in) ; 
75
76         AliQADataMakerSteer qas ; 
77         TString detectors  = ""; 
78         TString detectorsW = ""; 
79         UShort_t file = 0 ; 
80         UShort_t filesProcessed = 0 ; 
81         UShort_t eventsProcessed = 0 ; 
82         AliCDBManager* man = AliCDBManager::Instance();
83         for ( file = 0 ; file < maxFiles ; file++) {
84                 man->SetDefaultStorage(kDefaultOCDBStorage) ;  
85                 if ( qas.GetCurrentEvent() >= maxEvents) 
86                         break ;
87
88                 TString fileName ; 
89                 if ( local) {
90                         in >> fileName ;
91                 } 
92                 else 
93                         fileName = result->GetKey(file, "turl");
94                 if ( fileName == "" )  
95                         break ;
96                 if ( fileName.Contains("tag") )
97                         continue; 
98                 filesProcessed++ ;
99                 char input[200] ; 
100                 if (local) 
101                         sprintf(input, "%s", fileName.Data()) ; 
102                 else 
103                         sprintf(input, "%s", result->GetKey(file, "turl")); 
104                 AliInfo(Form("Proccessing file # %d --> %s", file, input)) ;
105                 AliLog::Flush();
106                 // check which detectors are present 
107                 AliRawReader * rawReader = new AliRawReaderRoot(input);
108                 AliTRDrawStreamBase::SetRawStreamVersion("TB");
109                 while ( rawReader->NextEvent() ) {
110                         man->SetRun(rawReader->GetRunNumber());
111                         AliLog::Flush();
112                         UChar_t * data ; 
113                         while (rawReader->ReadNextData(data)) {
114                                 Int_t detID = rawReader->GetDetectorID();
115                                 if (detID < 0 || detID >= AliDAQ::kNDetectors) {
116                                         AliError("Wrong detector ID! Skipping payload...");
117                                         continue;
118                                 }
119                                 detIn[detID] = kTRUE ; 
120                         }
121                         for (Int_t detID = 0; detID < AliDAQ::kNDetectors ; detID++) {
122                                 if (detIn[detID]) {
123                                         if ( ! detectors.Contains(detNameOff[detID]) ) {
124                                                 detectors.Append(detNameOff[detID]) ;
125                                                 detectors.Append(" ") ;
126                                         }
127                                 }
128                         }
129                         if ( !detectors.IsNull() )
130                                 break ; 
131                 }
132                 if ( !detectors.IsNull() ) {
133                         qas.SetMaxEvents(maxEvents) ;   
134                         detectorsW = qas.Run(detectors, rawReader) ;
135                         qas.Reset() ;
136                 } else {
137                         AliError("No valid detectors found") ; 
138                 } 
139                 delete rawReader ;
140                 eventsProcessed += qas.GetCurrentEvent() ; 
141         }
142         AliLog::Flush();
143         qas.Merge(runNumber) ; 
144         
145         AliLog::Flush();
146         // The summary 
147         AliInfo(Form("\n\n********** Summary for run %d **********", runNumber)) ; 
148         printf("     detectors present in the run        : %s\n", detectors.Data()) ; 
149         printf("     detectors present in the run with QA: %s\n", detectorsW.Data()) ; 
150         printf("     number of files/events processed    : %d/%d\n", filesProcessed, eventsProcessed) ; 
151         TFile * qaResult = TFile::Open(AliQA::GetQAResultFileName()) ; 
152         if ( qaResult ) {
153                 AliQA * qa = dynamic_cast<AliQA *>(qaResult->Get(AliQA::GetQAName())) ; 
154                 if ( qa) {
155                         for (Int_t index = 0 ; index < AliQA::kNDET ; index++)
156                                 if (detectorsW.Contains(AliQA::GetDetName(AliQA::DETECTORINDEX_t(index)))) 
157                                         qa->ShowStatus(AliQA::DETECTORINDEX_t(index)) ;
158                 } else {
159                         AliError(Form("%s not found in %s !", AliQA::GetQAName(), AliQA::GetQAResultFileName())) ; 
160                 }
161         } else {
162                 AliError(Form("%s has not been produced !", AliQA::GetQAResultFileName())) ; 
163         }
164 }