//_______________________________| CreateAlienHandler |________________________________
AliAnalysisGrid* CreateAlienHandler()
{
    
    AliAnalysisAlien *Plugin = new AliAnalysisAlien();
    Plugin->SetRunMode(fPluginMode.Data());
    Plugin->SetUser(fUsername.Data());
    Plugin->SetAPIVersion("V1.1x");
    Plugin->SetROOTVersion("v5-34-30-alice-12");
    Plugin->SetAliROOTVersion("v5-07-20-4");
    Plugin->SetAliPhysicsVersion("vAN-20160129-1");
    Plugin->SetNtestFiles(1);
    Plugin->SetFileForTestMode(TestFilesWPlugin.Data());
    
    // Set data search pattern for DATA grid Mode
    Plugin->SetGridDataDir("/alice/sim/2013/LHC13b2_efix_p1"); // specify MC sample
    if(readAOD) Plugin->SetDataPattern("AOD/*AliAOD.root");// specify AOD set
    else Plugin->SetDataPattern("*/AliESDs.root");
    
    Int_t totruns=0;
    //gROOT->LoadMacro("$ALICE_PHYSICS/PWGHF/vertexingHF/AddGoodRuns.C");
    gROOT->LoadMacro("AddGoodRuns.C");
    totruns += AddGoodRuns(Plugin,"LHC13b","LHC13b2_efix_p1"); //Set accordingly
    Plugin->SetNrunsPerMaster(totruns);
    
    Plugin->SetGridWorkingDir("SingleTrkEff/LHC13b2_efix_p1/16Feb2016/");
    Plugin->SetGridOutputDir("out");
    
    Plugin->SetExecutable("STE16Feb2016.sh");
    Plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_PHYSICS -I$ALICE_PHYSICS/include -I$ALICE_PHYSICS/ITS -I$ALICE_PHYSICS/TPC -I$ALICE_PHYSICS/CONTAINERS -I$ALICE_PHYSICS/STEER/STEER -I$ALICE_PHYSICS/STEER/STEERBase -I$ALICE_PHYSICS/STEER/ESD -I$ALICE_PHYSICS/STEER/AOD -I$ALICE_PHYSICS/TRD -I$ALICE_PHYSICS/macros -I$ALICE_PHYSICS/ANALYSIS -I$ALICE_PHYSICS/OADB -g");
    
    Plugin->SetSplitMaxInputFileNumber(5);
    Plugin->SetDefaultOutputs(kTRUE);
    Plugin->SetMergeViaJDL(kTRUE); // Merge Via JDL
    Plugin->SetOneStageMerging(kFALSE);
    Plugin->SetMaxMergeStages(2);
    Plugin->SetAnalysisMacro("STE16Feb2016.C");
    Plugin->SetJDLName("STE16Feb2016.jdl");
    
    return Plugin;
}
void setupSingleTask(const char* localAodDirectory, int nFiles, 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/PWGGA/PHOSTasks/PHOS_PbPb/macros/single-task/AddGoodRuns.C");
    int nruns=AddGoodRuns(alienHandler, lhcPeriod, mcProd);
    if (nruns<=0) {
      ::Error("setupSingleTask.C", Form("can not find any good runs for period %s", lhcPeriod));
      return;
    }
    gDirectory->Add(alienHandler);
    ::Info("setupSingleTask.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");
    gROOT->LoadMacro("$ALICE_ROOT/PWGGA/PHOSTasks/PHOS_PbPb/macros/single-task/MakeAODInputChain.C");
    TChain* chain = 0;
    chain = MakeAODInputChain(localAodDirectory, nFiles);
    // TString aodPathName(localAodDirectory);
    // if (!aodPathName.EndsWith("/")) aodPathName+="/";
    // aodPathName+="AliAOD.root";
    TChain* chain;
    // 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("setupSingleTask.C", Form("make chain from single chunk %s", aodPathName));
    //   chain = MakeAODInputChain(localAodDirectory ,1, -1);
    // } else {
    //   // Assume several folders containing different AODs. 
    //   // The AODs need to be in folders named 1, 2,...
    //   ::Info("setupSingleTask.C", Form("make chain from directory %s", localAodDirectory));
    //   chain=MakeAODInputChain(localAodDirectory, nFiles);
    // }
    ::Info("setupSingleTask.C", Form("local AOD chain: %d entries", chain->GetEntries()));
  }
}