]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/muon/CpMacroWithFilter.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWG / muon / CpMacroWithFilter.C
CommitLineData
8dda6345 1//
2// CpMacroWithFilter.C
3//
7bca7d11 4// Created by Laurent Aphecetche
8dda6345 5//
6
7bca7d11 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
8cc70f23 19Int_t CpMacroWithFilter(TString from, const TString& to,
20 TString filterName,
21 const TString& filterMacroFullPath,
22 const TString& filterRootLogonFullPath,
23 const TString& alirootPath)
8dda6345 24{
8dda6345 25 ///
8cc70f23 26 /// Copy one file from url "from" into url "to", while filtering it at the same time.
8dda6345 27 ///
8dda6345 28
8cc70f23 29 std::cout << "CpMacroWithFilter from : " << from.Data() << std::endl << " to : " << to.Data() << std::endl
30 << " with filter " << filterName.Data() << std::endl;
7bca7d11 31
8cc70f23 32 if (from.IsNull() || to.IsNull()) return -1;
8dda6345 33
7bca7d11 34 if ( gSystem->AccessPathName(filterMacroFullPath.Data()) )
8dda6345 35 {
7bca7d11 36 std::cerr << "Could not find requested filter macro (looking into " << filterMacroFullPath.Data() << ")" << std::endl;
37 return -3;
38 }
8dda6345 39
7bca7d11 40 // check that the companion macro (to load the relevant libraries
41 // and set the additional include paths, if needed) exists
8dda6345 42
7bca7d11 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 }
7bca7d11 48
8cc70f23 49 if (from.Contains("alien://"))
50 {
51 TGrid::Connect("alien://");
7bca7d11 52
8cc70f23 53 if (!gGrid)
54 {
55 std::cerr << "Cannot get gGrid !" << std::endl;
56 return -5;
57 }
58 }
7bca7d11 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()));
8dda6345 68
7bca7d11 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());
8dda6345 73
7bca7d11 74 std::cout << gSystem->GetIncludePath() << std::endl;
75
76 // finally delegate the work to the required filter
8dda6345 77
7bca7d11 78 std::cout << Form("Will compile filter %s+(\"%s\",\"%s\")",filterMacroFullPath.Data(),from.Data(),to.Data()) << std::endl;
8dda6345 79
8cc70f23 80 TString compile(filterMacroFullPath.Data());
81
82 compile += "+";
83
84 Int_t fail = gROOT->LoadMacro(compile.Data());
8dda6345 85
7bca7d11 86 if ( fail )
87 {
88 std::cout << Form("Failed to load/compile macro %s+",filterMacroFullPath.Data()) << std::endl;
89 return -6;
90 }
8dda6345 91
7bca7d11 92 std::cout << Form("Will execute filter %s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()) << std::endl;
8dda6345 93
7bca7d11 94 return (Int_t)gROOT->ProcessLine(Form("%s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()));
8dda6345 95 }
8cc70f23 96
97 return 0;
8dda6345 98}