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