ROOT logo
//-*- Mode: C++ -*-
// $Id$

/// @file   setupDxHFE.C
/// @author Matthias.Richter@cern.ch
/// @date   2012-09-12
/// @brief  Setup the environment specifically for running DxHFE analysis
///
/// Helper macro to initialize the environment for DxHFE. The macro can just
/// prepend other macros like run-single-task in the command line.
/// Usage:
/// aliroot -b -q -l setupDxHFE.C'("localAodDirectory", nofDirectories)' run-single-task.C'(...)'
/// aliroot -b -q -l setupDxHFE.C'("lhcPeriod", "mcPeriod")' run-single-task.C'(...)'
///
/// Example:
/// aliroot -b -q -l setupDxHFE.C run-single-task.C'(...)'
///
/// The macro has the following tasks:
/// - load the necessary libraries, in order to have those library names also
///   available for the alien handler initialization, a specific configuration
///   object is created
/// - setting a default analysis name via a configuration object
/// - the optional parameter 'localAodDirectory' allows to create an input chain from
///   local AODs; either a single AliAOD.root, or a folder containing directories
///   named "1, 2, ...", the number of directories is specified as parameter
///   nofDirectories
/// - loading the runs defined by AddGoodRuns of vertexingHF using lhcPeriod and
///   optional mcPeriod

///////////////////////////////////////////////////////////////////////////////////////////////////
//
// environment specific for DxHFE
//
const char* analysisName="DxHFECorrelation";
const char* includePath="-I$ALICE_ROOT/PWGHF/correlationHF -I$ALICE_ROOT/PWGHF/vertexingHF -I$ALICE_ROOT/PWGHF/hfe";
const char* libraryDependencies=
  "libSTEERBase "
  "libESD "
  "libAOD "
  "libANALYSIS "
  "libANALYSISalice "
  "libPWGflowBase.so "
  "libPWGflowTasks.so "
  "libCORRFW.so "
  "libPWGHFvertexingHF.so "
  "libPWGHFhfe.so "
  ;
// Note: "libPWGHFcorrelationHF.so " shouldn't be added here. If the library is
// loaded already, compilation of source files by Cint does not have any effect.
// The already existing class implementations are not overidden. To just load
// all necessary libraries to make the classes available in aliroot use macro
// LoadLibraries.C

void setupDxHFE(const char* localAodDirectory, int nofDirectories, const char* lhcPeriod, const char* mcProd="")
{
  //
  // adding include path and libraries
  //
  gSystem->AddIncludePath(includePath);
  TString libraries=libraryDependencies;
  TObjArray* pTokens=libraries.Tokenize(" ");
  if (pTokens) {
    for (int i=0; i<pTokens->GetEntriesFast(); i++) {
      if (gSystem->Load(pTokens->At(i)->GetName())==0) {
	cout << "loading " << pTokens->At(i)->GetName() << endl;
      }
    }
    delete pTokens;
  }
  libraries="";

  //
  // allow run-single-task to fetch the analysis name and library names
  //
  if (gDirectory) gDirectory->Add(new TNamed("analysis_name", analysisName));
  if (gDirectory) gDirectory->Add(new TNamed("analysis_libraries", libraryDependencies));

  if (lhcPeriod) {
    //
    // setting up the runs for the dpecified period
    //
    TString alienHandlerName(analysisName); alienHandlerName+="Handler";
    AliAnalysisAlien* alienHandler=new AliAnalysisAlien(alienHandlerName);
    gROOT->LoadMacro("$ALICE_ROOT/PWGHF/vertexingHF/AddGoodRuns.C");
    int nruns=AddGoodRuns(alienHandler, lhcPeriod, mcProd);
    if (nruns<=0) {
      ::Error("setupDxHFE.C", Form("can not find any good runs for period %s", lhcPeriod));
      return;
    }
    gDirectory->Add(alienHandler);
    ::Info("setupDxHFE.C", Form("setting up alien plugin '%s' for period %s\n>>>>> please use '%s' as input parameter for run-single-task.C <<<<<<", alienHandlerName.Data(), lhcPeriod, alienHandlerName.Data()));

  } else if (localAodDirectory) {
    //
    // create AOD tree from local files
    // the created object is added automatically to gDirectory and can be fetched
    // from there later
    //
    gROOT->LoadMacro("$ALICE_ROOT/PWGHF/vertexingHF/MakeAODInputChain.C");
    TString aodPathName(localAodDirectory);
    if (!aodPathName.EndsWith("/")) aodPathName+="/";
    aodPathName+="AliAOD.root";
    if (gSystem->AccessPathName(aodPathName)==0) {
      // Create a chain with one set of AliAOD.root and AliAOD.VertexingHF.root. The set needs 
      // to be located in the same folder as you run from (physically or linked)
      ::Info("setupDxHFE.C", Form("make chain from single chunk %s", aodPathName.Data()));
      TChain* chain = MakeAODInputChain(localAodDirectory ,1, -1);
    } else {
      // Assume several folders containing different AODs. 
      // The AODs need to be in folders named 1, 2,...
      aodPathName=localAodDirectory;
      if (!aodPathName.EndsWith("/")) aodPathName+="/";
      ::Info("setupDxHFE.C", Form("make chain from directory %s", aodPathName.Data()));
      chain=MakeAODInputChain(aodPathName, 1, nofDirectories);
    }
    ::Info("setupDxHFE.C", Form("local AOD chain: %d entries", chain->GetEntries()));
  }
}

void setupDxHFE(const char* lhcPeriod=NULL, const char* mcProd="")
{
  // Grid mode with optional calling of AddGoodRuns for specified
  // period
  setupDxHFE(NULL, 0, lhcPeriod, mcProd);
}

void setupDxHFE(const char* localAodDirectory, int nofDirectories)
{
  // local mode for AOD data
  setupDxHFE(localAodDirectory, nofDirectories, NULL);
}
 setupDxHFE.C:1
 setupDxHFE.C:2
 setupDxHFE.C:3
 setupDxHFE.C:4
 setupDxHFE.C:5
 setupDxHFE.C:6
 setupDxHFE.C:7
 setupDxHFE.C:8
 setupDxHFE.C:9
 setupDxHFE.C:10
 setupDxHFE.C:11
 setupDxHFE.C:12
 setupDxHFE.C:13
 setupDxHFE.C:14
 setupDxHFE.C:15
 setupDxHFE.C:16
 setupDxHFE.C:17
 setupDxHFE.C:18
 setupDxHFE.C:19
 setupDxHFE.C:20
 setupDxHFE.C:21
 setupDxHFE.C:22
 setupDxHFE.C:23
 setupDxHFE.C:24
 setupDxHFE.C:25
 setupDxHFE.C:26
 setupDxHFE.C:27
 setupDxHFE.C:28
 setupDxHFE.C:29
 setupDxHFE.C:30
 setupDxHFE.C:31
 setupDxHFE.C:32
 setupDxHFE.C:33
 setupDxHFE.C:34
 setupDxHFE.C:35
 setupDxHFE.C:36
 setupDxHFE.C:37
 setupDxHFE.C:38
 setupDxHFE.C:39
 setupDxHFE.C:40
 setupDxHFE.C:41
 setupDxHFE.C:42
 setupDxHFE.C:43
 setupDxHFE.C:44
 setupDxHFE.C:45
 setupDxHFE.C:46
 setupDxHFE.C:47
 setupDxHFE.C:48
 setupDxHFE.C:49
 setupDxHFE.C:50
 setupDxHFE.C:51
 setupDxHFE.C:52
 setupDxHFE.C:53
 setupDxHFE.C:54
 setupDxHFE.C:55
 setupDxHFE.C:56
 setupDxHFE.C:57
 setupDxHFE.C:58
 setupDxHFE.C:59
 setupDxHFE.C:60
 setupDxHFE.C:61
 setupDxHFE.C:62
 setupDxHFE.C:63
 setupDxHFE.C:64
 setupDxHFE.C:65
 setupDxHFE.C:66
 setupDxHFE.C:67
 setupDxHFE.C:68
 setupDxHFE.C:69
 setupDxHFE.C:70
 setupDxHFE.C:71
 setupDxHFE.C:72
 setupDxHFE.C:73
 setupDxHFE.C:74
 setupDxHFE.C:75
 setupDxHFE.C:76
 setupDxHFE.C:77
 setupDxHFE.C:78
 setupDxHFE.C:79
 setupDxHFE.C:80
 setupDxHFE.C:81
 setupDxHFE.C:82
 setupDxHFE.C:83
 setupDxHFE.C:84
 setupDxHFE.C:85
 setupDxHFE.C:86
 setupDxHFE.C:87
 setupDxHFE.C:88
 setupDxHFE.C:89
 setupDxHFE.C:90
 setupDxHFE.C:91
 setupDxHFE.C:92
 setupDxHFE.C:93
 setupDxHFE.C:94
 setupDxHFE.C:95
 setupDxHFE.C:96
 setupDxHFE.C:97
 setupDxHFE.C:98
 setupDxHFE.C:99
 setupDxHFE.C:100
 setupDxHFE.C:101
 setupDxHFE.C:102
 setupDxHFE.C:103
 setupDxHFE.C:104
 setupDxHFE.C:105
 setupDxHFE.C:106
 setupDxHFE.C:107
 setupDxHFE.C:108
 setupDxHFE.C:109
 setupDxHFE.C:110
 setupDxHFE.C:111
 setupDxHFE.C:112
 setupDxHFE.C:113
 setupDxHFE.C:114
 setupDxHFE.C:115
 setupDxHFE.C:116
 setupDxHFE.C:117
 setupDxHFE.C:118
 setupDxHFE.C:119
 setupDxHFE.C:120
 setupDxHFE.C:121
 setupDxHFE.C:122
 setupDxHFE.C:123
 setupDxHFE.C:124
 setupDxHFE.C:125
 setupDxHFE.C:126
 setupDxHFE.C:127
 setupDxHFE.C:128
 setupDxHFE.C:129
 setupDxHFE.C:130
 setupDxHFE.C:131
 setupDxHFE.C:132