]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/trains/GridDownload.C
Merge remote-tracking branch 'origin/flatdev' into mergeFlat2Master
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / GridDownload.C
1 /**
2  * @file   GridDownload.C
3  * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4  * @date   Wed Jan 23 21:51:40 2013
5  * 
6  * @brief  Helper script to download results from the Grid 
7  * 
8  * 
9  * @ingroup pwglf_forward_trains_helper
10  */
11 #ifndef __CINT__
12 # include <TString.h>
13 # include <TSystem.h>
14 # include <TGrid.h>
15 # include <TFile.h>
16 # include <TObjArray.h>
17 # include <TObjString.h>
18 # include <TError.h>
19 # include <TEnv.h>
20 #else
21 class TString;
22 #endif
23
24 /** 
25  * Get one file 
26  * 
27  * @param base   Base name 
28  * @param dir    Directory 
29  * @param unpack If true, also unzip the retrieved archive 
30  * 
31  * @return true on success 
32  */
33 Bool_t GetOne(const TString& base, const TString& dir, Bool_t unpack)
34 {
35   TString src(gSystem->ConcatFileName(base,dir));
36   src = gSystem->ConcatFileName(src,"root_archive.zip");
37   TString name;
38   name.Form("root_archive_%s",dir.Data());
39   TString dest;
40   dest.Form("%s.zip",name.Data());
41
42   if (!TFile::Cp(src, dest)) {
43     Error("GetOne","Failed to download %s -> %s",
44           src.Data(), dest.Data());
45     return false;
46   }
47   if (!unpack) return true;
48   gSystem->Exec(Form("mkdir -p %s && (cd %s && unzip ../%s)", 
49                      name.Data(), name.Data(), dest.Data()));
50   return true;
51 }
52
53 void GridDownload(const TString& base, const TString& runs, Bool_t unpack)
54 {
55   gEnv->SetValue("XSec.GSI.DelegProxy", "2");
56   if (!TGrid::Connect("alien://")) {
57     Error("Download","Failed to connect to AliEn");
58     return;
59   }
60
61   TObjArray*  runArray = runs.Tokenize(" ");
62   TObjString* run      = 0;
63   TIter       next(runArray);
64   while ((run = static_cast<TObjString*>(next()))) {
65     GetOne(base, run->String(), unpack);
66   }
67 }
68 // EOF
69