<commit_before>/**************************************************************************
 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

//-------------------------------------------------------------------------
//     Event handler for ESD input 
//     Author: <NAME>, CERN
//-------------------------------------------------------------------------

#include <TTree.h>
#include <TChain.h>
#include <TFile.h>
#include <TArchiveFile.h>
#include <TObjArray.h>
#include <TSystem.h>
#include <TString.h>
#include <TObjString.h>
#include <TProcessID.h>
#include <TMap.h>

#include "AliESDInputHandler.h"
#include "AliESDEvent.h"
#include "AliESDfriend.h"
#include "AliVCuts.h"
#include "AliESD.h"
#include "AliRunTag.h"
#include "AliEventTag.h"
#include "AliLog.h"

ClassImp(AliESDInputHandler)

static Option_t *gESDDataType = "ESD";

//______________________________________________________________________________
AliESDInputHandler::AliESDInputHandler() :
  AliInputEventHandler(),
  fEvent(0x0),
  fFriend(0x0),
  fESDpid(0x0),
  fAnalysisType(0),
  fNEvents(0),
  fHLTEvent(0x0),
  fHLTTree(0x0),
  fUseHLT(kFALSE),
  fTagCutSumm(0x0),
  fUseTags(kFALSE),
  fChainT(0),
  fTreeT(0),
  fRunTag(0),
  fReadFriends(0),
  fFriendFileName("AliESDfriends.root")
{
  // default constructor
}

//______________________________________________________________________________
AliESDInputHandler::~AliESDInputHandler() 
{
  //  destructor
}

//______________________________________________________________________________
AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
    AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fESDpid(0x0), fAnalysisType(0),
    fNEvents(0),  fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0), fReadFriends(0), fFriendFileName("AliESDfriends.root")
{
    // Constructor
}

//______________________________________________________________________________
Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* opt)
{
    //
    // Initialisation necessary for each new tree 
    // 
    fAnalysisType = opt;
    fTree         = tree;
    
    if (!fTree) return kFALSE;
    fTree->GetEntry(0);
    

    if (!fEvent) fEvent = new AliESDEvent();
    fEvent->ReadFromTree(fTree);
    fNEvents = fTree->GetEntries();

    if (fMixingHandler) fMixingHandler->Init(tree,  opt);

    return kTRUE;
}

//______________________________________________________________________________
Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
{
    
    // Copy from old to new format if necessary
  static Bool_t called = kFALSE;
  if (!called && fEventCuts && IsUserCallSelectionMask())
     AliInfo(Form("The ESD input handler expects that the first task calls AliESDInputHandler::CheckSelectionMask() %s", fEventCuts->ClassName()));
  AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
  if (old) {
	((AliESDEvent*)fEvent)->CopyFromOldESD();
	old->Reset();
  }

  if (fHLTTree) {
      fHLTTree->GetEntry(entry);
  }
  
  fNewEvent = kTRUE;
  //
  // Event selection
  // 
  fIsSelectedResult = 0;
  if (fEventCuts && !IsUserCallSelectionMask())
      fIsSelectedResult = fEventCuts->GetSelectionMask((AliESDEvent*)fEvent); 
  //
  // Friends
  ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
  called = kTRUE;
  
  if (fMixingHandler) fMixingHandler->BeginEvent(entry);
      
  return kTRUE;
}

//______________________________________________________________________________
void AliESDInputHandler::CheckSelectionMask()
{
// This method can be called by a task only if IsUserCallSelectionMask is true.
   if (!fEventCuts || !IsUserCallSelectionMask()) return;
   fIsSelectedResult = fEventCuts->GetSelectionMask((AliESDEvent*)fEvent);
}
   
//______________________________________________________________________________
Bool_t  AliESDInputHandler::FinishEvent()
{
    // Finish the event 
  if(fEvent)fEvent->Reset();
  
  if (fMixingHandler) fMixingHandler->FinishEvent();

  return kTRUE;
} 

//______________________________________________________________________________
Bool_t AliESDInputHandler::Notify(const char* path)
{
    // Notify a directory change
    AliInfo(Form("Directory change %s \n", path));
    //
    // Handle the friends first
    //
    if (!fTree->FindBranch("ESDfriend.") && fReadFriends) {
      // Try to add ESDfriend. branch as friend
      TString esdTreeFName, esdFriendTreeFName;    
      esdTreeFName = (fTree->GetCurrentFile())->GetName();
      esdFriendTreeFName = esdTreeFName;
      esdFriendTreeFName.ReplaceAll("AliESDs.root", fFriendFileName.Data());
      // Added protection in case friend is not available (missing protection in TTree::LoadEvent)
      TFile *esdfriendFile = TFile::Open(fFriendFileName);
      if (esdfriendFile) {
        TTree* cTree = fTree->GetTree();
        if (!cTree) cTree = fTree;      
        cTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
        cTree->SetBranchStatus("ESDfriend.", 1);
        fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
        cTree->SetBranchAddress("ESDfriend.", &fFriend);
      } else {
        fFriend = 0;
      }    
    } 
    //
    //
    SwitchOffBranches();
    SwitchOnBranches();
    fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
    //
    if (fUseHLT) {
	// Get HLTesdTree from current file
	TTree* cTree = fTree;
	if (fTree->GetTree()) cTree = fTree->GetTree();
	TFile* cFile = cTree->GetCurrentFile();
	cFile->GetObject("HLTesdTree", fHLTTree);
	
	if (fHLTTree) {
	  if (!fHLTEvent) fHLTEvent = new AliESDEvent();
	  fHLTEvent->ReadFromTree(fHLTTree);
	}
    }
<commit_msg>Corrected a correction in Notify that screwed reading of friends...<commit_after>/**************************************************************************
 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

//-------------------------------------------------------------------------
//     Event handler for ESD input 
//     Author: <NAME>, CERN
//-------------------------------------------------------------------------

#include <TTree.h>
#include <TChain.h>
#include <TFile.h>
#include <TArchiveFile.h>
#include <TObjArray.h>
#include <TSystem.h>
#include <TString.h>
#include <TObjString.h>
#include <TProcessID.h>
#include <TMap.h>

#include "AliESDInputHandler.h"
#include "AliESDEvent.h"
#include "AliESDfriend.h"
#include "AliVCuts.h"
#include "AliESD.h"
#include "AliRunTag.h"
#include "AliEventTag.h"
#include "AliLog.h"

ClassImp(AliESDInputHandler)

static Option_t *gESDDataType = "ESD";

//______________________________________________________________________________
AliESDInputHandler::AliESDInputHandler() :
  AliInputEventHandler(),
  fEvent(0x0),
  fFriend(0x0),
  fESDpid(0x0),
  fAnalysisType(0),
  fNEvents(0),
  fHLTEvent(0x0),
  fHLTTree(0x0),
  fUseHLT(kFALSE),
  fTagCutSumm(0x0),
  fUseTags(kFALSE),
  fChainT(0),
  fTreeT(0),
  fRunTag(0),
  fReadFriends(0),
  fFriendFileName("AliESDfriends.root")
{
  // default constructor
}

//______________________________________________________________________________
AliESDInputHandler::~AliESDInputHandler() 
{
  //  destructor
}

//______________________________________________________________________________
AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
    AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fESDpid(0x0), fAnalysisType(0),
    fNEvents(0),  fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0), fReadFriends(0), fFriendFileName("AliESDfriends.root")
{
    // Constructor
}

//______________________________________________________________________________
Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* opt)
{
    //
    // Initialisation necessary for each new tree 
    // 
    fAnalysisType = opt;
    fTree         = tree;
    
    if (!fTree) return kFALSE;
    fTree->GetEntry(0);
    

    if (!fEvent) fEvent = new AliESDEvent();
    fEvent->ReadFromTree(fTree);
    fNEvents = fTree->GetEntries();

    if (fMixingHandler) fMixingHandler->Init(tree,  opt);

    return kTRUE;
}

//______________________________________________________________________________
Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
{
    
    // Copy from old to new format if necessary
  static Bool_t called = kFALSE;
  if (!called && fEventCuts && IsUserCallSelectionMask())
     AliInfo(Form("The ESD input handler expects that the first task calls AliESDInputHandler::CheckSelectionMask() %s", fEventCuts->ClassName()));
  AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
  if (old) {
	((AliESDEvent*)fEvent)->CopyFromOldESD();
	old->Reset();
  }

  if (fHLTTree) {
      fHLTTree->GetEntry(entry);
  }
  
  fNewEvent = kTRUE;
  //
  // Event selection
  // 
  fIsSelectedResult = 0;
  if (fEventCuts && !IsUserCallSelectionMask())
      fIsSelectedResult = fEventCuts->GetSelectionMask((AliESDEvent*)fEvent); 
  //
  // Friends
  ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
  called = kTRUE;
  
  if (fMixingHandler) fMixingHandler->BeginEvent(entry);
      
  return kTRUE;
}

//______________________________________________________________________________
void AliESDInputHandler::CheckSelectionMask()
{
// This method can be called by a task only if IsUserCallSelectionMask is true.
   if (!fEventCuts || !IsUserCallSelectionMask()) return;
   fIsSelectedResult = fEventCuts->GetSelectionMask((AliESDEvent*)fEvent);
}
   
//______________________________________________________________________________
Bool_t  AliESDInputHandler::FinishEvent()
{
    // Finish the event 
  if(fEvent)fEvent->Reset();
  
  if (fMixingHandler) fMixingHandler->FinishEvent();

  return kTRUE;
} 

//______________________________________________________________________________
Bool_t AliESDInputHandler::Notify(const char* path)
{
    // Notify a directory change
    AliInfo(Form("Directory change %s \n", path));
    //
    // Handle the friends first
    //
    if (!fTree->FindBranch("ESDfriend.") && fReadFriends) {
      // Try to add ESDfriend. branch as friend
      TString esdTreeFName, esdFriendTreeFName;    
      esdTreeFName = (fTree->GetCurrentFile())->GetName();
      esdFriendTreeFName = esdTreeFName;
      esdFriendTreeFName.ReplaceAll("AliESDs.root", fFriendFileName.Data());
      TTree* cTree = fTree->GetTree();
      if (!cTree) cTree = fTree;      
      cTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
      cTree->SetBranchStatus("ESDfriend.", 1);
      fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
      if (fFriend) cTree->SetBranchAddress("ESDfriend.", &fFriend);
    } 
    //
    //
    SwitchOffBranches();
    SwitchOnBranches();
    fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
    //
    if (fUseHLT) {
	// Get HLTesdTree from current file
	TTree* cTree = fTree;
	if (fTree->GetTree()) cTree = fTree->GetTree();
	TFile* cFile = cTree->GetCurrentFile();
	cFile->GetObject("HLTesdTree", fHLTTree);
	
	if (fHLTTree) {
	  if (!fHLTEvent) fHLTEvent = new AliESDEvent();
	  fHLTEvent->ReadFromTree(fHLTTree);
	}
    }

{'fraction_non_alphanumeric': 0.15717991759499467, 'fraction_numerical': 0.007553792156264306, 'mean_word_length': 3.3719146097398265, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5367495', 'n_tokens_mistral': 3946, 'n_tokens_neox': 3855, 'n_words': 829}