]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/muon/CpMacroWithFilter.C
add setter
[u/mrichter/AliRoot.git] / PWG / muon / CpMacroWithFilter.C
1 //
2 //  CpMacroWithFilter.C
3 //
4 //  Created by Laurent Aphecetche on 30-sep-2013.
5 //
6
7 Int_t CpMacroWithFilter(TString from, TString to)
8 {
9   /// Copy one file from url "from" into url "to".
10   ///
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
14   ///
15   /// otherwise we do a simple TFile::Cp(from,to)
16   ///
17   
18   if (from.IsNull() || to.IsNull()) return 1;
19   
20   std::cout << Form("Entering CpMacroWithFilter(\"%s\",\"%s\")",from.Data(),to.Data()) << std::endl;
21   
22   TObjArray filters;
23   filters.SetOwner(kTRUE);
24   
25   filters.Add(new TObjString("FILTER_AODMUONWITHTRACKLETS"));
26   filters.Add(new TObjString("FILTER_RAWMUON"));
27   
28   TIter next(&filters);
29   TObjString* s;
30   TString filter;
31   
32   while ( ( s = static_cast<TObjString*>(next())) )
33   {
34       if ( from.Contains(s->String()) )
35       {
36         filter = s->String();
37         break;
38       }
39   }
40   
41   if (from.Contains("alien:\/\/")) TGrid::Connect("alien:\/\/");
42
43   if ( filter.Length() > 0 )
44   {
45     // check the required filter is actually available
46     
47     from.ReplaceAll(filter.Data(),"");
48     from.ReplaceAll("..",".");
49     
50     if ( gSystem->AccessPathName(Form("%s/etc/%s.C",gSystem->Getenv("XRDDMSYS"),filter.Data()) ) )
51     {
52       std::cout << Form("ERROR: could not find a filter named %s.C",filter.Data()) << std::endl;
53       return 2;
54     }
55     else
56     {
57       // check also we have a companion macro (to load the relevant libraries and
58       // set the additional include paths, if needed)
59       
60       if ( gSystem->AccessPathName(Form("%s/etc/%s_rootlogon.C",gSystem->Getenv("XRDDMSYS"),filter.Data()) ) )
61       {
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;
63         return 3;
64       }
65
66       else
67       {
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.
70         //
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")));
74         
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")));
78
79         // execute the companion macro
80
81         std::cout << Form("Will load companion macro %s_rootlogon.C(\"%s\",\"%s\")",filter.Data(),from.Data(),to.Data()) << std::endl;
82
83         gROOT->Macro(Form("%s_rootlogon.C",filter.Data()));
84         
85         std::cout << gSystem->GetIncludePath() << std::endl;
86         
87         // finally delegate the work to the required filter
88       
89         std::cout << Form("Will compile filter %s.C+(\"%s\",\"%s\")",filter.Data(),from.Data(),to.Data()) << std::endl;
90
91         Int_t fail = gROOT->LoadMacro(Form("%s.C+",filter.Data()));
92       
93         if ( fail )
94         {
95           std::cout << Form("Failed to load/compile macro %s.C+",filter.Data()) << std::endl;
96           return 4;
97         }
98         
99         std::cout << Form("Will execute filter %s(\"%s\",\"%s\")",filter.Data(),from.Data(),to.Data()) << std::endl;
100
101         return (Int_t)gROOT->ProcessLine(Form("%s(\"%s\",\"%s\")",filter.Data(),from.Data(),to.Data()));
102       }
103     }
104   }
105   else
106   {
107     // "normal" case of a simple copy
108     //
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()));
112   }
113   
114 }