<commit_before>/**
 * >> Testing Macro to fill FlatESDEvent from ALiESDEvent <<
 **
 * Primary Authors : <NAME>, <NAME>, <NAME>
 *
 * Usage:
 *  aliroot -b -l -q LoadLibs.C FlatESDConverter.C++
 *
 **************************************************************************/

#if !defined(__CINT__) || defined(__MAKECINT__)
#include "AliESDEvent.h"
#include "AliESD.h"
#include "AliESDfriend.h"
#include <TFile.h>
#include <TTree.h>
#include <TSystem.h>
#include "./AliFlatESDEvent.h"
#include "./AliFlatESDTrack.h"
#include "./AliFlatTPCCluster.h"
#include "./AliFlatExternalTrackParam.h"
#include "Riostream.h"
#endif   

void FlatESDConverter(const char* filename="AliESDs.root", Bool_t useESDFriends = kTRUE) {
  // -- Convert AliESDEvent to AliFlatESDEvent

  ofstream outFile("outFlatESD.dat", std::ifstream::binary | std::ifstream::out);
  //ofstream outFile("outFlatESD.dat");

  TFile *file    = new TFile(Form("%s", filename));
  TTree *esdTree = dynamic_cast<TTree*>(file->Get("esdTree"));
  
  // -- Connect ESD
  AliESDEvent *esd = new AliESDEvent;
  esd->ReadFromTree(esdTree);
  
  // -- Connect ESD friend
  AliESDfriend *esdFriend = NULL; 
  if (useESDFriends && !esdTree->FindBranch("ESDfriend.")) {
    esdTree->AddFriend("esdFriendTree", "AliESDfriends.root");
    esdTree->SetBranchStatus("ESDfriend.", 1);

    esdFriend = dynamic_cast<AliESDfriend*>((const_cast<AliESDEvent*>(esd))->FindListObject("AliESDfriend"));
    if (esdFriend)
      esdTree->SetBranchAddress("ESDfriend.", &esdFriend);
  } // if (!esdTree->FindBranch("ESDfriend.")) {
  
  AliFlatESDEvent *flatEsd = NULL;

  // -- Event Loop
  for (Int_t idxEvent = 1; idxEvent < 10; idxEvent++) {
    esdTree->GetEntry(idxEvent);
    // -- Book memory for AliFlatESDEvent
   // -- TEST >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Byte_t *mem = new Byte_t[AliFlatESDEvent::EstimateSize(esd, useESDFriends)];

    flatEsd = reinterpret_cast<AliFlatESDEvent*>(mem);    

    // -- Fill AliFlatESDEvent
    flatEsd->Fill(esd, useESDFriends);  

     Printf("TEST: Event %d || Tracks %d | FRIEND Tracks %d || estimated size %llu || sizeof(AliFlatESDEvent) %llu", 
	   idxEvent, esd->GetNumberOfTracks(), esdFriend->GetNumberOfTracks(), 
	   AliFlatESDEvent::EstimateSize(esd, useESDFriends), flatEsd->GetSize());

 #if 1
    AliFlatESDTrack *track = flatEsd->GetTracks();
    for (Int_t idxTrack = 0; idxTrack < flatEsd->GetNumberOfTracks(); ++idxTrack) {      
       AliESDtrack *esdTrack = esd->GetTrack(idxTrack);
       
       if (track && !esdTrack) {
	 Printf("ERROR THIS SHOULD NOT HAPPEN AT ALL !!! TRACK %d HAS NO ESD TRACK!!!", idxTrack);
	 return;
       }

      if (track) {
	AliFlatExternalTrackParam* exp1 = track->GetTrackParamCp();<commit_msg>switch in FlatESDConverter to use HLTesdtree<commit_after>/**
 * >> Testing Macro to fill FlatESDEvent from ALiESDEvent <<
 **
 * Primary Authors : <NAME>, <NAME>, <NAME>
 *
 * Usage:
 *  aliroot -b -l -q LoadLibs.C FlatESDConverter.C++
 *
 **************************************************************************/

#if !defined(__CINT__) || defined(__MAKECINT__)
#include "AliESDEvent.h"
#include "AliESD.h"
#include "AliESDfriend.h"
#include <TFile.h>
#include <TTree.h>
#include <TSystem.h>
#include "./AliFlatESDEvent.h"
#include "./AliFlatESDTrack.h"
#include "./AliFlatTPCCluster.h"
#include "./AliFlatExternalTrackParam.h"
#include "Riostream.h"
#endif   

void FlatESDConverter(const char* filename="AliESDs.root", Bool_t useESDFriends = kTRUE, Bool_t useHLTtree = kFALSE) {
  // -- Convert AliESDEvent to AliFlatESDEvent

  ofstream outFile("outFlatESD.dat", std::ifstream::binary | std::ifstream::out);
  //ofstream outFile("outFlatESD.dat");

  TFile *file    = new TFile(Form("%s", filename));
	
	TTree *esdTree = useHLTtree? dynamic_cast<TTree*>(file->Get("HLTesdTree")) : dynamic_cast<TTree*>(file->Get("esdTree"));

  
  // -- Connect ESD
  AliESDEvent *esd = new AliESDEvent;
  esd->ReadFromTree(esdTree);
  
  // -- Connect ESD friend
  AliESDfriend *esdFriend = NULL; 
  if (useESDFriends && !esdTree->FindBranch("ESDfriend.")) {
    esdTree->AddFriend("esdFriendTree", "AliESDfriends.root");
    esdTree->SetBranchStatus("ESDfriend.", 1);

    esdFriend = dynamic_cast<AliESDfriend*>((const_cast<AliESDEvent*>(esd))->FindListObject("AliESDfriend"));
    if (esdFriend)
      esdTree->SetBranchAddress("ESDfriend.", &esdFriend);
  } // if (!esdTree->FindBranch("ESDfriend.")) {
  
  AliFlatESDEvent *flatEsd = NULL;

  // -- Event Loop
  for (Int_t idxEvent = 0; idxEvent < esdTree->GetEntries(); idxEvent++) {
    esdTree->GetEntry(idxEvent);
    // -- Book memory for AliFlatESDEvent
   // -- TEST >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Byte_t *mem = new Byte_t[AliFlatESDEvent::EstimateSize(esd, useESDFriends)];

    flatEsd = reinterpret_cast<AliFlatESDEvent*>(mem);    

    // -- Fill AliFlatESDEvent
    flatEsd->Fill(esd, useESDFriends);  
 #if 0
     Printf("TEST: Event %d || Tracks %d | FRIEND Tracks %d || estimated size %llu || sizeof(AliFlatESDEvent) %llu", 
	   idxEvent, esd->GetNumberOfTracks(), esdFriend->GetNumberOfTracks(), 
	   AliFlatESDEvent::EstimateSize(esd, useESDFriends), flatEsd->GetSize());


    AliFlatESDTrack *track = flatEsd->GetTracks();
    for (Int_t idxTrack = 0; idxTrack < flatEsd->GetNumberOfTracks(); ++idxTrack) {      
       AliESDtrack *esdTrack = esd->GetTrack(idxTrack);
       
       if (track && !esdTrack) {
	 Printf("ERROR THIS SHOULD NOT HAPPEN AT ALL !!! TRACK %d HAS NO ESD TRACK!!!", idxTrack);
	 return;
       }

      if (track) {
	AliFlatExternalTrackParam* exp1 = track->GetTrackParamCp();
{'fraction_non_alphanumeric': 0.19897779344377864, 'fraction_numerical': 0.0021149101163200562, 'mean_word_length': 4.368968779564806, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 196, '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': '7194097', 'n_tokens_mistral': 2137, 'n_tokens_neox': 2023, 'n_words': 379}