#ifndef ROOT_TTree
# include <TTree.h>
#endif 
#ifndef __UTILITY__
# include <utility>
#endif
#ifndef __STRING__
# include <string>
#endif
#ifndef __VECTOR__
# include <vector>
#endif

class MixTree : public TTree 
{
private:
  TTree* fTree;
  typedef std::pair<std::string*, void*> branch_info_type;
  typedef std::vector<branch_info_type> branch_info_list;
  branch_info_list fList;
public: 
  MixTree(TTree* tree) : fTree(tree) {}
  const Char_t* GetName() const { return fTree->GetName(); }
  Int_t         GetEntry(Long64_t entry=0, Int_t getall=0);
  void          SetBranchAddress(const char *bname,void *add);
};


//____________________________________________________________________
Int_t
MixTree::GetEntry(Long64_t entry, Int_t getall) 
{
  // SetBranchStatus("*", 0);
  branch_info_list keep;
  for (branch_info_list::iterator i = fList.begin(); 
       i != fList.end(); ++i) {
    std::string* name = (*i).first;
    void* add         = (*i).second;
    TBranch* b = fTree->GetBranch(name->c_str());
    if (!b) continue;
    void* olda = b->GetAddress();
    keep.push_back(branch_info_type(name, olda));
    fTree->SetBranchAddress(name->c_str(), add);
  }
  Int_t ret = fTree->GetEntry(entry, getall);
  for (branch_info_list::iterator i = keep.begin(); 
       i != keep.end(); ++i) {
    std::string* name = (*i).first;
    void* add         = (*i).second;
    TBranch* b = fTree->GetBranch(name->c_str());
    if (!b) continue;
    fTree->SetBranchAddress(name->c_str(), add);
  }
  // SetBranchStatus("*", 1);
  return ret;
}

//____________________________________________________________________
void         
MixTree::SetBranchAddress(const char *bname,void *add) 
{
  std::string* name = new std::string(bname);
  fList.push_back(branch_info_type(name, add));
}

//
// EOF
//

