Macros for raw-data reco and QA at P2
[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 char* year = "08") 
24 {       
25
26         AliLog::SetGlobalDebugLevel(0) ; 
27         // connect to the grid 
28         TGrid * grid = 0x0 ; 
29         grid = TGrid::Connect("alien://") ; 
30                 
31         Bool_t detIn[AliDAQ::kNDetectors] = {kFALSE} ;
32         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"} ; 
33         // make the file name pattern year and run number
34         TString pattern;
35         pattern.Form("%9d",runNumber);
36         pattern.ReplaceAll(" ", "0") ; 
37         pattern.Prepend(year);
38         pattern.Append("*0.root");
39
40         // find the files associated to this run
41         TGridResult * result = 0x0 ; 
42         const UInt_t kMaxFiles = 10 ; 
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("alien://folder=/alice/data/2008/LHC08a/OCDB/"); // AliQA::GetQARefDefaultStorage()
68         AliQA::SetQARefStorage("local://../TestCDB") ; 
69         man->SetSpecificStorage(Form("%s/*", AliQA::GetQAOCDBDirName()), AliQA::GetQARefStorage());
70         AliQADataMakerSteer qas ; 
71         TString detectors  = ""; 
72         TString detectorsW = ""; 
73         UShort_t file = 0 ; 
74         for ( file = 0 ; file < kMaxFiles ; file++) {
75                 TString fileName ; 
76                 if ( local) {
77                         in >> fileName ;
78                 } 
79                 else 
80                         fileName = result->GetKey(file, "turl");
81                 if ( fileName == "" )  
82                         break ;
83                 if ( fileName.Contains("tag") )
84                         continue; 
85                 char input[200] ; 
86                 if (local) 
87                         sprintf(input, "%s", fileName.Data()) ; 
88                 else 
89                         sprintf(input, "%s", result->GetKey(file, "turl")); 
90                 AliInfo(Form("Proccessing file # %d --> %s", file, input)) ;
91                 AliLog::Flush();
92                 // check which detectors are present 
93                 AliRawReader * rawReader = new AliRawReaderRoot(input);
94                 rawReader->NextEvent() ; 
95                 man->SetRun(rawReader->GetRunNumber());
96                 UChar_t * data ; 
97                 while (rawReader->ReadNextData(data)) {
98                         Int_t detID = rawReader->GetDetectorID();
99                         if (detID < 0 || detID >= AliDAQ::kNDetectors) {
100                           AliError("Wrong detector ID! Skipping payload...");
101                           continue;
102                         }
103                         detIn[detID] = kTRUE ; 
104                 }
105                 for (Int_t detID = 0; detID < AliDAQ::kNDetectors ; detID++) {
106                         if (detIn[detID]) {
107                                 if ( ! detectors.Contains(detNameOff[detID]) ) {
108                                         detectors.Append(detNameOff[detID]) ;
109                                         detectors.Append(" ") ;
110                                 }
111                         }
112                 }
113                 // TEMPORARY REMOVAL OF TRD!!!
114                 detectors.ReplaceAll("TRD","");
115                 // TEMPORARY REMOVAL OF TRD!!!
116                 if ( !detectors.IsNull() ) {
117                   detectorsW = qas.Run(detectors, rawReader) ;
118                   qas.Reset() ;
119                 } else {
120                   AliError("No valid detectors found") ; 
121                 } 
122                 delete rawReader;
123         }
124         AliLog::Flush();
125         qas.Merge(runNumber) ; 
126         
127         AliLog::Flush();
128         // The summary 
129         AliInfo(Form("\n\n********** Summary for run %d **********", runNumber)) ; 
130         printf("     detectors present in the run        : %s\n", detectors.Data()) ; 
131         printf("     detectors present in the run with QA: %s\n", detectorsW.Data()) ; 
132         printf("     number of files processed           : %d\n", file) ; 
133         TFile * qaResult = TFile::Open(AliQA::GetQAResultFileName()) ; 
134         AliQA * qa = dynamic_cast<AliQA *>(qaResult->Get("QA")) ; 
135         for (Int_t index = 0 ; index < AliQA::kNDET ; index++)
136                 if (detectorsW.Contains(AliQA::GetDetName(AliQA::DETECTORINDEX(index)))) 
137                         qa->ShowStatus(AliQA::DETECTORINDEX(index)) ;
138 }