AliPhysics  449db5a (449db5a)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CopyQAFile.C
Go to the documentation of this file.
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 
21 
22 //_____________________________________________________________________________
24 {
25  TObjArray* array = filePath.Tokenize("/");
26  array->SetOwner();
27  TString auxString = "";
28  Int_t runNum = -1;
29  for ( Int_t ientry=0; ientry<array->GetEntries(); ientry++ ) {
30  auxString = array->At(ientry)->GetName();
31  if ( auxString.Length() == 9 && auxString.IsDigit() ) {
32  runNum = auxString.Atoi();
33  break;
34  }
35  }
36  delete array;
37 
38  if ( runNum < 0 ) {
39  array = auxString.Tokenize("_");
40  array->SetOwner();
41  auxString = array->Last()->GetName();
42  auxString.ReplaceAll(".root","");
43  if ( auxString.IsDigit() )
44  runNum = auxString.Atoi();
45  delete array;
46  }
47 
48  return runNum;
49 }
50 
51 //_____________________________________________________________________________
52 Int_t CopyQAFile(TString inFilename, TString baseOutDir=".", Bool_t makeRunDir=kTRUE, TString changeFilename="", Int_t timeOut = 10)
53 {
54 
55  gSystem->Setenv("XRDCLIENTMAXWAIT",Form("%d",timeOut));
56  gEnv->SetValue("XNet.RequestTimeout", timeOut);
57  gEnv->SetValue("XNet.ConnectTimeout", timeOut);
58  gEnv->SetValue("XNet.TransactionTimeout", timeOut);
59  TFile::SetOpenTimeout(timeOut);
60 
61 
62  if ( inFilename.Contains("alien://") && ! gGrid )
63 
64  if (! TGrid::Connect("alien://")) {
65  Error(__FUNCTION__,"Error connecting to alien");
66  return -1;
67  }
68 
69  TObjArray* array = inFilename.Tokenize("/");
70  array->SetOwner();
71  TString outFilename = changeFilename.IsNull() ? array->Last()->GetName() : changeFilename.Data();
72  delete array;
73 
74  if ( makeRunDir ) {
75  Int_t runNumber = GetRunNumber(inFilename);
76  if ( runNumber >= 0 ) {
77  baseOutDir = Form("%s/%i", baseOutDir.Data(), runNumber);
78  if ( gSystem->AccessPathName(baseOutDir.Data()) )
79  gSystem->mkdir(baseOutDir.Data());
80  }
81  else Warning(__FUNCTION__,"run number not found!");
82  }
83  outFilename.Prepend(Form("%s/", baseOutDir.Data()));
84  Bool_t showProgressBar = ! gROOT->IsBatch();
85 
86  if ( gSystem->AccessPathName(outFilename.Data())) {
87  if (! TFile::Cp(inFilename.Data(), outFilename.Data(), showProgressBar)) {
88  Error(__FUNCTION__,"Error copying the file from alien");
89  return -2;
90  }
91  }
92 
93  printf("file: %s\n", inFilename.Data());
94  printf("outDir: %s\n", baseOutDir.Data());
95  printf("outFile: %s\n", outFilename.Data());
96 
97  gErrorIgnoreLevel = kWarning +1;
98  TFile f(outFilename.Data());
99  gErrorIgnoreLevel = -1;
100 
101  if (f.IsZombie()) {
102  Error(__FUNCTION__,"Error opening outFile");
103  return -3;
104  }
105 
106  if (f.TestBit(TFile::kRecovered)) {
107  Info(__FUNCTION__,"The file is likely to be corrupted");
108  return -4;
109  }
110 
111  return 0;
112 }
113 
Int_t GetRunNumber(TString filePath)
Definition: CopyQAFile.C:23
TSystem * gSystem
int Int_t
Definition: External.C:63
Int_t CopyQAFile(TString inFilename, TString baseOutDir=".", Bool_t makeRunDir=kTRUE, TString changeFilename="", Int_t timeOut=10)
Definition: CopyQAFile.C:52
bool Bool_t
Definition: External.C:53