<commit_before>/* $Id$ */

// Helper macros can be found in this file
// A set of them can be used to connect to proof and execute selectors.

TVirtualProof* connectProof(const char* proofServer)
{
  TVirtualProof* proof = TProof::Open(proofServer);

  if (!proof)
  {
    printf("ERROR: PROOF connection not established.\n");
    return 0;
  }

  // enable the new packetizer
  //proof->AddInput(new TNamed("PROOF_Packetizer", "TPacketizerProgressive"));

  proof->ClearInput();

  return proof;
}

Bool_t prepareQuery(TString libraries, TString packages, Int_t useAliRoot)
{
  // if not proof load libraries
  if (!gProof)
  {
    TObjArray* librariesList = libraries.Tokenize(";");
    for (Int_t i=0; i<librariesList->GetEntries(); ++i)
    {
      TObjString* str = dynamic_cast<TObjString*> (librariesList->At(i));
      if (!str)
        continue;

      printf("Loading %s...", str->String().Data());
      Int_t result = CheckLoadLibrary(str->String());
      if (result < 0)
      {
        printf("failed\n");
        //return kFALSE;
      }
      else
        printf("succeeded\n");
    }
  }
  else
  {
    if (useAliRoot > 0)
      ProofEnableAliRoot(useAliRoot);

    TObjArray* packagesList = packages.Tokenize(";");
    for (Int_t i=0; i<packagesList->GetEntries(); ++i)
    {
      TObjString* str = dynamic_cast<TObjString*> (packagesList->At(i));
      if (!str)
        continue;

      /*if (!EnablePackageLocal(str->String()))
      {
        printf("Loading of package %s locally failed\n", str->String().Data());
        return kFALSE;
      }*/

      if (gProof->UploadPackage(Form("%s.par", str->String().Data())))
      {
        printf("Uploading of package %s failed\n", str->String().Data());
        return kFALSE;
      }

      if (gProof->EnablePackage(str->String()))
      {
        printf("Loading of package %s failed\n", str->String().Data());
        return kFALSE;
      }
    }
 }

 return kTRUE;
}

Int_t executeQuery(TChain* chain, TList* inputList, TString selectorName, const char* option = "", Long64_t entries = TChain::kBigNumber)
{
  if (!gProof)
    chain->GetUserInfo()->AddAll(inputList);
  else
  {
    for (Int_t i=0; i<inputList->GetEntries(); ++i)
      gProof->AddInput(inputList->At(i));
  }

  TStopwatch timer;
  timer.Start();

  Long64_t result = -1;

  if (gProof)
    result = chain->MakeTDSet()->Process(selectorName, option, entries);
  else
    result = chain->Process(selectorName, option, entries);

  if (result < 0)
    printf("ERROR: Executing process failed with %d.\n", result);

  timer.Stop();
  timer.Print();

  return result;
}

void ProofEnableAliRoot(Int_t aliroot)
{
  // enables a locally deployed AliRoot in a PROOF cluster

  /* executes the following commands on each node:
     gSystem->Setenv("ALICE_ROOT", "/home/alicecaf/ALICE/aliroot-head")
     gSystem->AddIncludePath("/home/alicecaf/ALICE/aliroot-head/include");
     gSystem->SetDynamicPath(Form("%s:%s", gSystem->GetDynamicPath(), "/home/alicecaf/ALICE/aliroot-head/lib/tgt_linux"))
     gSystem->Load("libMinuit");
     gROOT->Macro("$ALICE_ROOT/macros/loadlibs.C");<commit_msg>moving to new PROOF api<commit_after>/* $Id$ */

// Helper macros can be found in this file
// A set of them can be used to connect to proof and execute selectors.

TProof* connectProof(const char* proofServer)
{
  TProof* proof = TProof::Open(proofServer);

  if (!proof)
  {
    printf("ERROR: PROOF connection not established.\n");
    return 0;
  }

  // enable the new packetizer
  //proof->AddInput(new TNamed("PROOF_Packetizer", "TPacketizerProgressive"));

  proof->ClearInput();

  return proof;
}

Bool_t prepareQuery(TString libraries, TString packages, Int_t useAliRoot)
{
  // if not proof load libraries
  if (!gProof)
  {
    TObjArray* librariesList = libraries.Tokenize(";");
    for (Int_t i=0; i<librariesList->GetEntries(); ++i)
    {
      TObjString* str = dynamic_cast<TObjString*> (librariesList->At(i));
      if (!str)
        continue;

      printf("Loading %s...", str->String().Data());
      Int_t result = CheckLoadLibrary(str->String());
      if (result < 0)
      {
        printf("failed\n");
        //return kFALSE;
      }
      else
        printf("succeeded\n");
    }
  }
  else
  {
    if (useAliRoot > 0)
      ProofEnableAliRoot(useAliRoot);

    TObjArray* packagesList = packages.Tokenize(";");
    for (Int_t i=0; i<packagesList->GetEntries(); ++i)
    {
      TObjString* str = dynamic_cast<TObjString*> (packagesList->At(i));
      if (!str)
        continue;

      /*if (!EnablePackageLocal(str->String()))
      {
        printf("Loading of package %s locally failed\n", str->String().Data());
        return kFALSE;
      }*/

      if (gProof->UploadPackage(Form("%s.par", str->String().Data())))
      {
        printf("Uploading of package %s failed\n", str->String().Data());
        return kFALSE;
      }

      if (gProof->EnablePackage(str->String()))
      {
        printf("Loading of package %s failed\n", str->String().Data());
        return kFALSE;
      }
    }
 }

 return kTRUE;
}

Int_t executeQuery(TChain* chain, TList* inputList, TString selectorName, const char* option = "", Long64_t entries = TChain::kBigNumber)
{
  if (!gProof)
    chain->GetUserInfo()->AddAll(inputList);
  else
  {
    for (Int_t i=0; i<inputList->GetEntries(); ++i)
      gProof->AddInput(inputList->At(i));
  }

  TStopwatch timer;
  timer.Start();

  Long64_t result = -1;

  if (gProof)
  {
    chain->SetProof();
    result = chain->Process(selectorName, option, entries);
  }
  else
    result = chain->Process(selectorName, option, entries);

  if (result < 0)
    printf("ERROR: Executing process failed with %d.\n", result);

  timer.Stop();
  timer.Print();

  return result;
}

void ProofEnableAliRoot(Int_t aliroot)
{
  // enables a locally deployed AliRoot in a PROOF cluster

  /* executes the following commands on each node:
     gSystem->Setenv("ALICE_ROOT", "/home/alicecaf/ALICE/aliroot-head")
     gSystem->AddIncludePath("/home/alicecaf/ALICE/aliroot-head/include");
     gSystem->SetDynamicPath(Form("%s:%s", gSystem->GetDynamicPath(), "/home/alicecaf/ALICE/aliroot-head/lib/tgt_linux"))
     gSystem->Load("libMinuit");
     gROOT->Macro("$ALICE_ROOT/macros/loadlibs.C");
{'fraction_non_alphanumeric': 0.1560905612244898, 'fraction_numerical': 0.003826530612244898, 'mean_word_length': 3.105366492146597, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5584885', 'n_tokens_mistral': 2094, 'n_tokens_neox': 2041, 'n_words': 460}