]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/muon/CpMacroWithFilter.C
The filter name and aliroot version are now given to the macro
[u/mrichter/AliRoot.git] / PWG / muon / CpMacroWithFilter.C
1 //
2 //  CpMacroWithFilter.C
3 //
4 //  Created by Laurent Aphecetche
5 //
6
7 #if !defined(__CINT__) || defined(__MAKECINT__)
8
9 #include "Riostream.h"
10 #include "TString.h"
11 #include "TSystem.h"
12 #include "TROOT.h"
13 #include "TGrid.h"
14 #include "TFile.h"
15 #include "TObjString.h"
16
17 #endif
18
19 Int_t CpMacroWithFilter(TString from, const TString& to, 
20                         TString filterName,
21                         const TString& filterMacroFullPath,
22                         const TString& filterRootLogonFullPath,
23                         const TString& alirootPath)
24 {
25   ///
26   /// Copy one file from url "from" into url "to", while filtering it at the same time.
27   ///
28   
29   std::cout << "CpMacroWithFilter from : " << from.Data() << std::endl << " to : " << to.Data() << std::endl
30             << " with filter " << filterName.Data() << std::endl;
31
32   if (from.IsNull() || to.IsNull()) return -1;
33   
34     if ( gSystem->AccessPathName(filterMacroFullPath.Data()) )
35     {
36       std::cerr << "Could not find requested filter macro (looking into " << filterMacroFullPath.Data() << ")" << std::endl;
37       return -3;
38     }
39
40     // check that the companion macro (to load the relevant libraries 
41     // and set the additional include paths, if needed) exists
42
43     if ( gSystem->AccessPathName(filterRootLogonFullPath.Data()) )
44     {
45       std::cerr << "Could not find requested filter companion macro (looking into " << filterRootLogonFullPath.Data() << ")" << std::endl;
46       return -4;
47     }
48   
49   if (from.Contains("alien://")) 
50   {
51       TGrid::Connect("alien://");
52
53       if (!gGrid)
54         {
55           std::cerr << "Cannot get gGrid !" << std::endl;
56           return -5;
57         }
58   }
59
60   if ( !filterName.IsNull() ) 
61   {
62     // most probably the filter will require AliRoot libs, so add the dynamic path here
63     // as well as the include path and the macro path.
64     //
65     gSystem->AddDynamicPath(Form("%s/lib/tgt_%s",alirootPath.Data(),gSystem->GetBuildArch()));
66     gSystem->SetIncludePath(Form("-I%s/include -I%s/PWG/muon",alirootPath.Data(),alirootPath.Data()));
67     gROOT->SetMacroPath(Form("%s:%s/PWG/muon",gROOT->GetMacroPath(),alirootPath.Data()));
68         
69     // execute the companion macro
70     std::cout << Form("Will load companion macro %s(\"%s\",\"%s\")",filterRootLogonFullPath.Data(),from.Data(),to.Data()) << std::endl;
71
72     gROOT->Macro(filterRootLogonFullPath.Data());
73         
74     std::cout << gSystem->GetIncludePath() << std::endl;
75         
76     // finally delegate the work to the required filter
77       
78     std::cout << Form("Will compile filter %s+(\"%s\",\"%s\")",filterMacroFullPath.Data(),from.Data(),to.Data()) << std::endl;
79
80     TString compile(filterMacroFullPath.Data());
81
82     compile += "+";
83
84     Int_t fail = gROOT->LoadMacro(compile.Data());
85       
86     if ( fail )
87     {
88       std::cout << Form("Failed to load/compile macro %s+",filterMacroFullPath.Data()) << std::endl;
89       return -6;
90     }
91         
92     std::cout << Form("Will execute filter %s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()) << std::endl;
93
94     return (Int_t)gROOT->ProcessLine(Form("%s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()));
95   }
96
97   return 0;
98 }