]> git.uio.no Git - u/mrichter/AliRoot.git/blob - test/QA/rawqa.C
access to alien files
[u/mrichter/AliRoot.git] / test / QA / 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("*.root");
50         // find the files associated to this run
51         TGridResult * result = 0x0 ; 
52         Bool_t local = kFALSE ; 
53         if (grid) { // get the list of files from AliEn directly 
54                 TString collectionFile(pattern) ; 
55                 collectionFile.ReplaceAll("*.root", ".xml") ; 
56                 if ( gSystem->AccessPathName(collectionFile) == 0 ) { // get the list of files from an a-priori created collection file
57                         TAlienCollection collection(collectionFile.Data(), maxFiles) ; 
58                         result = collection.GetGridResult("", 0, 0); 
59                 } else { 
60                         TString baseDir; 
61                         baseDir.Form("/alice/data/20%s/",year);
62                         result = grid->Query(baseDir, pattern) ;  
63                 }
64         } else {
65            // get the list of files from the local current directory 
66             local = kTRUE ; 
67             char line[100] ; 
68             sprintf(line, ".! ls %s*.root > tempo.txt", pattern.Data()) ; 
69             gROOT->ProcessLine(line) ;
70         }
71         
72         AliLog::Flush();
73         ifstream in ; 
74         if (local) 
75                 in.open("tempo.txt", ifstream::in) ; 
76
77         AliQADataMakerSteer qas ; 
78         TString detectors  = ""; 
79         TString detectorsW = ""; 
80         UShort_t file = 0 ; 
81         UShort_t filesProcessed = 0 ; 
82         UShort_t eventsProcessed = 0 ; 
83         AliCDBManager* man = AliCDBManager::Instance();
84         for ( file = 0 ; file < maxFiles ; file++) {
85                 man->SetDefaultStorage(kDefaultOCDBStorage) ;  
86                 if ( qas.GetCurrentEvent() >= maxEvents) 
87                         break ;
88
89                 TString fileName ; 
90                 if ( local) {
91                         in >> fileName ;
92                 } 
93                 else 
94                         fileName = result->GetKey(file, "turl");
95                 if ( fileName == "" )  
96                         break ;
97                 if ( fileName.Contains("tag") )
98                         continue; 
99                 filesProcessed++ ;
100                 char input[200] ; 
101                 if (local) 
102                         sprintf(input, "%s", fileName.Data()) ; 
103                 else 
104                         sprintf(input, "%s", result->GetKey(file, "turl")); 
105                 AliInfo(Form("Proccessing file # %d --> %s", file, input)) ;
106                 AliLog::Flush();
107                 // check which detectors are present 
108                 AliRawReader * rawReader = new AliRawReaderRoot(input);
109                 AliTRDrawStreamBase::SetRawStreamVersion("TB");
110                 while ( rawReader->NextEvent() ) {
111                         man->SetRun(rawReader->GetRunNumber());
112                         AliLog::Flush();
113                         UChar_t * data ; 
114                         while (rawReader->ReadNextData(data)) {
115                                 Int_t detID = rawReader->GetDetectorID();
116                                 if (detID < 0 || detID >= AliDAQ::kNDetectors) {
117                                         AliError("Wrong detector ID! Skipping payload...");
118                                         continue;
119                                 }
120                                 detIn[detID] = kTRUE ; 
121                         }
122                         for (Int_t detID = 0; detID < AliDAQ::kNDetectors ; detID++) {
123                                 if (detIn[detID]) {
124                                         if ( ! detectors.Contains(detNameOff[detID]) ) {
125                                                 detectors.Append(detNameOff[detID]) ;
126                                                 detectors.Append(" ") ;
127                                         }
128                                 }
129                         }
130                         if ( !detectors.IsNull() )
131                                 break ; 
132                 }
133                 if ( !detectors.IsNull() ) {
134                         qas.SetMaxEvents(maxEvents) ;   
135                         detectorsW = qas.Run(detectors, rawReader) ;
136                         qas.Reset() ;
137                 } else {
138                         AliError("No valid detectors found") ; 
139                 } 
140                 delete rawReader ;
141                 eventsProcessed += qas.GetCurrentEvent() ; 
142         }
143         AliLog::Flush();
144         qas.Merge(runNumber) ; 
145         
146         AliLog::Flush();
147         // The summary 
148         AliInfo(Form("\n\n********** Summary for run %d **********", runNumber)) ; 
149         printf("     detectors present in the run        : %s\n", detectors.Data()) ; 
150         printf("     detectors present in the run with QA: %s\n", detectorsW.Data()) ; 
151         printf("     number of files/events processed    : %d/%d\n", filesProcessed, eventsProcessed) ; 
152         TFile * qaResult = TFile::Open(AliQA::GetQAResultFileName()) ; 
153         if ( qaResult ) {
154                 AliQA * qa = dynamic_cast<AliQA *>(qaResult->Get(AliQA::GetQAName())) ; 
155                 if ( qa) {
156                         for (Int_t index = 0 ; index < AliQA::kNDET ; index++)
157                                 if (detectorsW.Contains(AliQA::GetDetName(AliQA::DETECTORINDEX_t(index)))) 
158                                         qa->ShowStatus(AliQA::DETECTORINDEX_t(index)) ;
159                 } else {
160                         AliError(Form("%s not found in %s !", AliQA::GetQAName(), AliQA::GetQAResultFileName())) ; 
161                 }
162         } else {
163                 AliError(Form("%s has not been produced !", AliQA::GetQAResultFileName())) ; 
164         }
165 }