KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVRList.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  kvrlist.cpp - description
3  -------------------
4  begin : Thu Mar 13 2003
5  copyright : (C) 2003 by J.D Frankland & Alexis Mignon
6  email : frankland@ganil.fr, mignon@ganil.fr
7 
8 $Id: KVRList.cpp,v 1.20 2009/01/14 11:46:30 franklan Exp $
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #include "KVRList.h"
21 #include "TObject.h"
22 #include "Riostream.h"
23 #include "KVError.h"
24 
26 
27 
30 
32 {
33  //Look for object with name "name" in the list
34  return (KVBase*) TRefArray::FindObject(name);
35 }
36 
37 
38 
45 
47 {
48  //
49  // Find an object in this list using its type. Requires a sequential
50  // scan till the object has been found. Returns 0 if object with specified
51  // name is not found.
52  //
53 
54  if (type) {
55  if (GetSize()) { //make sure list contains some objects
56  for (Int_t i = 0; i < GetSize(); i++) {
57  KVBase* obj = (KVBase*) At(i);
58  if (obj->GetType() && !strcmp(type, obj->GetType()))
59  return obj;
60  }
61  }
62  }
63 // Warning("GetObjectByType",KVRLIST_NOT_WITH_THIS_TYPE,type);
64  return 0;
65 }
66 
67 
68 
75 
77 {
78  //
79  // Find an object in this list using its label. Requires a sequential
80  // scan till the object has been found. Returns 0 if object with specified
81  // label is not found.
82  //
83 
84  if (type) {
85  if (GetSize()) { //make sure list contains some objects
86  for (Int_t i = 0; i < GetSize(); i++) {
87  KVBase* obj = (KVBase*) At(i);
88  if (obj->GetLabel() && !strcmp(type, obj->GetLabel()))
89  return obj;
90  }
91  }
92  }
93 // Warning("GetObjectByType",KVRLIST_NOT_WITH_THIS_TYPE,type);
94  return 0;
95 }
96 
97 
98 
105 
106 KVBase* KVRList::FindObject(const Char_t* name, const Char_t* type) const
107 {
108 //
109 // Find an object in this list using its type and name. Requires a sequential
110 // scan till the object has been found. Returns 0 if object with specified
111 // name is not found.
112 //
113 
114  if (type && name) {
115  if (GetSize()) { //make sure list contains some objects
116  for (Int_t i = 0; i < GetSize(); i++) {
117  KVBase* obj = (KVBase*) At(i);
118  if (!strcmp(type, obj->GetType())
119  && !strcmp(name, obj->GetName()))
120  return obj;
121  }
122  }
123  }
124 // Warning("GetObject",KVRLIST_NOT_WITH_THIS_NAME_AND_TYPE,name,type);
125  return 0;
126 }
127 
128 
129 
130 #if ROOT_VERSION_CODE >= ROOT_VERSION(3,4,0)
131 
138 
139 void KVRList::Copy(TObject& obj) const
140 #else
141 void KVRList::Copy(TObject& obj)
142 #endif
143 {
144  //
145  //Copy this list to obj
146  //As a KVRList is a list of references to objects, here we are simply
147  //copying the references, i.e. no new objects are created
148  //
149  obj.Clear();
150  if (this->GetSize()) { //make sure list contains some objects
151  for (Int_t i = 0; i < this->GetSize(); i++) {
152  ((KVRList&) obj).Add(this->At(i));
153  }
154  }
155 }
156 
157 
158 
161 
162 void KVRList::Print(Option_t* opt) const
163 {
164  //Print description of all objects in list
165 #ifdef KV_DEBUG
166  Info("Print", "List size: %d elements", this->GetSize());
167 #endif
168  if (this->GetSize()) { //make sure list contains some objects
169  for (Int_t i = 0; i < this->GetSize(); i++) {
170  if (At(i))
171  ((KVBase*) At(i))->Print(opt);
172  else
173  Error("Print", "Object %d does not exist", i);
174  }
175  }
176 }
177 
178 
179 
184 
185 void KVRList::Execute(const char* method, const char* params,
186  Int_t* error)
187 {
188  //Redefinition of TObject::Execute method.
189  //TObject::Execute is called for each object in the list in order, meaning that for each
190  //object the method "method" is executed with arguments "params".
191  TIter next(this);
192  TObject* obj;
193  while ((obj = next())) {
194  obj->Execute(method, params, error);
195  }
196 }
197 
198 
199 
200 
202 
204 {
205  return (KVBase*) TRefArray::FindObject(obj);
206 }
207 
208 
int Int_t
Defines macros for standard error messages.
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const char Option_t
int type
Base class for KaliVeda framework.
Definition: KVBase.h:141
virtual const Char_t * GetType() const
Definition: KVBase.h:176
const Char_t * GetLabel() const
Definition: KVBase.h:198
Wrapper for TRefArray adding some functionality.
Definition: KVRList.h:36
virtual Int_t GetSize() const
Definition: KVRList.h:76
virtual KVBase * FindObjectByName(const Char_t *) const
Look for object with name "name" in the list.
Definition: KVRList.cpp:31
virtual KVBase * FindObject(const Char_t *name, const Char_t *type) const
Definition: KVRList.cpp:106
virtual KVBase * FindObjectByType(const Char_t *) const
Definition: KVRList.cpp:46
virtual void Execute(const char *method, const char *params, Int_t *error=0)
Definition: KVRList.cpp:185
virtual KVBase * FindObjectByLabel(const Char_t *) const
Definition: KVRList.cpp:76
virtual void Print(Option_t *opt="") const
Print description of all objects in list.
Definition: KVRList.cpp:162
virtual void Copy(TObject &obj) const
Definition: KVRList.cpp:139
virtual TObject * FindObject(const char *name) const
virtual const char * GetName() const
virtual void Clear(Option_t *="")
virtual void Execute(const char *method, const char *params, Int_t *error=0)
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
TObject * At(Int_t idx) const