]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
The filter name and aliroot version are now given to the macro
authorlaphecet <laurent.aphecetche@subatech.in2p3.fr>
Tue, 16 Dec 2014 16:49:25 +0000 (17:49 +0100)
committerlaphecet <laurent.aphecetche@subatech.in2p3.fr>
Tue, 16 Dec 2014 16:49:40 +0000 (17:49 +0100)
PWG/muon/CpMacroWithFilter.C

index b1eb3f05c69d89c71c66d923af08ea992a275d0a..989b871da7f1ff2e8d9ae68946908296ffadfe85 100644 (file)
 
 #endif
 
-Int_t CpMacroWithFilter(TString from, TString to)
+Int_t CpMacroWithFilter(TString from, const TString& to, 
+                       TString filterName,
+                       const TString& filterMacroFullPath,
+                       const TString& filterRootLogonFullPath,
+                       const TString& alirootPath)
 {
-  /// Copy one file from url "from" into url "to".
   ///
-  /// If from contains one of the filter keywords
-  /// (in the form of e.g. AliAOD.FILTER_ZZZZ_WITH_ALIROOT_YYYY.root)
-  /// then we call the external filter macro
+  /// Copy one file from url "from" into url "to", while filtering it at the same time.
   ///
-  /// otherwise we do a simple TFile::Cp(from,to)
-  ///
-
-  const char* swBaseDir = "/cvmfs/alice.cern.ch/x86_64-2.6-gnu-4.1.2/Packages/AliRoot";
-  
-  if (from.IsNull() || to.IsNull()) return -1;
   
-  std::cout << Form("Entering CpMacroWithFilter(\"%s\",\"%s\")",from.Data(),to.Data()) << std::endl;
-  
-  TString filterName;
-  TString alirootVersion;
-  TString alirootPath(swBaseDir);
-  TString filterMacroFullPath;
-  TString filterRootLogonFullPath;
+  std::cout << "CpMacroWithFilter from : " << from.Data() << std::endl << " to : " << to.Data() << std::endl
+           << " with filter " << filterName.Data() << std::endl;
 
-  Int_t ix = from.Index("FILTER_");
+  if (from.IsNull() || to.IsNull()) return -1;
   
-  if ( ix > 0)
-  {
-    TString part = from(ix,from.Length()-ix+1);
-    TObjArray* tmp = part.Tokenize(".");
-    TObjString* ostr = static_cast<TObjString*>(tmp->First());
-    if (!ostr)
-    {
-      std::cerr << "Could not get filter ??? Filename does not look right !!!" << std::endl;
-      return -2;
-    }
-    filterName = ostr->String();
-    delete tmp;
-    ix = filterName.Index("_WITH_");
-    if ( ix > 0 )
-    {
-      alirootVersion = filterName(ix+strlen("_WITH_ALIROOT_"),part.Length()-ix-strlen("_WITH_ALIROOT_"));
-      filterName = filterName(0,ix);
-    }
-
-    alirootPath += "/";
-    alirootPath += alirootVersion;
-
-    // check the aliroot version required actually exists on cvmfs...
-    if ( gSystem->AccessPathName(alirootPath.Data()) ) 
-    {
-       std::cerr << "Requested AliRoot version not found (looking into " << alirootPath.Data() << ")" << std::endl;
-       return -2;
-    }
-
-    // check the filter required actually exists
-    filterMacroFullPath.Form("%s/PWG/muon/%s.C",alirootPath.Data(),filterName.Data());
-   
     if ( gSystem->AccessPathName(filterMacroFullPath.Data()) )
     {
       std::cerr << "Could not find requested filter macro (looking into " << filterMacroFullPath.Data() << ")" << std::endl;
@@ -82,29 +40,22 @@ Int_t CpMacroWithFilter(TString from, TString to)
     // check that the companion macro (to load the relevant libraries 
     // and set the additional include paths, if needed) exists
 
-    filterRootLogonFullPath.Form("%s/PWG/muon/%s_rootlogon.C",alirootPath.Data(),filterName.Data());
-
     if ( gSystem->AccessPathName(filterRootLogonFullPath.Data()) )
     {
       std::cerr << "Could not find requested filter companion macro (looking into " << filterRootLogonFullPath.Data() << ")" << std::endl;
       return -4;
     }
-
-    from.ReplaceAll(filterName.Data(),"");
-    from.ReplaceAll("_WITH_ALIROOT_","");
-    from.ReplaceAll(alirootVersion,"");
-    from.ReplaceAll("..",".");
-
-    std::cout << "Will filter file=" << from.Data() << std::endl;
-  }
   
-  if (from.Contains("alien://")) TGrid::Connect("alien://");
+  if (from.Contains("alien://")) 
+  {
+      TGrid::Connect("alien://");
 
-  if (!gGrid)
-    {
-      std::cerr << "Cannot get gGrid !" << std::endl;
-      return -5;
-    }
+      if (!gGrid)
+       {
+         std::cerr << "Cannot get gGrid !" << std::endl;
+         return -5;
+       }
+  }
 
   if ( !filterName.IsNull() ) 
   {
@@ -126,7 +77,11 @@ Int_t CpMacroWithFilter(TString from, TString to)
       
     std::cout << Form("Will compile filter %s+(\"%s\",\"%s\")",filterMacroFullPath.Data(),from.Data(),to.Data()) << std::endl;
 
-    Int_t fail = gROOT->LoadMacro(Form("%s.C+",filterName.Data()));
+    TString compile(filterMacroFullPath.Data());
+
+    compile += "+";
+
+    Int_t fail = gROOT->LoadMacro(compile.Data());
       
     if ( fail )
     {
@@ -138,13 +93,6 @@ Int_t CpMacroWithFilter(TString from, TString to)
 
     return (Int_t)gROOT->ProcessLine(Form("%s(\"%s\",\"%s\")",filterName.Data(),from.Data(),to.Data()));
   }
-  else
-  {
-    // "normal" case of a simple copy
-    //
-    // ! operator since TFile::Cp returns kTRUE(1) in case of success
-    std::cout << "Performing a simple TFile::Cp" << std::endl;
-    return (!TFile::Cp(from.Data(),to.Data()));
-  }
-  
+
+  return 0;
 }