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