AliPhysics  64f4410 (64f4410)
GridDownloadAODs.C
Go to the documentation of this file.
1 
11 void
12 GridDownloadAODs(const char* url,
13  Bool_t verbose=false,
14  Bool_t force=false)
15 {
16  if (!TGrid::Connect("alien://")) {
17  Error("GridDownloadAODs","Failed to connect to AliEn");
18  return;
19  }
20  Printf("Directory: %s", url);
21  Printf("Verbosity: %d", verbose);
22  Printf("Force: %d", force);
23 
24 
25  TString dir(url);
26  TString pat("*/AliAOD.root");
27  TGridResult* r = gGrid->Query(dir,pat);
28  if (!r) {
29  Error("GridDownloadAODs","No result from query");
30  return;
31  }
32 
33  TStopwatch timer;
34  timer.Reset();
35  Int_t c = 0;
36  Int_t n = r->GetEntries();
37  Int_t save = gErrorIgnoreLevel;
38  if (verbose) Printf("=== Got a total of %d AOD files",n);
39  for (Int_t i = 0; i < n; i++) {
40  TString path(r->GetKey(i, "turl"));
41  TString dir(gSystem->DirName(path));
42  TString sub(gSystem->BaseName(dir));
43  TString subsub(gSystem->BaseName(gSystem->DirName(dir)));
44  TString out = TString::Format("AliAOD_%s_%s.root",
45  subsub.Data(),sub.Data());
46  if (!gSystem->AccessPathName(out.Data()) && !force) {
47  if (verbose) Printf("=== Already have %s",out.Data());
48  continue;
49  }
50  if (verbose) Printf("=== Getting %s %s (%3d/%3d)",
51  subsub.Data(),sub.Data(),i,n);
52  else {
53  printf("%5d/%5d %22s ", i+1, n, out.Data());
54  fflush(stdout);
55  }
56 
57  gErrorIgnoreLevel = kError;
58  if (!TFile::Cp(path, out, verbose)) {
59  gErrorIgnoreLevel = save;
60  Warning("DownloadAODs","Failed to copy %s -> %s",
61  path.Data(), out.Data());
62  continue;
63  }
64  c++;
65  gErrorIgnoreLevel = save;
66  if (verbose) continue;
67 
68  Double_t passed = timer.RealTime();
69  timer.Continue();
70  Double_t perFile = passed / c;
71  Double_t remain = (n-i-1) * perFile;
72  printf("%5.1f%% [%3d copied] ETA: %4d:%02d:%02d (%5.1fs/file)\r",
73  100*float(i+1)/n, c,
74  Int_t(remain/60/60),
75  Int_t(remain/60)%60,
76  Int_t(remain)%60,
77  perFile);
78  fflush(stdout);
79 
80  }
81 
82 }
83 //
84 // EOF
85 //
double Double_t
Definition: External.C:58
const char * url
TSystem * gSystem
TCanvas * c
Definition: TestFitELoss.C:172
void GridDownloadAODs(const char *url, Bool_t verbose=false, Bool_t force=false)
int Int_t
Definition: External.C:63
bool Bool_t
Definition: External.C:53
TDirectoryFile * dir