<commit_before>///
/// \file PWGCF/FEMTOSCOPY/macros/Train/PionPionFemto/AddNuTaskPionPionRoot6.C
/// \author <NAME>, Ohio State University, <EMAIL>
///

#include <TROOT.h>

#include <TString.h>
#include <TList.h>
#include <TObjArray.h>
#include <TObjString.h>

#include <AliAnalysisManager.h>

#include "AliAnalysisTaskFemtoNu.h"


/// \class MacroCfg
/// \brief All parameters for this macro
///
struct MacroCfg : public TNamed {

  TString macro = "%%/ConfigNuFemtoAnalysisR6.C",
          auto_directory = "$ALICE_PHYSICS/PWGCF/FEMTOSCOPY/macros/Train/PionPionFemto",
          output_filename,
          output_container = "PWG2FEMTO",
          subwagon_array = "",
          subwagon_type = "centrality";

  MacroCfg()
    : TNamed("cfg", "MacroCfg")
    , output_filename(AliAnalysisManager::GetAnalysisManager()->GetCommonFileName())
    {}

  TString GetFilename()
    {
      return (output_container == "")
           ? output_filename
           : TString::Format("%s:%s", output_filename.Data(), output_container.Data());
    }
};


/// \brief Adds an AliAnalysisTaskFemtoNu analysis object, constructed
///        with parameters provided, to the global AliAnalysisManager.
///
/// This macro creates and returns an :class:`AliAnalysisTaskFemto` object.
/// The task object is given a macro
/// is given the config macro "Train/PionPionFemto/ConfigFemtoAnalysis.C"
/// which is run to create the analysis objects.
/// This is fixed (for now), and if an alternative is required, you
/// should use the general AddTaskFemto.C macro.
///
/// Subwagons are supported, the name of which will be appended to
/// the task name.
/// The task name by default is "TaskPionPionFemto" which cannot be
/// changed.
///
/// The output container name is fixed at the standard "femtolist".
///
/// \param configuration
///     A string containing commands to execute, separated by semicolons.
///     Assign the old parameters using this command.
///     Single quotes are turned to double quotes.
///
///     * macro: Path to the FemtoConfig macro to load; "%%" is
///          expaneded to directory containing this file.
///     * output_filename: Name of the output file to produce.
///         Default generated by AliAnalysisManager::GetCommonFileName()
///     * output_container: Name of top-level ROOT directory in the output file.
///         Default is the classic 'PWG2FEMTO'.
///     * container: Name of the AliAnalysis container.
///     * task_name: Name of the AliAnalysisTask - May need to be unique...
///     * verbose: Task created in verbose mode
///
/// \param params
///     A string forwarded to the ConfigFemtoAnalysis macro for parsing.
///     This string is wrapped in double-quotes so escaping some to
///     ensure results is a string is unneccessary.
///
/// \param subwagon_suffix
///     If this macro is run in a train with subwagons, this will be
///     set with the identifier.
///
AliAnalysisTask* AddNuTaskPionPionRoot6(TString container,
                                        TString configuration,
                                        TString params,
                                        TString subwagon_suffix)
{
  std::cout << "\n\n============== AddNuTaskPionPion (ROOT6 Version) ===============\n";

  // Get the global analysis manager
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    Error("AddNuTaskPionPion", "Could not get the global AliAnalysisManager.");
    return nullptr;
  }

  MacroCfg cfg;

  bool verbose = kFALSE;

  TObjArray* lines = configuration.Tokenize("\n;");

  TIter next_line(lines);
  TObject *line_obj = nullptr;

  gDirectory->Add(&cfg);

  while ((line_obj = next_line())) {
    TObjString *s = static_cast<TObjString*>(line_obj);
    TString cmd = s->String().Strip(TString::kBoth, ' ');
    if (cmd.IsWhitespace()) {
      continue;
    }

    cmd.ReplaceAll("'", '"');

    cmd = "static_cast<MacroCfg*>(cfg)->" + cmd + ";";

    std::cout << "running `" << cmd  << "`\n";
    gROOT->ProcessLineFast(cmd);
  }

  gDirectory->Remove(&cfg);

  // Replace %% with this directory for convenience
  cfg.macro.ReplaceAll("%%", cfg.auto_directory);

  // Dealing with subwagons
  if (!subwagon_suffix.IsWhitespace()) {
    Int_t index = subwagon_suffix.Atoi();
    TObjArray *values = cfg.subwagon_array.Tokenize(",");
    TIter next_value(values);
    if (values->GetEntries() < index) {
      std::cerr << "Could not use subwagon-index " << index << " in subwagon_array of only " << values->GetEntries() << " entries\n";
      return nullptr;
    }
    for (int i=0; i<index; ++i) {
      next_value();<commit_msg>FemtoAnalysisPion - Update train-macro to tokenize using ~ and compile config-macro by default<commit_after>///
/// \file PWGCF/FEMTOSCOPY/macros/Train/PionPionFemto/AddNuTaskPionPionRoot6.C
/// \author <NAME>, Ohio State University, <EMAIL>
///

#include <TROOT.h>

#include <TString.h>
#include <TList.h>
#include <TObjArray.h>
#include <TObjString.h>

#include <AliAnalysisManager.h>

#include "AliAnalysisTaskFemtoNu.h"


/// \class MacroCfg
/// \brief All parameters for this macro
///
struct MacroCfg : public TNamed {

  TString macro = "%%/ConfigNuFemtoAnalysisR6.C+",
          auto_directory = "$ALICE_PHYSICS/PWGCF/FEMTOSCOPY/macros/Train/PionPionFemto",
          output_filename,
          output_container = "PWG2FEMTO",
          subwagon_array = "",
          subwagon_type = "centrality";

  MacroCfg()
    : TNamed("cfg", "MacroCfg")
    , output_filename(AliAnalysisManager::GetAnalysisManager()->GetCommonFileName())
    {}

  TString GetFilename()
    {
      return (output_container == "")
           ? output_filename
           : TString::Format("%s:%s", output_filename.Data(), output_container.Data());
    }
};


/// \brief Adds an AliAnalysisTaskFemtoNu analysis object, constructed
///        with parameters provided, to the global AliAnalysisManager.
///
/// This macro creates and returns an :class:`AliAnalysisTaskFemto` object.
/// The task object is given a macro
/// is given the config macro "Train/PionPionFemto/ConfigFemtoAnalysis.C"
/// which is run to create the analysis objects.
/// This is fixed (for now), and if an alternative is required, you
/// should use the general AddTaskFemto.C macro.
///
/// Subwagons are supported, the name of which will be appended to
/// the task name.
/// The task name by default is "TaskPionPionFemto" which cannot be
/// changed.
///
/// The output container name is fixed at the standard "femtolist".
///
/// \param configuration
///     A string containing commands to execute, separated by semicolons.
///     Assign the old parameters using this command.
///     Single quotes are turned to double quotes.
///
///     * macro: Path to the FemtoConfig macro to load; "%%" is
///          expaneded to directory containing this file.
///     * output_filename: Name of the output file to produce.
///         Default generated by AliAnalysisManager::GetCommonFileName()
///     * output_container: Name of top-level ROOT directory in the output file.
///         Default is the classic 'PWG2FEMTO'.
///     * container: Name of the AliAnalysis container.
///     * task_name: Name of the AliAnalysisTask - May need to be unique...
///     * verbose: Task created in verbose mode
///
/// \param params
///     A string forwarded to the ConfigFemtoAnalysis macro for parsing.
///     This string is wrapped in double-quotes so escaping some to
///     ensure results is a string is unneccessary.
///
/// \param subwagon_suffix
///     If this macro is run in a train with subwagons, this will be
///     set with the identifier.
///
AliAnalysisTask* AddNuTaskPionPionRoot6(TString container,
                                        TString configuration,
                                        TString params,
                                        TString subwagon_suffix)
{
  std::cout << "\n\n============== AddNuTaskPionPion (ROOT6 Version) ===============\n";

  // Get the global analysis manager
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    Error("AddNuTaskPionPion", "Could not get the global AliAnalysisManager.");
    return nullptr;
  }

  MacroCfg cfg;

  bool verbose = kFALSE;

  TObjArray* lines = configuration.Tokenize("\n;");

  TIter next_line(lines);
  TObject *line_obj = nullptr;

  gDirectory->Add(&cfg);

  while ((line_obj = next_line())) {
    TObjString *s = static_cast<TObjString*>(line_obj);
    TString cmd = s->String().Strip(TString::kBoth, ' ');
    if (cmd.IsWhitespace()) {
      continue;
    }

    cmd.ReplaceAll("'", '"');

    cmd = "static_cast<MacroCfg*>(cfg)->" + cmd + ";";

    std::cout << "running `" << cmd  << "`\n";
    gROOT->ProcessLineFast(cmd);
  }

  gDirectory->Remove(&cfg);

  // Replace %% with this directory for convenience
  cfg.macro.ReplaceAll("%%", cfg.auto_directory);

  // Dealing with subwagons
  if (!subwagon_suffix.IsWhitespace()) {
    Int_t index = subwagon_suffix.Atoi();
    TObjArray *values = cfg.subwagon_array.Tokenize("~");
    TIter next_value(values);
    if (values->GetEntries() < index) {
      std::cerr << "Could not use subwagon-index " << index << " in subwagon_array of only " << values->GetEntries() << " entries\n";
      return nullptr;
    }
    for (int i=0; i<index; ++i) {
      next_value();
{'fraction_non_alphanumeric': 0.1356928999144568, 'fraction_numerical': 0.0014970059880239522, 'mean_word_length': 2.814437194127243, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2769947', 'n_tokens_mistral': 2867, 'n_tokens_neox': 2769, 'n_words': 819}