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());
51 std::cerr << "Could not get filter ??? Filename does not look right !!!" << std::endl;
54 filterName = ostr->String();
56 ix = filterName.Index("_WITH_");
59 alirootVersion = filterName(ix+strlen("_WITH_ALIROOT_"),part.Length()-ix-strlen("_WITH_ALIROOT_"));
60 filterName = filterName(0,ix);
64 alirootPath += alirootVersion;
66 // check the aliroot version required actually exists on cvmfs...
67 if ( gSystem->AccessPathName(alirootPath.Data()) )
69 std::cerr << "Requested AliRoot version not found (looking into " << alirootPath.Data() << ")" << std::endl;
73 // check the filter required actually exists
74 filterMacroFullPath.Form("%s/PWG/muon/%s.C",alirootPath.Data(),filterName.Data());
76 if ( gSystem->AccessPathName(filterMacroFullPath.Data()) )
78 std::cerr << "Could not find requested filter macro (looking into " << filterMacroFullPath.Data() << ")" << std::endl;
82 // check that the companion macro (to load the relevant libraries
83 // and set the additional include paths, if needed) exists
85 filterRootLogonFullPath.Form("%s/PWG/muon/%s_rootlogon.C",alirootPath.Data(),filterName.Data());
87 if ( gSystem->AccessPathName(filterRootLogonFullPath.Data()) )
89 std::cerr << "Could not find requested filter companion macro (looking into " << filterRootLogonFullPath.Data() << ")" << std::endl;
93 from.ReplaceAll(filterName.Data(),"");
94 from.ReplaceAll("_WITH_ALIROOT_","");
95 from.ReplaceAll(alirootVersion,"");
96 from.ReplaceAll("..",".");
98 std::cout << "Will filter file=" << from.Data() << std::endl;
101 if (from.Contains("alien://")) TGrid::Connect("alien://");
105 std::cerr << "Cannot get gGrid !" << std::endl;
109 if ( !filterName.IsNull() )
111 // most probably the filter will require AliRoot libs, so add the dynamic path here
112 // as well as the include path and the macro path.
114 gSystem->AddDynamicPath(Form("%s/lib/tgt_%s",alirootPath.Data(),gSystem->GetBuildArch()));
115 gSystem->SetIncludePath(Form("-I%s/include -I%s/PWG/muon",alirootPath.Data(),alirootPath.Data()));
116 gROOT->SetMacroPath(Form("%s:%s/PWG/muon",gROOT->GetMacroPath(),alirootPath.Data()));
118 // execute the companion macro
119 std::cout << Form("Will load companion macro %s(\"%s\",\"%s\")",filterRootLogonFullPath.Data(),from.Data(),to.Data()) << std::endl;
121 gROOT->Macro(filterRootLogonFullPath.Data());
123 std::cout << gSystem->GetIncludePath() << std::endl;
125 // finally delegate the work to the required filter
127 std::cout << Form("Will compile filter %s+(\"%s\",\"%s\")",filterMacroFullPath.Data(),from.Data(),to.Data()) << std::endl;
129 Int_t fail = gROOT->LoadMacro(Form("%s.C+",filterName.Data()));
133 std::cout << Form("Failed to load/compile macro %s+",filterMacroFullPath.Data()) << std::endl;
137 std::cout << Form("Will execute filter %s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()) << std::endl;
139 return (Int_t)gROOT->ProcessLine(Form("%s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()));
143 // "normal" case of a simple copy
145 // ! operator since TFile::Cp returns kTRUE(1) in case of success
146 std::cout << "Performing a simple TFile::Cp" << std::endl;
147 return (!TFile::Cp(from.Data(),to.Data()));