<commit_before>// @(#)root/tree:$Name:  $:$Id: TFriendElement.cxx,v 1.1 2001/04/09 07:52:33 brun Exp $
// Author: <NAME>   11/02/97

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TFriendElement                                                       //
//                                                                      //
// A TFriendElement TF describes a TTree object TF in a file.           //
// When a TFriendElement TF is added to the the list of friends of an   //
// existing TTree T, any variable from TF can be referenced in a query  //
// to T.                                                                //
//                                                                      //
// To add a TFriendElement to an existing TTree T, do:                  //
//       T.AddFriend("friendTreename","friendTreeFilke");               //
//                                                                      //
//  see TTree::AddFriend for more information                           //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TTree.h"
#include "TFriendElement.h"
#include "TFile.h"

ClassImp(TFriendElement)

//______________________________________________________________________________
TFriendElement::TFriendElement(): TNamed()
{
//*-*-*-*-*-*Default constructor for a friend element*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*        =======================================

   fFile       = 0;
   fTree       = 0;
   fParentTree = 0;
}

//______________________________________________________________________________
TFriendElement::TFriendElement(TTree *tree, const char *treename, const char *filename)
    :TNamed(treename,filename)
{
//*-*-*-*-*-*-*-*-*-*-*-*-*Create a friend element*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ======================
//
// if treename is of the form "a=b", an alias called "a" is created for treename = "b"
// by default the alias name is the name of the tree.   

   fFile       = 0;
   fTree       = 0;
   fParentTree = tree;
   fTreeName   = treename;
   if (strchr(treename,'=')) {
      char *temp = Compress(treename);
      char *equal = strchr(temp,'=');
      *equal=0;
      fTreeName = equal+1;
      SetName(temp);
      delete [] temp;
   }
   
   Connect();
}

//______________________________________________________________________________
TFriendElement::~TFriendElement()
{

   DisConnect();
}

//_______________________________________________________________________
TTree *TFriendElement::Connect()
{
// Connect file and Tree

   GetFile();
   return GetTree();
}

//_______________________________________________________________________
TTree *TFriendElement::DisConnect()
{
// DisConnect file and Tree

   if (fTree) delete fTree;
   TDirectory *dir = fParentTree->GetDirectory();
   if (dir && fFile != dir->GetFile()) delete fFile;
   fFile = 0;
   fTree = 0;
   return 0;
}

//_______________________________________________________________________
TFile *TFriendElement::GetFile()
{
// return pointer to TFile containing this friend Tree

   if (fFile) return fFile;
   if (strlen(GetTitle())) fFile = new TFile(GetTitle());
   else {
      TDirectory *dir = fParentTree->GetDirectory();
      if (dir) fFile = dir->GetFile();
   }
   if (fFile && fFile->IsZombie()) {
      delete fFile;
      fFile = 0;
   }
   return fFile;
}

//_______________________________________________________________________
TTree *TFriendElement::GetTree()
{
// return pointer to friend Tree

   if (fTree) return fTree;
   if (!GetFile()) return 0;
   fTree = (TTree*)fFile->Get(GetTreeName());
   TDirectory *dir = fParentTree->GetDirectory();
   if (dir && dir != gDirectory) dir->cd();
   return fTree;
}

//_______________________________________________________________________
void TFriendElement::ls(Option_t *option) const
{
// List this friend element
//

   printf(" friend Tree: %s in file: %s\n",GetName(),GetTitle());
}
<commit_msg>Initialize fParentTree to the current Tree in the default constructor. This is necessary when reading a Tree with a list of friends.<commit_after>// @(#)root/tree:$Name:  $:$Id: TFriendElement.cxx,v 1.2 2001/04/10 16:34:51 brun Exp $
// Author: <NAME>   11/02/97

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TFriendElement                                                       //
//                                                                      //
// A TFriendElement TF describes a TTree object TF in a file.           //
// When a TFriendElement TF is added to the the list of friends of an   //
// existing TTree T, any variable from TF can be referenced in a query  //
// to T.                                                                //
//                                                                      //
// To add a TFriendElement to an existing TTree T, do:                  //
//       T.AddFriend("friendTreename","friendTreeFilke");               //
//                                                                      //
//  see TTree::AddFriend for more information                           //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TTree.h"
#include "TFriendElement.h"
#include "TFile.h"

R__EXTERN TTree *gTree;

ClassImp(TFriendElement)

//______________________________________________________________________________
TFriendElement::TFriendElement(): TNamed()
{
//*-*-*-*-*-*Default constructor for a friend element*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*        =======================================

   fFile       = 0;
   fTree       = 0;
   fParentTree = gTree;
}

//______________________________________________________________________________
TFriendElement::TFriendElement(TTree *tree, const char *treename, const char *filename)
    :TNamed(treename,filename)
{
//*-*-*-*-*-*-*-*-*-*-*-*-*Create a friend element*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ======================
//
// if treename is of the form "a=b", an alias called "a" is created for treename = "b"
// by default the alias name is the name of the tree.   

   fFile       = 0;
   fTree       = 0;
   fParentTree = tree;
   fTreeName   = treename;
   if (strchr(treename,'=')) {
      char *temp = Compress(treename);
      char *equal = strchr(temp,'=');
      *equal=0;
      fTreeName = equal+1;
      SetName(temp);
      delete [] temp;
   }
   
   Connect();
}

//______________________________________________________________________________
TFriendElement::~TFriendElement()
{

   DisConnect(); 
}

//_______________________________________________________________________
TTree *TFriendElement::Connect()
{
// Connect file and Tree

   GetFile();
   return GetTree();
}

//_______________________________________________________________________
TTree *TFriendElement::DisConnect()
{
// DisConnect file and Tree

   if (fTree) delete fTree;
   TDirectory *dir = fParentTree->GetDirectory();
   if (dir && fFile != dir->GetFile()) delete fFile;
   fFile = 0;
   fTree = 0;
   return 0;
}

//_______________________________________________________________________
TFile *TFriendElement::GetFile()
{
// return pointer to TFile containing this friend Tree

   if (fFile) return fFile;
   if (strlen(GetTitle())) fFile = new TFile(GetTitle());
   else {
      TDirectory *dir = fParentTree->GetDirectory();
      if (dir) fFile = dir->GetFile();
   }
   if (fFile && fFile->IsZombie()) {
      delete fFile;
      fFile = 0;
   }
   return fFile;
}

//_______________________________________________________________________
TTree *TFriendElement::GetTree()
{
// return pointer to friend Tree

   if (fTree) return fTree;
   if (!GetFile()) return 0;
   fTree = (TTree*)fFile->Get(GetTreeName());
   TDirectory *dir = fParentTree->GetDirectory();
   if (dir && dir != gDirectory) dir->cd();
   return fTree;
}

//_______________________________________________________________________
void TFriendElement::ls(Option_t *option) const
{
// List this friend element
//

   printf(" friend Tree: %s in file: %s\n",GetName(),GetTitle());
}

{'fraction_non_alphanumeric': 0.19076793070666526, 'fraction_numerical': 0.008767296926164571, 'mean_word_length': 1.7855251544571933, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5753085', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2183, 'n_words': 602}