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