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