]>
Commit | Line | Data |
---|---|---|
97a28f97 | 1 | #if !defined(__CINT__) || defined(__MAKECINT__) |
2 | #include "TSystem.h" | |
3 | #include "Riostream.h" | |
4 | #include "TEnv.h" | |
5 | #include "TROOT.h" | |
6 | #include "TGrid.h" | |
7 | #include "TSystem.h" | |
8 | #include "TFile.h" | |
9 | #include "TError.h" | |
10 | #endif | |
11 | ||
12 | // copy a QAresult.root file from alien to a local directory and check it. | |
13 | ||
14 | //_____________________________________________________________________________ | |
15 | Int_t GetRunNumber(TString filePath) | |
16 | { | |
17 | TObjArray* array = filePath.Tokenize("/"); | |
18 | array->SetOwner(); | |
19 | TString auxString = ""; | |
20 | Int_t runNum = -1; | |
21 | for ( Int_t ientry=0; ientry<array->GetEntries(); ientry++ ) { | |
22 | auxString = array->At(ientry)->GetName(); | |
23 | if ( auxString.Length() == 9 && auxString.IsDigit() ) { | |
24 | runNum = auxString.Atoi(); | |
25 | break; | |
26 | } | |
27 | } | |
28 | delete array; | |
29 | ||
30 | if ( runNum < 0 ) { | |
31 | array = auxString.Tokenize("_"); | |
32 | array->SetOwner(); | |
33 | auxString = array->Last()->GetName(); | |
34 | auxString.ReplaceAll(".root",""); | |
35 | if ( auxString.IsDigit() ) | |
36 | runNum = auxString.Atoi(); | |
37 | delete array; | |
38 | } | |
39 | ||
40 | return runNum; | |
41 | } | |
42 | ||
43 | //_____________________________________________________________________________ | |
44 | ||
45 | Int_t CopyQAFile(TString inFilename, TString baseOutDir=".", Bool_t makeRunDir=kTRUE, TString changeFilename="", Int_t timeOut = 10) | |
46 | { | |
47 | ||
48 | gSystem->Setenv("XRDCLIENTMAXWAIT",Form("%d",timeOut)); | |
49 | gEnv->SetValue("XNet.RequestTimeout", timeOut); | |
50 | gEnv->SetValue("XNet.ConnectTimeout", timeOut); | |
51 | gEnv->SetValue("XNet.TransactionTimeout", timeOut); | |
52 | TFile::SetOpenTimeout(timeOut); | |
53 | ||
54 | ||
55 | if ( inFilename.Contains("alien://") && ! gGrid ) | |
56 | ||
57 | if (! TGrid::Connect("alien://")) { | |
58 | Error(__FUNCTION__,"Error connecting to alien"); | |
59 | return -1; | |
60 | } | |
61 | ||
62 | TObjArray* array = inFilename.Tokenize("/"); | |
63 | array->SetOwner(); | |
64 | TString outFilename = changeFilename.IsNull() ? array->Last()->GetName() : changeFilename.Data(); | |
65 | delete array; | |
66 | ||
67 | if ( makeRunDir ) { | |
68 | Int_t runNumber = GetRunNumber(inFilename); | |
69 | if ( runNumber >= 0 ) { | |
70 | baseOutDir = Form("%s/%i", baseOutDir.Data(), runNumber); | |
71 | if ( gSystem->AccessPathName(baseOutDir.Data()) ) | |
72 | gSystem->mkdir(baseOutDir.Data()); | |
73 | } | |
74 | else Warning(__FUNCTION__,"run number not found!"); | |
75 | } | |
76 | outFilename.Prepend(Form("%s/", baseOutDir.Data())); | |
77 | Bool_t showProgressBar = ! gROOT->IsBatch(); | |
78 | ||
79 | if ( gSystem->AccessPathName(outFilename.Data())) { | |
80 | if (! TFile::Cp(inFilename.Data(), outFilename.Data(), showProgressBar)) { | |
81 | Error(__FUNCTION__,"Error copying the file from alien"); | |
82 | return -2; | |
83 | } | |
84 | } | |
85 | ||
86 | printf("file: %s\n", inFilename.Data()); | |
87 | printf("outDir: %s\n", baseOutDir.Data()); | |
88 | printf("outFile: %s\n", outFilename.Data()); | |
89 | ||
90 | gErrorIgnoreLevel = kWarning +1; | |
91 | TFile f(outFilename.Data()); | |
92 | gErrorIgnoreLevel = -1; | |
93 | ||
94 | if (f.IsZombie()) { | |
95 | Error(__FUNCTION__,"Error opening outFile"); | |
96 | return -3; | |
97 | } | |
98 | ||
99 | if (f.TestBit(TFile::kRecovered)) { | |
100 | Info(__FUNCTION__,"The file is likely to be corrupted"); | |
101 | return -4; | |
102 | } | |
103 | ||
104 | return 0; | |
105 | } | |
106 |