ROOT logo
// @(#)root/cont:$Id: TSelectorList.cxx 20882 2007-11-19 11:31:26Z rdm $
// Author: Fons Rademakers   10/08/95

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

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TSelectorList                                                        //
//                                                                      //
// A TList derived class that makes sure that objects added to it       //
// are not linked to the currently open file (like histograms,          //
// eventlists and trees). Also it makes sure the name of the added      //
// object is unique. This class is used in the TSelector for the        //
// output list.                                                         //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TSelectorList.h"
#include "TMethodCall.h"


ClassImp(TSelectorList)

//______________________________________________________________________________
Bool_t TSelectorList::UnsetDirectory(TObject *obj)
{
   // If the class of obj has the SetDirectory(TDirectory*) method
   // call it to unset the directory assiciation. The objects in the
   // selector list or owned by the list and not by the directory that
   // was active when they were created. Returns true in case of success.

   if (!obj || !obj->IsA())
      return kFALSE;

   TMethodCall callEnv;
   callEnv.InitWithPrototype(obj->IsA(), "SetDirectory", "TDirectory*");
   if (!callEnv.IsValid())
      return kFALSE;

   callEnv.SetParam((Long_t) 0);
   callEnv.Execute(obj);

   return kTRUE;
}

//______________________________________________________________________________
Bool_t TSelectorList::CheckDuplicateName(TObject *obj)
{
   // Check for duplicate object names in the list. If an object with
   // the same name is added then the merge function will fail that will
   // look up objects in different output lists by name. Returns true
   // in case name is unique.

   if (!obj)
      return kFALSE;

   TObject *org = FindObject(obj->GetName());
   if (org == obj) {
      Error("CheckDuplicateName","object with name: %s already in the list",obj->GetName());
      return kFALSE;
   }

   if (org) {
      Error("CheckDuplicateName","an object with the same name: %s is already in the list",obj->GetName());
      return kFALSE;
   }

   return kTRUE;
}

//______________________________________________________________________________
void TSelectorList::AddFirst(TObject *obj)
{
   // Add at the start of the list

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddFirst(obj);
}

//______________________________________________________________________________
void TSelectorList::AddFirst(TObject *obj, Option_t *opt)
{
   // Add at the start of the list

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddFirst(obj, opt);
}

//______________________________________________________________________________
void TSelectorList::AddLast(TObject *obj)
{
   // Add at the end of the list

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddLast(obj);
}

//______________________________________________________________________________
void TSelectorList::AddLast(TObject *obj, Option_t *opt)
{
   // Add at the end of the list

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddLast(obj, opt);
}

//______________________________________________________________________________
void TSelectorList::AddAt(TObject *obj, Int_t idx)
{
   // Add to the list.

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddAt(obj, idx);
}

//______________________________________________________________________________
void TSelectorList::AddAfter(const TObject *after, TObject *obj)
{
   // Add to the list.

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddAfter(after, obj);
}

//______________________________________________________________________________
void TSelectorList::AddAfter(TObjLink *after, TObject *obj)
{
   // Add to the list.

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddAfter(after, obj);
}

//______________________________________________________________________________
void TSelectorList::AddBefore(const TObject *before, TObject *obj)
{
   // Add to the list.

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddBefore(before, obj);
}

//______________________________________________________________________________
void TSelectorList::AddBefore(TObjLink *before, TObject *obj)
{
   // Add to the list.

   UnsetDirectory(obj);
   if (CheckDuplicateName(obj))
      TList::AddBefore(before, obj);
}
 TSelectorList.cxx:1
 TSelectorList.cxx:2
 TSelectorList.cxx:3
 TSelectorList.cxx:4
 TSelectorList.cxx:5
 TSelectorList.cxx:6
 TSelectorList.cxx:7
 TSelectorList.cxx:8
 TSelectorList.cxx:9
 TSelectorList.cxx:10
 TSelectorList.cxx:11
 TSelectorList.cxx:12
 TSelectorList.cxx:13
 TSelectorList.cxx:14
 TSelectorList.cxx:15
 TSelectorList.cxx:16
 TSelectorList.cxx:17
 TSelectorList.cxx:18
 TSelectorList.cxx:19
 TSelectorList.cxx:20
 TSelectorList.cxx:21
 TSelectorList.cxx:22
 TSelectorList.cxx:23
 TSelectorList.cxx:24
 TSelectorList.cxx:25
 TSelectorList.cxx:26
 TSelectorList.cxx:27
 TSelectorList.cxx:28
 TSelectorList.cxx:29
 TSelectorList.cxx:30
 TSelectorList.cxx:31
 TSelectorList.cxx:32
 TSelectorList.cxx:33
 TSelectorList.cxx:34
 TSelectorList.cxx:35
 TSelectorList.cxx:36
 TSelectorList.cxx:37
 TSelectorList.cxx:38
 TSelectorList.cxx:39
 TSelectorList.cxx:40
 TSelectorList.cxx:41
 TSelectorList.cxx:42
 TSelectorList.cxx:43
 TSelectorList.cxx:44
 TSelectorList.cxx:45
 TSelectorList.cxx:46
 TSelectorList.cxx:47
 TSelectorList.cxx:48
 TSelectorList.cxx:49
 TSelectorList.cxx:50
 TSelectorList.cxx:51
 TSelectorList.cxx:52
 TSelectorList.cxx:53
 TSelectorList.cxx:54
 TSelectorList.cxx:55
 TSelectorList.cxx:56
 TSelectorList.cxx:57
 TSelectorList.cxx:58
 TSelectorList.cxx:59
 TSelectorList.cxx:60
 TSelectorList.cxx:61
 TSelectorList.cxx:62
 TSelectorList.cxx:63
 TSelectorList.cxx:64
 TSelectorList.cxx:65
 TSelectorList.cxx:66
 TSelectorList.cxx:67
 TSelectorList.cxx:68
 TSelectorList.cxx:69
 TSelectorList.cxx:70
 TSelectorList.cxx:71
 TSelectorList.cxx:72
 TSelectorList.cxx:73
 TSelectorList.cxx:74
 TSelectorList.cxx:75
 TSelectorList.cxx:76
 TSelectorList.cxx:77
 TSelectorList.cxx:78
 TSelectorList.cxx:79
 TSelectorList.cxx:80
 TSelectorList.cxx:81
 TSelectorList.cxx:82
 TSelectorList.cxx:83
 TSelectorList.cxx:84
 TSelectorList.cxx:85
 TSelectorList.cxx:86
 TSelectorList.cxx:87
 TSelectorList.cxx:88
 TSelectorList.cxx:89
 TSelectorList.cxx:90
 TSelectorList.cxx:91
 TSelectorList.cxx:92
 TSelectorList.cxx:93
 TSelectorList.cxx:94
 TSelectorList.cxx:95
 TSelectorList.cxx:96
 TSelectorList.cxx:97
 TSelectorList.cxx:98
 TSelectorList.cxx:99
 TSelectorList.cxx:100
 TSelectorList.cxx:101
 TSelectorList.cxx:102
 TSelectorList.cxx:103
 TSelectorList.cxx:104
 TSelectorList.cxx:105
 TSelectorList.cxx:106
 TSelectorList.cxx:107
 TSelectorList.cxx:108
 TSelectorList.cxx:109
 TSelectorList.cxx:110
 TSelectorList.cxx:111
 TSelectorList.cxx:112
 TSelectorList.cxx:113
 TSelectorList.cxx:114
 TSelectorList.cxx:115
 TSelectorList.cxx:116
 TSelectorList.cxx:117
 TSelectorList.cxx:118
 TSelectorList.cxx:119
 TSelectorList.cxx:120
 TSelectorList.cxx:121
 TSelectorList.cxx:122
 TSelectorList.cxx:123
 TSelectorList.cxx:124
 TSelectorList.cxx:125
 TSelectorList.cxx:126
 TSelectorList.cxx:127
 TSelectorList.cxx:128
 TSelectorList.cxx:129
 TSelectorList.cxx:130
 TSelectorList.cxx:131
 TSelectorList.cxx:132
 TSelectorList.cxx:133
 TSelectorList.cxx:134
 TSelectorList.cxx:135
 TSelectorList.cxx:136
 TSelectorList.cxx:137
 TSelectorList.cxx:138
 TSelectorList.cxx:139
 TSelectorList.cxx:140
 TSelectorList.cxx:141
 TSelectorList.cxx:142
 TSelectorList.cxx:143
 TSelectorList.cxx:144
 TSelectorList.cxx:145
 TSelectorList.cxx:146
 TSelectorList.cxx:147
 TSelectorList.cxx:148
 TSelectorList.cxx:149
 TSelectorList.cxx:150
 TSelectorList.cxx:151
 TSelectorList.cxx:152
 TSelectorList.cxx:153
 TSelectorList.cxx:154
 TSelectorList.cxx:155
 TSelectorList.cxx:156
 TSelectorList.cxx:157
 TSelectorList.cxx:158
 TSelectorList.cxx:159
 TSelectorList.cxx:160
 TSelectorList.cxx:161
 TSelectorList.cxx:162
 TSelectorList.cxx:163
 TSelectorList.cxx:164
 TSelectorList.cxx:165