going from local to 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>
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
20TString ClassName() { return "rawqa" ; }
21
22//________________________________qa______________________________________
87929a37 23void rawqa(const Int_t runNumber, const UInt_t kMaxFiles = 10, const char* year = "08")
40d0f38f 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 ;
40d0f38f 42 Bool_t local = kFALSE ;
43 if (grid) { // get the list of files from AliEn directly
44 TString baseDir;
45 baseDir.Form("/alice/data/20%s/",year);
46 result = grid->Query(baseDir, pattern) ;
47 } else {
48 TString collectionFile(pattern) ;
49 collectionFile.Append(".xml") ;
50 if ( gSystem->AccessPathName(collectionFile) == 0 ) { // get the list of files from an a-priori created collection file
51 TAlienCollection collection(collectionFile.Data(), kMaxFiles) ;
52 result = collection.GetGridResult("", 0, 0);
53 } else { // get the list of files from the local current directory
54 local = kTRUE ;
55 char line[100] ;
56 sprintf(line, ".! ls %s*.root > tempo.txt", pattern.Data()) ;
57 gROOT->ProcessLine(line) ;
58 }
59 }
60 AliLog::Flush();
61 ifstream in ;
62 if (local)
63 in.open("tempo.txt", ifstream::in) ;
64
65 AliCDBManager* man = AliCDBManager::Instance();
72c25501 66 man->SetDefaultStorage(AliQA::GetQARefDefaultStorage()) ;
67 AliQA::SetQARefStorage("alien://folder=/alice/QA/2008") ;
68 man->SetSpecificStorage(Form("%s/20%s/*", AliQA::GetQAOCDBDirName(), year),AliQA::GetQARefStorage());
40d0f38f 69 AliQADataMakerSteer qas ;
70 TString detectors = "";
71 TString detectorsW = "";
72 UShort_t file = 0 ;
87929a37 73 UShort_t filesProcessed = 0 ;
40d0f38f 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;
87929a37 85 filesProcessed++ ;
40d0f38f 86 char input[200] ;
87 if (local)
88 sprintf(input, "%s", fileName.Data()) ;
89 else
90 sprintf(input, "%s", result->GetKey(file, "turl"));
91 AliInfo(Form("Proccessing file # %d --> %s", file, input)) ;
92 AliLog::Flush();
93 // check which detectors are present
94 AliRawReader * rawReader = new AliRawReaderRoot(input);
95 rawReader->NextEvent() ;
96 man->SetRun(rawReader->GetRunNumber());
97 UChar_t * data ;
98 while (rawReader->ReadNextData(data)) {
99 Int_t detID = rawReader->GetDetectorID();
100 if (detID < 0 || detID >= AliDAQ::kNDetectors) {
101 AliError("Wrong detector ID! Skipping payload...");
102 continue;
103 }
104 detIn[detID] = kTRUE ;
105 }
106 for (Int_t detID = 0; detID < AliDAQ::kNDetectors ; detID++) {
107 if (detIn[detID]) {
108 if ( ! detectors.Contains(detNameOff[detID]) ) {
109 detectors.Append(detNameOff[detID]) ;
110 detectors.Append(" ") ;
111 }
112 }
113 }
114 // TEMPORARY REMOVAL OF TRD!!!
115 detectors.ReplaceAll("TRD","");
116 // TEMPORARY REMOVAL OF TRD!!!
117 if ( !detectors.IsNull() ) {
118 detectorsW = qas.Run(detectors, rawReader) ;
119 qas.Reset() ;
120 } else {
121 AliError("No valid detectors found") ;
122 }
123 delete rawReader;
124 }
125 AliLog::Flush();
126 qas.Merge(runNumber) ;
127
128 AliLog::Flush();
129 // The summary
130 AliInfo(Form("\n\n********** Summary for run %d **********", runNumber)) ;
131 printf(" detectors present in the run : %s\n", detectors.Data()) ;
132 printf(" detectors present in the run with QA: %s\n", detectorsW.Data()) ;
87929a37 133 printf(" number of files processed : %d\n", filesProcessed) ;
40d0f38f 134 TFile * qaResult = TFile::Open(AliQA::GetQAResultFileName()) ;
135 AliQA * qa = dynamic_cast<AliQA *>(qaResult->Get("QA")) ;
136 for (Int_t index = 0 ; index < AliQA::kNDET ; index++)
137 if (detectorsW.Contains(AliQA::GetDetName(AliQA::DETECTORINDEX(index))))
138 qa->ShowStatus(AliQA::DETECTORINDEX(index)) ;
139}