| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2000-2002
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | // //
|
|---|
| 27 | // MParList //
|
|---|
| 28 | // //
|
|---|
| 29 | // This class contains a list of different parameter containers. //
|
|---|
| 30 | // //
|
|---|
| 31 | // A parameter container is an object which is derived from //
|
|---|
| 32 | // MParContainer. //
|
|---|
| 33 | // //
|
|---|
| 34 | // Normally a parameter container is used for data exchange between two //
|
|---|
| 35 | // tasks at runtime. //
|
|---|
| 36 | // //
|
|---|
| 37 | // You can add every parameter container (Named object) to the //
|
|---|
| 38 | // instance and access it from somewhere else via its Name. //
|
|---|
| 39 | // //
|
|---|
| 40 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 41 | #include "MParList.h"
|
|---|
| 42 |
|
|---|
| 43 | #include <fstream> // ofstream, SavePrimitive
|
|---|
| 44 |
|
|---|
| 45 | #include <TNamed.h>
|
|---|
| 46 | #include <TClass.h>
|
|---|
| 47 | #include <TOrdCollection.h>
|
|---|
| 48 |
|
|---|
| 49 | #include "MLog.h"
|
|---|
| 50 | #include "MLogManip.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MIter.h"
|
|---|
| 53 | #include "MTaskList.h"
|
|---|
| 54 |
|
|---|
| 55 | ClassImp(MParList);
|
|---|
| 56 |
|
|---|
| 57 | using namespace std;
|
|---|
| 58 |
|
|---|
| 59 | static const TString gsDefName = "MParList";
|
|---|
| 60 | static const TString gsDefTitle = "A list of Parameter Containers";
|
|---|
| 61 |
|
|---|
| 62 | // --------------------------------------------------------------------------
|
|---|
| 63 | //
|
|---|
| 64 | // default constructor
|
|---|
| 65 | // creates an empty list
|
|---|
| 66 | //
|
|---|
| 67 | MParList::MParList(const char *name, const char *title)
|
|---|
| 68 | {
|
|---|
| 69 | fName = name ? name : gsDefName.Data();
|
|---|
| 70 | fTitle = title ? title : gsDefTitle.Data();
|
|---|
| 71 |
|
|---|
| 72 | //
|
|---|
| 73 | // This sets a flag that the list is the owner, which means
|
|---|
| 74 | // that the destructor of the list deletes all it's objects
|
|---|
| 75 | //
|
|---|
| 76 | fContainer = new TOrdCollection;
|
|---|
| 77 | fAutodelete = new TOrdCollection;
|
|---|
| 78 |
|
|---|
| 79 | gROOT->GetListOfCleanups()->Add(fContainer);
|
|---|
| 80 | gROOT->GetListOfCleanups()->Add(fAutodelete);
|
|---|
| 81 | fContainer->SetBit(kMustCleanup);
|
|---|
| 82 | fAutodelete->SetBit(kMustCleanup);
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | // --------------------------------------------------------------------------
|
|---|
| 86 | //
|
|---|
| 87 | // Copy constructor. It copies all entries of the parameter list, but it
|
|---|
| 88 | // takes care of, that the automatically created entries are only deleted
|
|---|
| 89 | // once. (doesn't copy the list which holds the automatically created
|
|---|
| 90 | // entries)
|
|---|
| 91 | //
|
|---|
| 92 | MParList::MParList(MParList &ts)
|
|---|
| 93 | {
|
|---|
| 94 | fContainer->AddAll(ts.fContainer);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | // --------------------------------------------------------------------------
|
|---|
| 98 | //
|
|---|
| 99 | // If the 'IsOwner' bit is set (via SetOwner()) all containers are deleted
|
|---|
| 100 | // by the destructor
|
|---|
| 101 | //
|
|---|
| 102 | MParList::~MParList()
|
|---|
| 103 | {
|
|---|
| 104 | //
|
|---|
| 105 | // Case:
|
|---|
| 106 | // 1) MParList is owner of the containers:
|
|---|
| 107 | // All container are stored in fContainer, and become deleted by
|
|---|
| 108 | // 'delete fContainer'. Some of these containers, which were
|
|---|
| 109 | // created automatically are stored in fAutodelete, too. To prevent
|
|---|
| 110 | // double deletion this containers are not deleted by the destructor
|
|---|
| 111 | // of fAutodelete.
|
|---|
| 112 | // 2) MParList is not owner of the containers:
|
|---|
| 113 | // The containers which were Added by AddToList are not touched.
|
|---|
| 114 | // Only the containers which were created automatically are also
|
|---|
| 115 | // automatically deleted.
|
|---|
| 116 | //
|
|---|
| 117 | IsOwner() ? fContainer->SetOwner() : fAutodelete->SetOwner();
|
|---|
| 118 |
|
|---|
| 119 | TIter Next(fContainer);
|
|---|
| 120 | TObject *o;
|
|---|
| 121 | while ((o=Next()))
|
|---|
| 122 | if (o->TestBit(kCanDelete))
|
|---|
| 123 | delete fContainer->Remove(o);
|
|---|
| 124 |
|
|---|
| 125 | // FIXME? If fContainer is owner do we have to remove the object
|
|---|
| 126 | // from fAutodelete due to the acces when checking for a
|
|---|
| 127 | // garbage collection?
|
|---|
| 128 |
|
|---|
| 129 | delete fContainer;
|
|---|
| 130 | delete fAutodelete;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | // --------------------------------------------------------------------------
|
|---|
| 134 | //
|
|---|
| 135 | // If the 'IsOwner' bit is set (via SetOwner()) all containers are deleted
|
|---|
| 136 | // by the destructor
|
|---|
| 137 | //
|
|---|
| 138 | void MParList::SetOwner(Bool_t enable)
|
|---|
| 139 | {
|
|---|
| 140 | enable ? SetBit(kIsOwner) : ResetBit(kIsOwner);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | // --------------------------------------------------------------------------
|
|---|
| 144 | //
|
|---|
| 145 | // Set the logging streamer of the parameter list and all contained
|
|---|
| 146 | // parameter containers
|
|---|
| 147 | //
|
|---|
| 148 | void MParList::SetLogStream(MLog *log)
|
|---|
| 149 | {
|
|---|
| 150 | fContainer->ForEach(MParContainer, SetLogStream)(log);
|
|---|
| 151 | MParContainer::SetLogStream(log);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | void MParList::SetDisplay(MStatusDisplay *d)
|
|---|
| 155 | {
|
|---|
| 156 | fContainer->ForEach(MParContainer, SetDisplay)(d);
|
|---|
| 157 | MParContainer::SetDisplay(d);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | // --------------------------------------------------------------------------
|
|---|
| 161 | //
|
|---|
| 162 | // Add a single container to the list.
|
|---|
| 163 | //
|
|---|
| 164 | // If 'where' is given, the object will be added after this.
|
|---|
| 165 | //
|
|---|
| 166 | Bool_t MParList::AddToList(MParContainer *cont, MParContainer *where)
|
|---|
| 167 | {
|
|---|
| 168 | //
|
|---|
| 169 | // check if the object (you want to add) exists
|
|---|
| 170 | //
|
|---|
| 171 | if (!cont)
|
|---|
| 172 | return kFALSE;
|
|---|
| 173 |
|
|---|
| 174 | //
|
|---|
| 175 | // Get Name of new container
|
|---|
| 176 | //
|
|---|
| 177 | const char *name = cont->GetName();
|
|---|
| 178 |
|
|---|
| 179 | //
|
|---|
| 180 | // Check if the new container is already existing in the list
|
|---|
| 181 | //
|
|---|
| 182 | const TObject *objn = fContainer->FindObject(name);
|
|---|
| 183 | const TObject *objt = fContainer->FindObject(cont);
|
|---|
| 184 |
|
|---|
| 185 | if (objn || objt)
|
|---|
| 186 | {
|
|---|
| 187 | //
|
|---|
| 188 | // If the container is already in the list ignore it.
|
|---|
| 189 | //
|
|---|
| 190 | if (objt || objn==cont)
|
|---|
| 191 | {
|
|---|
| 192 | *fLog << warn << dbginf << "Warning: Container '" << cont->GetName() << ", 0x" << (void*)cont;
|
|---|
| 193 | *fLog << "' already existing in '" << GetName() << "'... ignoring." << endl;
|
|---|
| 194 | return kTRUE;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | //
|
|---|
| 198 | // Otherwise add it to the list, but print a warning message
|
|---|
| 199 | //
|
|---|
| 200 | *fLog << warn << dbginf << "Warning: Container with the same name '" << cont->GetName();
|
|---|
| 201 | *fLog << "' already existing in '" << GetName() << "'." << endl;
|
|---|
| 202 | *fLog << "You may not be able to get a pointer to container task by name." << endl;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | //
|
|---|
| 206 | // check if you want to add the new parameter container somewhere
|
|---|
| 207 | // special (in that case you specify "where")
|
|---|
| 208 | //
|
|---|
| 209 | if (where)
|
|---|
| 210 | {
|
|---|
| 211 | if (!fContainer->FindObject(where))
|
|---|
| 212 | {
|
|---|
| 213 | *fLog << dbginf << "Error: Cannot find parameter container after which the new one should be added!" << endl;
|
|---|
| 214 | return kFALSE;
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | if (!cont->InheritsFrom(MParContainer::Class()))
|
|---|
| 219 | {
|
|---|
| 220 | *fLog << dbginf << "Error: Cantainer MUST derive from MParContainer!" << endl;
|
|---|
| 221 | return kFALSE;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | *fLog << inf << "Adding " << name << " to " << GetName() << "... " << flush;
|
|---|
| 225 |
|
|---|
| 226 | cont->SetBit(kMustCleanup);
|
|---|
| 227 | fContainer->Add(cont);
|
|---|
| 228 | *fLog << "Done." << endl;
|
|---|
| 229 |
|
|---|
| 230 | return kTRUE;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | // --------------------------------------------------------------------------
|
|---|
| 234 | //
|
|---|
| 235 | // Add all entries of the TObjArray to the list.
|
|---|
| 236 | //
|
|---|
| 237 | void MParList::AddToList(TObjArray *list)
|
|---|
| 238 | {
|
|---|
| 239 | //
|
|---|
| 240 | // check if the object (you want to add) exists
|
|---|
| 241 | //
|
|---|
| 242 | if (!list)
|
|---|
| 243 | return;
|
|---|
| 244 |
|
|---|
| 245 | MIter Next(list);
|
|---|
| 246 |
|
|---|
| 247 | MParContainer *cont = NULL;
|
|---|
| 248 | while ((cont=Next()))
|
|---|
| 249 | {
|
|---|
| 250 | cont->SetBit(kMustCleanup);
|
|---|
| 251 | AddToList(cont);
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | // --------------------------------------------------------------------------
|
|---|
| 256 | //
|
|---|
| 257 | // Find an object with the same name in the list and replace it with
|
|---|
| 258 | // the new one. If the kIsOwner flag is set and the object was not
|
|---|
| 259 | // created automatically, the object is deleted.
|
|---|
| 260 | //
|
|---|
| 261 | Bool_t MParList::Replace(MParContainer *cont)
|
|---|
| 262 | {
|
|---|
| 263 | //
|
|---|
| 264 | // check if the object (you want to add) exists
|
|---|
| 265 | //
|
|---|
| 266 | if (!cont)
|
|---|
| 267 | return kFALSE;
|
|---|
| 268 |
|
|---|
| 269 | TObject *obj = FindObject(cont->GetName());
|
|---|
| 270 | if (!obj)
|
|---|
| 271 | {
|
|---|
| 272 | *fLog << warn << "No object with the same name '";
|
|---|
| 273 | *fLog << cont->GetName() << "' in list... adding." << endl;
|
|---|
| 274 | return AddToList(cont);
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | fContainer->Remove(obj);
|
|---|
| 278 |
|
|---|
| 279 | if (IsOwner() && !fAutodelete->FindObject(obj))
|
|---|
| 280 | delete obj;
|
|---|
| 281 |
|
|---|
| 282 | *fLog << inf << "MParContainer '" << cont->GetName() << "' found and replaced..." << endl;
|
|---|
| 283 |
|
|---|
| 284 | return AddToList(cont);
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | // --------------------------------------------------------------------------
|
|---|
| 288 | //
|
|---|
| 289 | // Find an object with the same name in the list and remove it.
|
|---|
| 290 | // If the kIsOwner flag is set and the object was not created
|
|---|
| 291 | // automatically, the object is deleted.
|
|---|
| 292 | //
|
|---|
| 293 | void MParList::Remove(MParContainer *cont)
|
|---|
| 294 | {
|
|---|
| 295 | //
|
|---|
| 296 | // check if the object (you want to add) exists
|
|---|
| 297 | //
|
|---|
| 298 | if (!cont)
|
|---|
| 299 | return;
|
|---|
| 300 |
|
|---|
| 301 | TObject *obj = fContainer->Remove(cont);
|
|---|
| 302 | if (!obj)
|
|---|
| 303 | {
|
|---|
| 304 | *fLog << warn << "Object not found in list..." << endl;
|
|---|
| 305 | return;
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | *fLog << inf << "MParContainer '" << cont->GetName() << "' removed..." << endl;
|
|---|
| 309 |
|
|---|
| 310 | if (IsOwner() && !fAutodelete->FindObject(obj))
|
|---|
| 311 | delete obj;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | // --------------------------------------------------------------------------
|
|---|
| 315 | //
|
|---|
| 316 | // Find an object in the list.
|
|---|
| 317 | // 'name' is the name of the object you are searching for.
|
|---|
| 318 | //
|
|---|
| 319 | TObject *MParList::FindObject(const char *name) const
|
|---|
| 320 | {
|
|---|
| 321 | return fContainer->FindObject(name);
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | // --------------------------------------------------------------------------
|
|---|
| 325 | //
|
|---|
| 326 | // check if the object is in the list or not
|
|---|
| 327 | //
|
|---|
| 328 | TObject *MParList::FindObject(const TObject *obj) const
|
|---|
| 329 | {
|
|---|
| 330 | return fContainer->FindObject(obj);
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | // --------------------------------------------------------------------------
|
|---|
| 334 | //
|
|---|
| 335 | // Find an object in the list and check for the correct inheritance.
|
|---|
| 336 | // 'name' is the name of the object you are searching for.
|
|---|
| 337 | //
|
|---|
| 338 | // In words: Find object name and check whether it inherits from classname
|
|---|
| 339 | //
|
|---|
| 340 | TObject *MParList::FindObject(const char *name, const char *classname) const
|
|---|
| 341 | {
|
|---|
| 342 | TObject *obj = fContainer->FindObject(name);
|
|---|
| 343 |
|
|---|
| 344 | if (!obj)
|
|---|
| 345 | return NULL;
|
|---|
| 346 |
|
|---|
| 347 | if (obj->InheritsFrom(classname))
|
|---|
| 348 | return obj;
|
|---|
| 349 |
|
|---|
| 350 | *fLog << dbginf << warn << "Found object '" << name << "' doesn't ";
|
|---|
| 351 | *fLog << "inherit from " << "'" << classname << "'" << endl;
|
|---|
| 352 | return NULL;
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | // --------------------------------------------------------------------------
|
|---|
| 356 | //
|
|---|
| 357 | // check if the object is in the list or not and check for the correct
|
|---|
| 358 | // inheritance
|
|---|
| 359 | //
|
|---|
| 360 | TObject *MParList::FindObject(const TObject *obj, const char *classname) const
|
|---|
| 361 | {
|
|---|
| 362 | TObject *nobj = fContainer->FindObject(obj);
|
|---|
| 363 |
|
|---|
| 364 | if (!nobj)
|
|---|
| 365 | return NULL;
|
|---|
| 366 |
|
|---|
| 367 | if (nobj->InheritsFrom(classname))
|
|---|
| 368 | return nobj;
|
|---|
| 369 |
|
|---|
| 370 | *fLog << dbginf << warn << "Found object '" << nobj->GetName() << "' ";
|
|---|
| 371 | *fLog << "doesn't inherit from " << "'" << classname << "'" << endl;
|
|---|
| 372 | return NULL;
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | // --------------------------------------------------------------------------
|
|---|
| 376 | //
|
|---|
| 377 | // Searches for the tasklist tlist (default: MTaskList) and returns
|
|---|
| 378 | // a task with the given name found in this list. If one of both isn't
|
|---|
| 379 | // found NULL is returned
|
|---|
| 380 | //
|
|---|
| 381 | MTask *MParList::FindTask(const char *name, const char *tlist) const
|
|---|
| 382 | {
|
|---|
| 383 | TObject *l = FindObject(tlist, "MTaskList");
|
|---|
| 384 | return (MTask*)(l ? l->FindObject(name) : NULL);
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | // --------------------------------------------------------------------------
|
|---|
| 388 | //
|
|---|
| 389 | // Find a tasklist which contains a task with name name
|
|---|
| 390 | //
|
|---|
| 391 | MTaskList *MParList::FindTaskListWithTask(const char *name) const
|
|---|
| 392 | {
|
|---|
| 393 | TIter Next(fContainer);
|
|---|
| 394 | TObject *o=0;
|
|---|
| 395 | while ((o=Next()))
|
|---|
| 396 | {
|
|---|
| 397 | MTaskList *l1 = dynamic_cast<MTaskList*>(o);
|
|---|
| 398 | if (!l1)
|
|---|
| 399 | continue;
|
|---|
| 400 |
|
|---|
| 401 | MTaskList *l2 = l1->FindTaskList(name);
|
|---|
| 402 | if (l2)
|
|---|
| 403 | return l2;
|
|---|
| 404 | }
|
|---|
| 405 | return 0;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | // --------------------------------------------------------------------------
|
|---|
| 409 | //
|
|---|
| 410 | // Find a tasklist which contains a task task
|
|---|
| 411 | //
|
|---|
| 412 | MTaskList *MParList::FindTaskListWithTask(const MTask *task) const
|
|---|
| 413 | {
|
|---|
| 414 | TIter Next(fContainer);
|
|---|
| 415 | TObject *o=0;
|
|---|
| 416 | while ((o=Next()))
|
|---|
| 417 | {
|
|---|
| 418 | MTaskList *l1 = dynamic_cast<MTaskList*>(o);
|
|---|
| 419 | if (!l1)
|
|---|
| 420 | continue;
|
|---|
| 421 |
|
|---|
| 422 | MTaskList *l2 = l1->FindTaskList(task);
|
|---|
| 423 | if (l2)
|
|---|
| 424 | return l2;
|
|---|
| 425 | }
|
|---|
| 426 | return 0;
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | // --------------------------------------------------------------------------
|
|---|
| 430 | //
|
|---|
| 431 | // returns the ClassName without anything which is behind that last ';' in
|
|---|
| 432 | // string.
|
|---|
| 433 | //
|
|---|
| 434 | TString MParList::GetClassName(const char *classname)
|
|---|
| 435 | {
|
|---|
| 436 | TString cname(classname);
|
|---|
| 437 | const char *semicolon = strrchr(cname, ';');
|
|---|
| 438 |
|
|---|
| 439 | if (semicolon)
|
|---|
| 440 | cname.Remove(semicolon-cname);
|
|---|
| 441 |
|
|---|
| 442 | return cname;
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | // --------------------------------------------------------------------------
|
|---|
| 446 | //
|
|---|
| 447 | // returns the ObjectName. It is created from a class and object name.
|
|---|
| 448 | // If no object name is given the objectname is the same than the
|
|---|
| 449 | // class name. Leading dots are removed from the object name
|
|---|
| 450 | //
|
|---|
| 451 | TString MParList::GetObjectName(const char *classname, const char *objname)
|
|---|
| 452 | {
|
|---|
| 453 | TString cname(classname);
|
|---|
| 454 | const char *semicolon = strrchr(cname, ';');
|
|---|
| 455 |
|
|---|
| 456 | TString oname(objname ? objname : classname);
|
|---|
| 457 |
|
|---|
| 458 | if (semicolon)
|
|---|
| 459 | {
|
|---|
| 460 | //
|
|---|
| 461 | // Remove leading dots from objectname (eg. "MMcTrig;5.")
|
|---|
| 462 | //
|
|---|
| 463 | Int_t sz = oname.Sizeof()-2;
|
|---|
| 464 |
|
|---|
| 465 | while (sz>=0 && oname[sz]=='.')
|
|---|
| 466 | oname.Remove(sz--);
|
|---|
| 467 | }
|
|---|
| 468 | return oname;
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | // --------------------------------------------------------------------------
|
|---|
| 472 | //
|
|---|
| 473 | // Find an object in the list.
|
|---|
| 474 | // 'name' is the name of the object you are searching for.
|
|---|
| 475 | // If the object doesn't exist we try to create one from the
|
|---|
| 476 | // dictionary. If this isn't possible NULL is returned.
|
|---|
| 477 | //
|
|---|
| 478 | // An object which was created automatically is deleted automatically in
|
|---|
| 479 | // the destructor of the parameter list, too. This means, that if an
|
|---|
| 480 | // object should survive (eg. Histograms) you MUST create it by yourself
|
|---|
| 481 | // and add it to the parameter list.
|
|---|
| 482 | //
|
|---|
| 483 | // By default (you don't specify an object name) the object name is
|
|---|
| 484 | // the same as the classname
|
|---|
| 485 | //
|
|---|
| 486 | // If the classname (default classname) is of the structure
|
|---|
| 487 | // "Name;something" - containing a semicolon - evarything which is
|
|---|
| 488 | // after the last appearance of a semicolon is stripped to get the
|
|---|
| 489 | // Name of the Class. Normally this is used to number your objects.
|
|---|
| 490 | // "Name;1", "Name;2", ... If a semicolon is detected leading dots
|
|---|
| 491 | // are stripped from the object-name (eg. "name;5.")
|
|---|
| 492 | //
|
|---|
| 493 | // In words: Create object of type classname and set its name to objname.
|
|---|
| 494 | // If an object with objname already exists return it.
|
|---|
| 495 | //
|
|---|
| 496 | MParContainer *MParList::FindCreateObj(const char *classname, const char *objname)
|
|---|
| 497 | {
|
|---|
| 498 | //
|
|---|
| 499 | // If now object name (name of the object to identify it in the
|
|---|
| 500 | // List) is given use it's classname as the objectname
|
|---|
| 501 | //
|
|---|
| 502 |
|
|---|
| 503 | //
|
|---|
| 504 | // Check if the classname is a 'numbered' name (like: "MTime;2")
|
|---|
| 505 | // if so strip the number from the classname.
|
|---|
| 506 | //
|
|---|
| 507 | // Becareful: We check for the last occurance of a ';' only and we
|
|---|
| 508 | // also don't check if a number follows or something else.
|
|---|
| 509 | //
|
|---|
| 510 | // Rem: I use a TString to make the code more readyble and to get
|
|---|
| 511 | // the new object deleted automatically
|
|---|
| 512 | //
|
|---|
| 513 | TString cname = GetClassName(classname);
|
|---|
| 514 | TString oname = GetObjectName(classname, objname);
|
|---|
| 515 |
|
|---|
| 516 | //
|
|---|
| 517 | // Try to find a object with this object name which is already
|
|---|
| 518 | // in the List. If we can find one we are done.
|
|---|
| 519 | //
|
|---|
| 520 | MParContainer *pcont = (MParContainer*)FindObject(oname);
|
|---|
| 521 |
|
|---|
| 522 | if (pcont)
|
|---|
| 523 | {
|
|---|
| 524 | if (pcont->InheritsFrom(cname))
|
|---|
| 525 | return pcont;
|
|---|
| 526 |
|
|---|
| 527 | *fLog << err << "Warning: Object '" << oname << "' found in list doesn't inherit from " << cname << "." << endl;
|
|---|
| 528 | return NULL;
|
|---|
| 529 | }
|
|---|
| 530 |
|
|---|
| 531 | //
|
|---|
| 532 | // if object is not existing in the list try to create one
|
|---|
| 533 | //
|
|---|
| 534 | *fLog << inf << "Object '" << oname << "' ";
|
|---|
| 535 | if (oname!=cname)
|
|---|
| 536 | *fLog << "[" << cname << "] ";
|
|---|
| 537 | *fLog << "not yet in " << GetName() << "... creating." << endl;
|
|---|
| 538 |
|
|---|
| 539 | //
|
|---|
| 540 | // try to get class from root environment
|
|---|
| 541 | //
|
|---|
| 542 | TClass *cls = gROOT->GetClass(cname);
|
|---|
| 543 | Int_t rc = 0;
|
|---|
| 544 | if (!cls)
|
|---|
| 545 | rc =1;
|
|---|
| 546 | else
|
|---|
| 547 | {
|
|---|
| 548 | if (!cls->Property())
|
|---|
| 549 | rc = 5;
|
|---|
| 550 | if (!cls->Size())
|
|---|
| 551 | rc = 4;
|
|---|
| 552 | if (!cls->IsLoaded())
|
|---|
| 553 | rc = 3;
|
|---|
| 554 | if (!cls->HasDefaultConstructor())
|
|---|
| 555 | rc = 2;
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | if (rc)
|
|---|
| 559 | {
|
|---|
| 560 | *fLog << err << dbginf << "Cannot create new instance of class '" << cname << "': ";
|
|---|
| 561 | switch (rc)
|
|---|
| 562 | {
|
|---|
| 563 | case 1:
|
|---|
| 564 | *fLog << "gROOT->GetClass() returned NULL." << endl;
|
|---|
| 565 | return NULL;
|
|---|
| 566 | case 2:
|
|---|
| 567 | *fLog << "no default constructor." << endl;
|
|---|
| 568 | return NULL;
|
|---|
| 569 | case 3:
|
|---|
| 570 | *fLog << "not loaded." << endl;
|
|---|
| 571 | return NULL;
|
|---|
| 572 | case 4:
|
|---|
| 573 | *fLog << "zero size." << endl;
|
|---|
| 574 | return NULL;
|
|---|
| 575 | case 5:
|
|---|
| 576 | *fLog << "no property." << endl;
|
|---|
| 577 | return NULL;
|
|---|
| 578 | }
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | if (!cls->InheritsFrom(MParContainer::Class()))
|
|---|
| 582 | {
|
|---|
| 583 | *fLog << " - Class doesn't inherit from MParContainer." << endl;
|
|---|
| 584 | return NULL;
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 | //
|
|---|
| 588 | // create the parameter container of the the given class type
|
|---|
| 589 | //
|
|---|
| 590 | pcont = (MParContainer*)cls->New();
|
|---|
| 591 | if (!pcont)
|
|---|
| 592 | {
|
|---|
| 593 | *fLog << " - Class has no default constructor." << endl;
|
|---|
| 594 | *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
|
|---|
| 595 | return NULL;
|
|---|
| 596 | }
|
|---|
| 597 |
|
|---|
| 598 | //
|
|---|
| 599 | // Set the name of the container
|
|---|
| 600 | //
|
|---|
| 601 | pcont->SetName(oname);
|
|---|
| 602 |
|
|---|
| 603 | //
|
|---|
| 604 | // Now add the object to the parameter list
|
|---|
| 605 | //
|
|---|
| 606 | AddToList(pcont);
|
|---|
| 607 |
|
|---|
| 608 | //
|
|---|
| 609 | // The object was automatically created. This makes sure, that such an
|
|---|
| 610 | // object is deleted together with the list
|
|---|
| 611 | //
|
|---|
| 612 | fAutodelete->Add(pcont);
|
|---|
| 613 |
|
|---|
| 614 | //
|
|---|
| 615 | // Find an object in the list.
|
|---|
| 616 | // 'name' is the name of the object you are searching for.
|
|---|
| 617 | //
|
|---|
| 618 | return pcont;
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | // --------------------------------------------------------------------------
|
|---|
| 622 | //
|
|---|
| 623 | // print some information about the current status of MParList
|
|---|
| 624 | //
|
|---|
| 625 | void MParList::Print(Option_t *t) const
|
|---|
| 626 | {
|
|---|
| 627 | *fLog << all << underline << GetDescriptor() << ":" << endl;
|
|---|
| 628 |
|
|---|
| 629 | MParContainer *obj = NULL;
|
|---|
| 630 | MIter Next(fContainer);
|
|---|
| 631 | while ((obj=Next()))
|
|---|
| 632 | {
|
|---|
| 633 | *fLog << " " << obj->GetDescriptor();
|
|---|
| 634 | if (fAutodelete->FindObject(obj))
|
|---|
| 635 | *fLog << " <autodel>";
|
|---|
| 636 | *fLog << endl;
|
|---|
| 637 | }
|
|---|
| 638 | *fLog << endl;
|
|---|
| 639 | }
|
|---|
| 640 |
|
|---|
| 641 | // --------------------------------------------------------------------------
|
|---|
| 642 | //
|
|---|
| 643 | // Sets the flags off all containers in the list (and the list
|
|---|
| 644 | // itself) to unchanged
|
|---|
| 645 | //
|
|---|
| 646 | void MParList::SetReadyToSave(Bool_t flag)
|
|---|
| 647 | {
|
|---|
| 648 | fContainer->ForEach(MParContainer, SetReadyToSave)(flag);
|
|---|
| 649 | MParContainer::SetReadyToSave(flag);
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | // --------------------------------------------------------------------------
|
|---|
| 653 | //
|
|---|
| 654 | // Reset all containers in the list
|
|---|
| 655 | //
|
|---|
| 656 | void MParList::Reset()
|
|---|
| 657 | {
|
|---|
| 658 | fContainer->ForEach(MParContainer, Reset)();
|
|---|
| 659 | }
|
|---|
| 660 |
|
|---|
| 661 | // --------------------------------------------------------------------------
|
|---|
| 662 | //
|
|---|
| 663 | // This finds numbered objects. The objects are returned in a copy of a
|
|---|
| 664 | // TObjArray.
|
|---|
| 665 | //
|
|---|
| 666 | // If from only is given (or to=0) object are assumed numbered
|
|---|
| 667 | // from 1 to from.
|
|---|
| 668 | //
|
|---|
| 669 | TObjArray MParList::FindObjectList(const char *name, UInt_t first, const UInt_t last) const
|
|---|
| 670 | {
|
|---|
| 671 | TObjArray list;
|
|---|
| 672 |
|
|---|
| 673 | if (first>0 && last<first)
|
|---|
| 674 | {
|
|---|
| 675 | *fLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
|
|---|
| 676 | return list;
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | const UInt_t len = strlen(name);
|
|---|
| 680 |
|
|---|
| 681 | char *auxname = new char[len+7];
|
|---|
| 682 | strcpy(auxname, name);
|
|---|
| 683 |
|
|---|
| 684 | if (first==0 && last!=0)
|
|---|
| 685 | first = 1;
|
|---|
| 686 |
|
|---|
| 687 | //
|
|---|
| 688 | // If only 'from' is specified the number of entries are ment
|
|---|
| 689 | //
|
|---|
| 690 | for (UInt_t i=first; i<=last; i++)
|
|---|
| 691 | {
|
|---|
| 692 | if (first!=0 || last!=0)
|
|---|
| 693 | sprintf(auxname+len, ";%d", i);
|
|---|
| 694 |
|
|---|
| 695 | TObject *obj = FindObject(auxname);
|
|---|
| 696 | if (!obj)
|
|---|
| 697 | continue;
|
|---|
| 698 |
|
|---|
| 699 | list.AddLast(obj);
|
|---|
| 700 | }
|
|---|
| 701 | delete auxname;
|
|---|
| 702 |
|
|---|
| 703 | return list;
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | // --------------------------------------------------------------------------
|
|---|
| 707 | //
|
|---|
| 708 | // This finds numbered objects. The objects are returned in a copy of a
|
|---|
| 709 | // TObjArray. If one of the objects doesn't exist it is created from the
|
|---|
| 710 | // meaning of cname and oname (s. FindCreateObj)
|
|---|
| 711 | //
|
|---|
| 712 | // If from only is given (or to=0) object are assumed numbered
|
|---|
| 713 | // from 1 to from.
|
|---|
| 714 | //
|
|---|
| 715 | TObjArray MParList::FindCreateObjList(const char *cname, UInt_t first, const UInt_t last, const char *oname)
|
|---|
| 716 | {
|
|---|
| 717 | TObjArray list;
|
|---|
| 718 |
|
|---|
| 719 | if (first>0 && last<first)
|
|---|
| 720 | {
|
|---|
| 721 | *fLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
|
|---|
| 722 | return list;
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | const UInt_t len = strlen(cname);
|
|---|
| 726 |
|
|---|
| 727 | char *auxname = new char[len+7];
|
|---|
| 728 | strcpy(auxname, cname);
|
|---|
| 729 |
|
|---|
| 730 | //
|
|---|
| 731 | // If only 'from' is specified the number of entries are ment
|
|---|
| 732 | //
|
|---|
| 733 | if (first==0 && last!=0)
|
|---|
| 734 | first = 1;
|
|---|
| 735 |
|
|---|
| 736 | for (UInt_t i=first; i<=last; i++)
|
|---|
| 737 | {
|
|---|
| 738 | if (first!=0 || last!=0)
|
|---|
| 739 | sprintf(auxname+len, ";%d", i);
|
|---|
| 740 |
|
|---|
| 741 | TObject *obj = FindCreateObj(auxname, oname);
|
|---|
| 742 | if (!obj)
|
|---|
| 743 | break;
|
|---|
| 744 |
|
|---|
| 745 | list.AddLast(obj);
|
|---|
| 746 | }
|
|---|
| 747 | delete auxname;
|
|---|
| 748 |
|
|---|
| 749 | return list;
|
|---|
| 750 | }
|
|---|
| 751 |
|
|---|
| 752 | // --------------------------------------------------------------------------
|
|---|
| 753 | //
|
|---|
| 754 | // This finds numbered objects. The objects are returned in a copy of a
|
|---|
| 755 | // TObjArray. If one of the objects doesn't exist it is created from the
|
|---|
| 756 | // meaning of cname and oname (s. FindCreateObj)
|
|---|
| 757 | //
|
|---|
| 758 | // If from only is given (or to=0) object are assumed numbered
|
|---|
| 759 | // from 1 to from.
|
|---|
| 760 | //
|
|---|
| 761 | // Remark: Because it is static the object are only created and not added to
|
|---|
| 762 | // the parameter list. You must also take care of deleting these objects!
|
|---|
| 763 | // This function is mainly made for use in root macros. Don't use it in
|
|---|
| 764 | // compiled programs if you are not 100% sure what you are doing.
|
|---|
| 765 | //
|
|---|
| 766 | TObjArray MParList::CreateObjList(const char *cname, UInt_t first, const UInt_t last, const char *oname)
|
|---|
| 767 | {
|
|---|
| 768 | TObjArray list;
|
|---|
| 769 |
|
|---|
| 770 | if (first>0 && last<first)
|
|---|
| 771 | {
|
|---|
| 772 | gLog << err << dbginf << "Cannot create entries backwards (last<first)...skipped." << endl;
|
|---|
| 773 | return list;
|
|---|
| 774 | }
|
|---|
| 775 |
|
|---|
| 776 | //
|
|---|
| 777 | // try to get class from root environment
|
|---|
| 778 | //
|
|---|
| 779 | TClass *cls = gROOT->GetClass(cname);
|
|---|
| 780 | if (!cls)
|
|---|
| 781 | {
|
|---|
| 782 | //
|
|---|
| 783 | // if class is not existing in the root environment
|
|---|
| 784 | //
|
|---|
| 785 | gLog << dbginf << "Class '" << cname << "' not existing in dictionary." << endl;
|
|---|
| 786 | return list;
|
|---|
| 787 | }
|
|---|
| 788 |
|
|---|
| 789 | const UInt_t len = strlen(cname);
|
|---|
| 790 |
|
|---|
| 791 | char *auxname = new char[len+7];
|
|---|
| 792 | strcpy(auxname, cname);
|
|---|
| 793 |
|
|---|
| 794 | //
|
|---|
| 795 | // If only 'from' is specified the number of entries are ment
|
|---|
| 796 | //
|
|---|
| 797 | if (first==0 && last!=0)
|
|---|
| 798 | first = 1;
|
|---|
| 799 |
|
|---|
| 800 | for (UInt_t i=first; i<=last; i++)
|
|---|
| 801 | {
|
|---|
| 802 | if (first!=0 || last!=0)
|
|---|
| 803 | sprintf(auxname+len, ";%d", i);
|
|---|
| 804 |
|
|---|
| 805 | //
|
|---|
| 806 | // create the parameter container of the the given class type
|
|---|
| 807 | //
|
|---|
| 808 | MParContainer *pcont = (MParContainer*)cls->New();
|
|---|
| 809 | if (!pcont)
|
|---|
| 810 | {
|
|---|
| 811 | gLog << err << dbginf << "Cannot create new instance of class '" << cname << "' (Maybe no def. constructor)" << endl;
|
|---|
| 812 | return list;
|
|---|
| 813 | }
|
|---|
| 814 |
|
|---|
| 815 | //
|
|---|
| 816 | // Set the name of the container
|
|---|
| 817 | //
|
|---|
| 818 | pcont->SetName(auxname);
|
|---|
| 819 |
|
|---|
| 820 | //
|
|---|
| 821 | // Add new object to the return list
|
|---|
| 822 | //
|
|---|
| 823 | list.AddLast(pcont);
|
|---|
| 824 | }
|
|---|
| 825 | delete auxname;
|
|---|
| 826 |
|
|---|
| 827 | return list;
|
|---|
| 828 | }
|
|---|
| 829 |
|
|---|
| 830 | void MParList::SavePrimitive(ofstream &out, Option_t *o)
|
|---|
| 831 | {
|
|---|
| 832 | Bool_t saved = IsSavedAsPrimitive();
|
|---|
| 833 |
|
|---|
| 834 | MParContainer::SavePrimitive(out);
|
|---|
| 835 |
|
|---|
| 836 | MIter Next(fContainer);
|
|---|
| 837 |
|
|---|
| 838 | MParContainer *cont = NULL;
|
|---|
| 839 | while ((cont=Next()))
|
|---|
| 840 | {
|
|---|
| 841 | //
|
|---|
| 842 | // Because it was automatically created don't store its primitive
|
|---|
| 843 | // I guess it will be automatically created again
|
|---|
| 844 | //
|
|---|
| 845 | if (fAutodelete->FindObject(cont) || cont->IsSavedAsPrimitive())
|
|---|
| 846 | continue;
|
|---|
| 847 |
|
|---|
| 848 | cont->SavePrimitive(out, "");
|
|---|
| 849 |
|
|---|
| 850 | out << " " << GetUniqueName() << ".";
|
|---|
| 851 | out << (cont->InheritsFrom("MTaskList") && saved ? "Replace" : "AddToList");
|
|---|
| 852 | out << "(&" << cont->GetUniqueName() << ");" << endl << endl;
|
|---|
| 853 | }
|
|---|
| 854 | }
|
|---|
| 855 |
|
|---|
| 856 | // --------------------------------------------------------------------------
|
|---|
| 857 | //
|
|---|
| 858 | // Implementation of SavePrimitive. Used to write the call to a constructor
|
|---|
| 859 | // to a macro. In the original root implementation it is used to write
|
|---|
| 860 | // gui elements to a macro-file.
|
|---|
| 861 | //
|
|---|
| 862 | void MParList::StreamPrimitive(ofstream &out) const
|
|---|
| 863 | {
|
|---|
| 864 | out << " MParList " << GetUniqueName();
|
|---|
| 865 | if (fName!=gsDefName || fTitle!=gsDefTitle)
|
|---|
| 866 | {
|
|---|
| 867 | out << "(\"" << fName << "\"";
|
|---|
| 868 | if (fTitle!=gsDefTitle)
|
|---|
| 869 | out << ", \"" << fTitle << "\"";
|
|---|
| 870 | out <<")";
|
|---|
| 871 | }
|
|---|
| 872 | out << ";" << endl << endl;
|
|---|
| 873 | }
|
|---|
| 874 |
|
|---|
| 875 | // --------------------------------------------------------------------------
|
|---|
| 876 | //
|
|---|
| 877 | // Adds one TNamed object per object in the list. The TNamed object must
|
|---|
| 878 | // be deleted by the user.
|
|---|
| 879 | //
|
|---|
| 880 | void MParList::GetNames(TObjArray &arr) const
|
|---|
| 881 | {
|
|---|
| 882 | MParContainer::GetNames(arr);
|
|---|
| 883 | fContainer->ForEach(MParContainer, GetNames)(arr);
|
|---|
| 884 | }
|
|---|
| 885 |
|
|---|
| 886 | // --------------------------------------------------------------------------
|
|---|
| 887 | //
|
|---|
| 888 | // Sets name and title of each object in the list from the objects in
|
|---|
| 889 | // the array.
|
|---|
| 890 | //
|
|---|
| 891 | void MParList::SetNames(TObjArray &arr)
|
|---|
| 892 | {
|
|---|
| 893 | MParContainer::SetNames(arr);
|
|---|
| 894 | fContainer->ForEach(MParContainer, SetNames)(arr);
|
|---|
| 895 | }
|
|---|
| 896 |
|
|---|
| 897 | // --------------------------------------------------------------------------
|
|---|
| 898 | //
|
|---|
| 899 | // Read the contents/setup of a parameter container/task from a TEnv
|
|---|
| 900 | // instance (steering card/setup file).
|
|---|
| 901 | // The key to search for in the file should be of the syntax:
|
|---|
| 902 | // prefix.vname
|
|---|
| 903 | // While vname is a name which is specific for a single setup date
|
|---|
| 904 | // (variable) of this container and prefix is something like:
|
|---|
| 905 | // evtloopname.name
|
|---|
| 906 | // While name is the name of the containers/tasks in the parlist/tasklist
|
|---|
| 907 | //
|
|---|
| 908 | // eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
|
|---|
| 909 | // Job4.MImgCleanStd.CleaningLevel2: 2.5
|
|---|
| 910 | //
|
|---|
| 911 | // If this cannot be found the next step is to search for
|
|---|
| 912 | // MImgCleanStd.CleaningLevel1: 3.0
|
|---|
| 913 | // And if this doesn't exist, too, we search for:
|
|---|
| 914 | // CleaningLevel1: 3.0
|
|---|
| 915 | //
|
|---|
| 916 | // Warning: The programmer is responsible for the names to be unique in
|
|---|
| 917 | // all Mars classes.
|
|---|
| 918 | //
|
|---|
| 919 | Int_t MParList::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
|---|
| 920 | {
|
|---|
| 921 | if (print)
|
|---|
| 922 | *fLog << all << "MParList::ReadEnv: " << prefix << endl;
|
|---|
| 923 |
|
|---|
| 924 | MParContainer *cont = NULL;
|
|---|
| 925 |
|
|---|
| 926 | MIter Next(fContainer);
|
|---|
| 927 | while ((cont=Next()))
|
|---|
| 928 | {
|
|---|
| 929 | if (cont->InheritsFrom("MTaskList"))
|
|---|
| 930 | {
|
|---|
| 931 | if (cont->ReadEnv(env, prefix, print)==kERROR)
|
|---|
| 932 | return kERROR;
|
|---|
| 933 | continue;
|
|---|
| 934 | }
|
|---|
| 935 |
|
|---|
| 936 | if (cont->TestEnv(env, prefix, print)==kERROR)
|
|---|
| 937 | return kERROR;
|
|---|
| 938 | }
|
|---|
| 939 |
|
|---|
| 940 | return kTRUE;
|
|---|
| 941 | }
|
|---|
| 942 |
|
|---|
| 943 | // --------------------------------------------------------------------------
|
|---|
| 944 | //
|
|---|
| 945 | // Write the contents/setup of a parameter container/task to a TEnv
|
|---|
| 946 | // instance (steering card/setup file).
|
|---|
| 947 | // The key to search for in the file should be of the syntax:
|
|---|
| 948 | // prefix.vname
|
|---|
| 949 | // While vname is a name which is specific for a single setup date
|
|---|
| 950 | // (variable) of this container and prefix is something like:
|
|---|
| 951 | // evtloopname.name
|
|---|
| 952 | // While name is the name of the containers/tasks in the parlist/tasklist
|
|---|
| 953 | //
|
|---|
| 954 | // eg. Job4.MImgCleanStd.CleaningLevel1: 3.0
|
|---|
| 955 | // Job4.MImgCleanStd.CleaningLevel2: 2.5
|
|---|
| 956 | //
|
|---|
| 957 | // If this cannot be found the next step is to search for
|
|---|
| 958 | // MImgCleanStd.CleaningLevel1: 3.0
|
|---|
| 959 | // And if this doesn't exist, too, we search for:
|
|---|
| 960 | // CleaningLevel1: 3.0
|
|---|
| 961 | //
|
|---|
| 962 | // Warning: The programmer is responsible for the names to be unique in
|
|---|
| 963 | // all Mars classes.
|
|---|
| 964 | //
|
|---|
| 965 | Bool_t MParList::WriteEnv(TEnv &env, TString prefix, Bool_t print) const
|
|---|
| 966 | {
|
|---|
| 967 | MParContainer *cont = NULL;
|
|---|
| 968 |
|
|---|
| 969 | MIter Next(fContainer);
|
|---|
| 970 | while ((cont=Next()))
|
|---|
| 971 | if (!cont->WriteEnv(env, prefix, print))
|
|---|
| 972 | return kFALSE;
|
|---|
| 973 | return kTRUE;
|
|---|
| 974 | }
|
|---|
| 975 |
|
|---|
| 976 | // --------------------------------------------------------------------------
|
|---|
| 977 | //
|
|---|
| 978 | // Can be used to create an iterator over all containers, eg:
|
|---|
| 979 | // MParList plist;
|
|---|
| 980 | // TIter Next(plist); // Be aware: Use a object here rather than a pointer!
|
|---|
| 981 | // TObject *o=0;
|
|---|
| 982 | // while ((o=Next()))
|
|---|
| 983 | // {
|
|---|
| 984 | // [...]
|
|---|
| 985 | // }
|
|---|
| 986 | //
|
|---|
| 987 | MParList::operator TIterator*() const
|
|---|
| 988 | {
|
|---|
| 989 | return new TOrdCollectionIter(fContainer);
|
|---|
| 990 | }
|
|---|