4 // Created by Laurent Aphecetche
7 #if !defined(__CINT__) || defined(__MAKECINT__)
15 #include "TObjString.h"
19 Int_t CpMacroWithFilter(TString from, TString to)
21 /// Copy one file from url "from" into url "to".
23 /// If from contains one of the filter keywords
24 /// (in the form of e.g. AliAOD.FILTER_ZZZZ_WITH_ALIROOT_YYYY.root)
25 /// then we call the external filter macro
27 /// otherwise we do a simple TFile::Cp(from,to)
30 const char* swBaseDir = "/cvmfs/alice.cern.ch/x86_64-2.6-gnu-4.1.2/Packages/AliRoot";
32 if (from.IsNull() || to.IsNull()) return -1;
34 std::cout << Form("Entering CpMacroWithFilter(\"%s\",\"%s\")",from.Data(),to.Data()) << std::endl;
37 TString alirootVersion;
38 TString alirootPath(swBaseDir);
39 TString filterMacroFullPath;
40 TString filterRootLogonFullPath;
42 Int_t ix = from.Index("FILTER_");
46 TString part = from(ix,from.Length()-ix+1);
47 TObjArray* tmp = part.Tokenize(".");
48 TObjString* ostr = static_cast<TObjString*>(tmp->First());
50 filterName = ostr->String();
52 ix = filterName.Index("_WITH_");
55 alirootVersion = filterName(ix+strlen("_WITH_ALIROOT_"),part.Length()-ix-strlen("_WITH_ALIROOT_"));
56 filterName = filterName(0,ix);
60 alirootPath += alirootVersion;
62 // check the aliroot version required actually exists on cvmfs...
63 if ( gSystem->AccessPathName(alirootPath.Data()) )
65 std::cerr << "Requested AliRoot version not found (looking into " << alirootPath.Data() << ")" << std::endl;
69 // check the filter required actually exists
70 filterMacroFullPath.Form("%s/PWG/muon/%s.C",alirootPath.Data(),filterName.Data());
72 if ( gSystem->AccessPathName(filterMacroFullPath.Data()) )
74 std::cerr << "Could not find requested filter macro (looking into " << filterMacroFullPath.Data() << ")" << std::endl;
78 // check that the companion macro (to load the relevant libraries
79 // and set the additional include paths, if needed) exists
81 filterRootLogonFullPath.Form("%s/PWG/muon/%s_rootlogon.C",alirootPath.Data(),filterName.Data());
83 if ( gSystem->AccessPathName(filterRootLogonFullPath.Data()) )
85 std::cerr << "Could not find requested filter companion macro (looking into " << filterRootLogonFullPath.Data() << ")" << std::endl;
89 from.ReplaceAll(filterName.Data(),"");
90 from.ReplaceAll("_WITH_ALIROOT_","");
91 from.ReplaceAll(alirootVersion,"");
92 from.ReplaceAll("..",".");
94 std::cout << "Will filter file=" << from.Data() << std::endl;
97 if (from.Contains("alien://")) TGrid::Connect("alien://");
101 std::cerr << "Cannot get gGrid !" << std::endl;
105 if ( !filterName.IsNull() )
107 // most probably the filter will require AliRoot libs, so add the dynamic path here
108 // as well as the include path and the macro path.
110 gSystem->AddDynamicPath(Form("%s/lib/tgt_%s",alirootPath.Data(),gSystem->GetBuildArch()));
111 gSystem->SetIncludePath(Form("-I%s/include -I%s/PWG/muon",alirootPath.Data(),alirootPath.Data()));
112 gROOT->SetMacroPath(Form("%s:%s/PWG/muon",gROOT->GetMacroPath(),alirootPath.Data()));
114 // execute the companion macro
115 std::cout << Form("Will load companion macro %s(\"%s\",\"%s\")",filterRootLogonFullPath.Data(),from.Data(),to.Data()) << std::endl;
117 gROOT->Macro(filterRootLogonFullPath.Data());
119 std::cout << gSystem->GetIncludePath() << std::endl;
121 // finally delegate the work to the required filter
123 std::cout << Form("Will compile filter %s+(\"%s\",\"%s\")",filterMacroFullPath.Data(),from.Data(),to.Data()) << std::endl;
125 Int_t fail = gROOT->LoadMacro(Form("%s.C+",filterName.Data()));
129 std::cout << Form("Failed to load/compile macro %s+",filterMacroFullPath.Data()) << std::endl;
133 std::cout << Form("Will execute filter %s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()) << std::endl;
135 return (Int_t)gROOT->ProcessLine(Form("%s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()));
139 // "normal" case of a simple copy
141 // ! operator since TFile::Cp returns kTRUE(1) in case of success
142 std::cout << "Performing a simple TFile::Cp" << std::endl;
143 return (!TFile::Cp(from.Data(),to.Data()));