added an event counter
[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 <TROOT.h>
9 #include <TString.h>
10 #include <TSystem.h>
11
12 #include "AliCDBManager.h"
13 #include "AliLog.h"
14 #include "AliQA.h"
15 #include "AliQADataMakerSteer.h"
16 #include "AliRawReader.h"
17 #include "AliRawReaderRoot.h"
18 #include "AliDAQ.h"
19
20 TString ClassName() { return "rawqa" ; } 
21
22 //________________________________qa______________________________________
23 void rawqa(const Int_t runNumber, const UInt_t kMaxFiles = 10, const char* year = "08") 
24 {       
25
26         const char * kDefaultOCDBStorage = Form("alien://folder=/alice/data/20%s/LHC%sa/OCDB/", year, year) ; 
27         AliLog::SetGlobalDebugLevel(0) ; 
28         // connect to the grid 
29         TGrid * grid = 0x0 ; 
30         grid = TGrid::Connect("alien://") ; 
31                 
32         Bool_t detIn[AliDAQ::kNDetectors] = {kFALSE} ;
33         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"} ; 
34         // make the file name pattern year and run number
35         TString pattern;
36         pattern.Form("%9d",runNumber);
37         pattern.ReplaceAll(" ", "0") ; 
38         pattern.Prepend(year);
39         pattern.Append("*0.root");
40
41         // find the files associated to this run
42         TGridResult * result = 0x0 ; 
43         Bool_t local = kFALSE ; 
44         if (grid) { // get the list of files from AliEn directly 
45           TString baseDir; 
46           baseDir.Form("/alice/data/20%s/",year);
47           result = grid->Query(baseDir, pattern) ;  
48         } else {
49           TString collectionFile(pattern) ; 
50           collectionFile.Append(".xml") ; 
51           if ( gSystem->AccessPathName(collectionFile) == 0 ) { // get the list of files from an a-priori created collection file
52             TAlienCollection collection(collectionFile.Data(), kMaxFiles) ; 
53             result = collection.GetGridResult("", 0, 0); 
54           } else { // get the list of files from the local current directory 
55             local = kTRUE ; 
56             char line[100] ; 
57             sprintf(line, ".! ls %s*.root > tempo.txt", pattern.Data()) ; 
58             gROOT->ProcessLine(line) ;
59           }
60         }
61         AliLog::Flush();
62         ifstream in ; 
63         if (local) 
64                 in.open("tempo.txt", ifstream::in) ; 
65
66         AliCDBManager* man = AliCDBManager::Instance();
67         man->SetDefaultStorage(kDefaultOCDBStorage) ;  
68         AliQA::SetQARefStorage("alien://folder=/alice/QA/2008") ; 
69         man->SetSpecificStorage(Form("%s/20%s/*", AliQA::GetQAOCDBDirName(), year),AliQA::GetQARefStorage());
70         AliQADataMakerSteer qas ; 
71         TString detectors  = ""; 
72         TString detectorsW = ""; 
73         UShort_t file = 0 ; 
74         UShort_t filesProcessed = 0 ; 
75         for ( file = 0 ; file < kMaxFiles ; file++) {
76                 TString fileName ; 
77                 if ( local) {
78                         in >> fileName ;
79                 } 
80                 else 
81                         fileName = result->GetKey(file, "turl");
82                 if ( fileName == "" )  
83                         break ;
84                 if ( fileName.Contains("tag") )
85                         continue; 
86                 filesProcessed++ ;
87                 char input[200] ; 
88                 if (local) 
89                         sprintf(input, "%s", fileName.Data()) ; 
90                 else 
91                         sprintf(input, "%s", result->GetKey(file, "turl")); 
92                 AliInfo(Form("Proccessing file # %d --> %s", file, input)) ;
93                 AliLog::Flush();
94                 // check which detectors are present 
95                 AliRawReader * rawReader = new AliRawReaderRoot(input);
96                 rawReader->NextEvent() ; 
97                 man->SetRun(rawReader->GetRunNumber());
98                 UChar_t * data ; 
99                 while (rawReader->ReadNextData(data)) {
100                         Int_t detID = rawReader->GetDetectorID();
101                         if (detID < 0 || detID >= AliDAQ::kNDetectors) {
102                           AliError("Wrong detector ID! Skipping payload...");
103                           continue;
104                         }
105                         detIn[detID] = kTRUE ; 
106                 }
107                 for (Int_t detID = 0; detID < AliDAQ::kNDetectors ; detID++) {
108                         if (detIn[detID]) {
109                                 if ( ! detectors.Contains(detNameOff[detID]) ) {
110                                         detectors.Append(detNameOff[detID]) ;
111                                         detectors.Append(" ") ;
112                                 }
113                         }
114                 }
115                 // TEMPORARY REMOVAL OF TRD!!!
116                 detectors.ReplaceAll("TRD","");
117                 // TEMPORARY REMOVAL OF TRD!!!
118                 if ( !detectors.IsNull() ) {
119                   detectorsW = qas.Run(detectors, rawReader) ;
120                   qas.Reset() ;
121                 } else {
122                   AliError("No valid detectors found") ; 
123                 } 
124                 delete rawReader;
125         }
126         AliLog::Flush();
127         qas.Merge(runNumber) ; 
128         
129         AliLog::Flush();
130         // The summary 
131         AliInfo(Form("\n\n********** Summary for run %d **********", runNumber)) ; 
132         printf("     detectors present in the run        : %s\n", detectors.Data()) ; 
133         printf("     detectors present in the run with QA: %s\n", detectorsW.Data()) ; 
134         printf("     number of files processed           : %d\n", filesProcessed) ; 
135         TFile * qaResult = TFile::Open(AliQA::GetQAResultFileName()) ; 
136         AliQA * qa = dynamic_cast<AliQA *>(qaResult->Get("QA")) ; 
137         for (Int_t index = 0 ; index < AliQA::kNDET ; index++)
138                 if (detectorsW.Contains(AliQA::GetDetName(AliQA::DETECTORINDEX(index)))) 
139                         qa->ShowStatus(AliQA::DETECTORINDEX(index)) ;
140 }