4 // Created by Laurent Aphecetche on 30-sep-2013.
7 Int_t CpMacroWithFilter(TString from, TString to)
9 /// Copy one file from url "from" into url "to".
11 /// If from contains one of the filter keywords
12 /// (in the form of e.g. AliAOD.FILTER_ZZZZ.root)
13 /// then we call the external filter macro
15 /// otherwise we do a simple TFile::Cp(from,to)
18 if (from.IsNull() || to.IsNull()) return 1;
20 std::cout << Form("Entering CpMacroWithFilter(\"%s\",\"%s\")",from.Data(),to.Data()) << std::endl;
23 filters.SetOwner(kTRUE);
25 filters.Add(new TObjString("FILTER_AODMUONWITHTRACKLETS"));
26 filters.Add(new TObjString("FILTER_RAWMUON"));
32 while ( ( s = static_cast<TObjString*>(next())) )
34 if ( from.Contains(s->String()) )
41 if (from.Contains("alien:\/\/")) TGrid::Connect("alien:\/\/");
43 if ( filter.Length() > 0 )
45 // check the required filter is actually available
47 from.ReplaceAll(filter.Data(),"");
48 from.ReplaceAll("..",".");
50 if ( gSystem->AccessPathName(Form("%s/etc/%s.C",gSystem->Getenv("XRDDMSYS"),filter.Data()) ) )
52 std::cout << Form("ERROR: could not find a filter named %s.C",filter.Data()) << std::endl;
57 // check also we have a companion macro (to load the relevant libraries and
58 // set the additional include paths, if needed)
60 if ( gSystem->AccessPathName(Form("%s/etc/%s_rootlogon.C",gSystem->Getenv("XRDDMSYS"),filter.Data()) ) )
62 std::cout << Form("ERROR: could not find the companion macro %s_rootlogon.C for the filter named %s.C",filter.Data(),filter.Data()) << std::endl;
68 // most probably the filter will require AliRoot libs, so add the dynamic path here
69 // as well as the include path and the macro path.
71 gSystem->AddDynamicPath(Form("%s/aliroot/lib/tgt_%s",gSystem->Getenv("ALICE_PROOF_AAF_DIR"),gSystem->GetBuildArch()));
72 gSystem->SetIncludePath(Form("-I%s/etc -I%s/aliroot/include",gSystem->Getenv("XRDDMSYS"),gSystem->Getenv("ALICE_PROOF_AAF_DIR")));
73 gROOT->SetMacroPath(Form("%s:%s/etc",gROOT->GetMacroPath(),gSystem->Getenv("XRDDMSYS")));
75 // gSystem->AddDynamicPath(Form("/pool/PROOF-AAF/aliroot/lib/tgt_%s",gSystem->GetBuildArch()));
76 // gSystem->SetIncludePath("-I/pool/PROOF-AAF/xrootd_1.0.50/etc -I/pool/PROOF-AAF/aliroot/include");
77 // gROOT->SetMacroPath(Form("%s:%s/etc",gROOT->GetMacroPath(),gSystem->Getenv("XRDDMSYS")));
79 // execute the companion macro
81 std::cout << Form("Will load companion macro %s_rootlogon.C(\"%s\",\"%s\")",filter.Data(),from.Data(),to.Data()) << std::endl;
83 gROOT->Macro(Form("%s_rootlogon.C",filter.Data()));
85 std::cout << gSystem->GetIncludePath() << std::endl;
87 // finally delegate the work to the required filter
89 std::cout << Form("Will compile filter %s.C+(\"%s\",\"%s\")",filter.Data(),from.Data(),to.Data()) << std::endl;
91 Int_t fail = gROOT->LoadMacro(Form("%s.C+",filter.Data()));
95 std::cout << Form("Failed to load/compile macro %s.C+",filter.Data()) << std::endl;
99 std::cout << Form("Will execute filter %s(\"%s\",\"%s\")",filter.Data(),from.Data(),to.Data()) << std::endl;
101 return (Int_t)gROOT->ProcessLine(Form("%s(\"%s\",\"%s\")",filter.Data(),from.Data(),to.Data()));
107 // "normal" case of a simple copy
109 // ! operator since TFile::Cp returns kTRUE(1) in case of success
110 std::cout << "Performing a simple TFile::Cp" << std::endl;
111 return (!TFile::Cp(from.Data(),to.Data()));