ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id$
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
// 
// RooArgList is a container object that can hold multiple RooAbsArg objects.
// The container has list semantics which means that:
//
//  - Contained objects are ordered, The iterator 
//    follows the object insertion order.
//
//  - Objects can be retrieved by name and index
//
//  - Multiple objects with the same name are allowed
//
// Ownership of contents. 
//
// Unowned objects are inserted with the add() method. Owned objects
// are added with addOwned() or addClone(). A RooArgSet either owns all 
// of it contents, or none, which is determined by the first <add>
// call. Once an ownership status is selected, inappropriate <add> calls
// will return error status. Clearing the list via removeAll() resets the 
// ownership status. Arguments supplied in the constructor are always added 
// as unowned elements.
//
//

#include "RooFit.h"

#include "Riostream.h"
#include "Riostream.h"
#include <iomanip>
#include <fstream>
#include "TClass.h"
#include "RooArgList.h"
#include "RooStreamParser.h"
#include "RooFormula.h"
#include "RooAbsRealLValue.h"
#include "RooAbsCategoryLValue.h"
#include "RooStringVar.h"
#include "RooTrace.h"
#include "RooMsgService.h"

using namespace std;

ClassImp(RooArgList)
  ;


//_____________________________________________________________________________
RooArgList::RooArgList() :
  RooAbsCollection()
{
  // Default constructor
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooArgSet& set) :
  RooAbsCollection(set.GetName())
{
  // Constructor from a RooArgSet. 

  add(set) ;
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const char *name) :
  RooAbsCollection(name)
{
  // Empty list constructor
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1,
		     const char *name) :
  RooAbsCollection(name)
{
  // Constructor for list containing 1 initial object

  add(var1);
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2,
		     const char *name) :
  RooAbsCollection(name)
{
  // Constructor for set containing 2 initial objects

  add(var1); add(var2);
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2, 
		     const RooAbsArg& var3,
		     const char *name) :
  RooAbsCollection(name)
{
  // Constructor for set containing 3 initial objects

  add(var1); add(var2); add(var3);
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2, 
		     const RooAbsArg& var3, const RooAbsArg& var4,
		     const char *name) :
  RooAbsCollection(name)
{
  // Constructor for set containing 4 initial objects

  add(var1); add(var2); add(var3); add(var4);
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1,
		     const RooAbsArg& var2, const RooAbsArg& var3,
		     const RooAbsArg& var4, const RooAbsArg& var5,
		     const char *name) :
  RooAbsCollection(name)
{
  // Constructor for set containing 5 initial objects

  add(var1); add(var2); add(var3); add(var4); add(var5);
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2, 
		     const RooAbsArg& var3, const RooAbsArg& var4, 
		     const RooAbsArg& var5, const RooAbsArg& var6,
		     const char *name) :
  RooAbsCollection(name)
{
  // Constructor for set containing 6 initial objects

  add(var1); add(var2); add(var3); add(var4); add(var5); add(var6);
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2, 
		     const RooAbsArg& var3, const RooAbsArg& var4, 
		     const RooAbsArg& var5, const RooAbsArg& var6, 
		     const RooAbsArg& var7,
		     const char *name) :
  RooAbsCollection(name)
{
  // Constructor for set containing 7 initial objects

  add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2, 
		     const RooAbsArg& var3, const RooAbsArg& var4, 
		     const RooAbsArg& var5, const RooAbsArg& var6, 
		     const RooAbsArg& var7, const RooAbsArg& var8,
		     const char *name) :
  RooAbsCollection(name)
{
  // Constructor for set containing 8 initial objects

  add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;add(var8) ;
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2, 
		     const RooAbsArg& var3, const RooAbsArg& var4, 
		     const RooAbsArg& var5, const RooAbsArg& var6, 
		     const RooAbsArg& var7, const RooAbsArg& var8,
		     const RooAbsArg& var9, const char *name) :
  RooAbsCollection(name)
{
  // Constructor for set containing 9 initial objects

  add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7); add(var8); add(var9);
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const TCollection& tcoll, const char* name) :
  RooAbsCollection(name)
{
  // Constructor from a root TCollection. Elements in the collection that
  // do not inherit from RooAbsArg will be skipped. A warning message
  // will be printed for every skipped item.

  TIterator* iter = tcoll.MakeIterator() ;
  TObject* obj ;
  while((obj=iter->Next())) {
    if (!dynamic_cast<RooAbsArg*>(obj)) {
      coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName() 
			    << " is not a RooAbsArg, ignored" << endl ;
      continue ;
    }
    add(*(RooAbsArg*)obj) ;
  }
  delete iter ;
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::RooArgList(const RooArgList& other, const char *name) 
  : RooAbsCollection(other,name)
{
  // Copy constructor. Note that a copy of a list is always non-owning,
  // even the source list is owning. To create an owning copy of
  // a list (owning or not), use the snaphot() method.
  TRACE_CREATE
}



//_____________________________________________________________________________
RooArgList::~RooArgList() 
{
  // Destructor
  TRACE_DESTROY
}



//_____________________________________________________________________________
RooAbsArg& RooArgList::operator[](Int_t idx) const 
{     
  // Array operator. Element in slot 'idx' must already exist, otherwise
  // code will abort. 
  //
  // When used as lvalue in assignment operations, the element contained in
  // the list will not be changed, only the value of the existing element!

  RooAbsArg* arg = at(idx) ;
  if (!arg) {
    coutE(InputArguments) << "RooArgList::operator[](" << GetName() << ") ERROR: index " 
			  << idx << " out of range (0," << getSize() << ")" << endl ;
    RooErrorHandler::softAbort() ;
  }
  return *arg ; 
}



//_____________________________________________________________________________
void RooArgList::writeToStream(ostream& os, Bool_t compact) 
{
  // Write the contents of the argset in ASCII form to given stream.
  // 
  // All elements will be printed on a single line separated by a single 
  // white space. The contents of each element is written by the arguments' 
  // writeToStream() function

  if (!compact) {
    coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << endl ;
    return ;
  }

  TIterator *iterat= createIterator();
  RooAbsArg *next = 0;
  while((0 != (next= (RooAbsArg*)iterat->Next()))) {
      next->writeToStream(os,kTRUE) ;
      os << " " ;
  }
  delete iterat;  
  os << endl ;
}



//_____________________________________________________________________________
Bool_t RooArgList::readFromStream(istream& is, Bool_t compact, Bool_t verbose) 
{
  // Read the contents of the argset in ASCII form from given stream.
  // 
  // A single line is read, and all elements are assumed to be separated 
  // by white space. The value of each argument is read by the arguments 
  // readFromStream function.

  if (!compact) {
    coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << endl ;
    return kTRUE ;
  }    

  TIterator *iterat= createIterator();
  RooStreamParser parser(is) ;
  RooAbsArg *next = 0;
  while((0 != (next= (RooAbsArg*)iterat->Next()))) {
    if (!next->getAttribute("Dynamic")) {
      if (next->readFromStream(is,kTRUE,verbose)) {
	parser.zapToEnd() ;
	
	delete iterat ;
	return kTRUE ;
      }	
    } else {
    }
  }
  
  if (!parser.atEOL()) {
    TString rest = parser.readLine() ;
    if (verbose) {
      coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName() 
			    << "): ignoring extra characters at end of line: '" << rest << "'" << endl ;
    }
  }
  
  delete iterat;    
  return kFALSE ;  
}

 RooArgList.cxx:1
 RooArgList.cxx:2
 RooArgList.cxx:3
 RooArgList.cxx:4
 RooArgList.cxx:5
 RooArgList.cxx:6
 RooArgList.cxx:7
 RooArgList.cxx:8
 RooArgList.cxx:9
 RooArgList.cxx:10
 RooArgList.cxx:11
 RooArgList.cxx:12
 RooArgList.cxx:13
 RooArgList.cxx:14
 RooArgList.cxx:15
 RooArgList.cxx:16
 RooArgList.cxx:17
 RooArgList.cxx:18
 RooArgList.cxx:19
 RooArgList.cxx:20
 RooArgList.cxx:21
 RooArgList.cxx:22
 RooArgList.cxx:23
 RooArgList.cxx:24
 RooArgList.cxx:25
 RooArgList.cxx:26
 RooArgList.cxx:27
 RooArgList.cxx:28
 RooArgList.cxx:29
 RooArgList.cxx:30
 RooArgList.cxx:31
 RooArgList.cxx:32
 RooArgList.cxx:33
 RooArgList.cxx:34
 RooArgList.cxx:35
 RooArgList.cxx:36
 RooArgList.cxx:37
 RooArgList.cxx:38
 RooArgList.cxx:39
 RooArgList.cxx:40
 RooArgList.cxx:41
 RooArgList.cxx:42
 RooArgList.cxx:43
 RooArgList.cxx:44
 RooArgList.cxx:45
 RooArgList.cxx:46
 RooArgList.cxx:47
 RooArgList.cxx:48
 RooArgList.cxx:49
 RooArgList.cxx:50
 RooArgList.cxx:51
 RooArgList.cxx:52
 RooArgList.cxx:53
 RooArgList.cxx:54
 RooArgList.cxx:55
 RooArgList.cxx:56
 RooArgList.cxx:57
 RooArgList.cxx:58
 RooArgList.cxx:59
 RooArgList.cxx:60
 RooArgList.cxx:61
 RooArgList.cxx:62
 RooArgList.cxx:63
 RooArgList.cxx:64
 RooArgList.cxx:65
 RooArgList.cxx:66
 RooArgList.cxx:67
 RooArgList.cxx:68
 RooArgList.cxx:69
 RooArgList.cxx:70
 RooArgList.cxx:71
 RooArgList.cxx:72
 RooArgList.cxx:73
 RooArgList.cxx:74
 RooArgList.cxx:75
 RooArgList.cxx:76
 RooArgList.cxx:77
 RooArgList.cxx:78
 RooArgList.cxx:79
 RooArgList.cxx:80
 RooArgList.cxx:81
 RooArgList.cxx:82
 RooArgList.cxx:83
 RooArgList.cxx:84
 RooArgList.cxx:85
 RooArgList.cxx:86
 RooArgList.cxx:87
 RooArgList.cxx:88
 RooArgList.cxx:89
 RooArgList.cxx:90
 RooArgList.cxx:91
 RooArgList.cxx:92
 RooArgList.cxx:93
 RooArgList.cxx:94
 RooArgList.cxx:95
 RooArgList.cxx:96
 RooArgList.cxx:97
 RooArgList.cxx:98
 RooArgList.cxx:99
 RooArgList.cxx:100
 RooArgList.cxx:101
 RooArgList.cxx:102
 RooArgList.cxx:103
 RooArgList.cxx:104
 RooArgList.cxx:105
 RooArgList.cxx:106
 RooArgList.cxx:107
 RooArgList.cxx:108
 RooArgList.cxx:109
 RooArgList.cxx:110
 RooArgList.cxx:111
 RooArgList.cxx:112
 RooArgList.cxx:113
 RooArgList.cxx:114
 RooArgList.cxx:115
 RooArgList.cxx:116
 RooArgList.cxx:117
 RooArgList.cxx:118
 RooArgList.cxx:119
 RooArgList.cxx:120
 RooArgList.cxx:121
 RooArgList.cxx:122
 RooArgList.cxx:123
 RooArgList.cxx:124
 RooArgList.cxx:125
 RooArgList.cxx:126
 RooArgList.cxx:127
 RooArgList.cxx:128
 RooArgList.cxx:129
 RooArgList.cxx:130
 RooArgList.cxx:131
 RooArgList.cxx:132
 RooArgList.cxx:133
 RooArgList.cxx:134
 RooArgList.cxx:135
 RooArgList.cxx:136
 RooArgList.cxx:137
 RooArgList.cxx:138
 RooArgList.cxx:139
 RooArgList.cxx:140
 RooArgList.cxx:141
 RooArgList.cxx:142
 RooArgList.cxx:143
 RooArgList.cxx:144
 RooArgList.cxx:145
 RooArgList.cxx:146
 RooArgList.cxx:147
 RooArgList.cxx:148
 RooArgList.cxx:149
 RooArgList.cxx:150
 RooArgList.cxx:151
 RooArgList.cxx:152
 RooArgList.cxx:153
 RooArgList.cxx:154
 RooArgList.cxx:155
 RooArgList.cxx:156
 RooArgList.cxx:157
 RooArgList.cxx:158
 RooArgList.cxx:159
 RooArgList.cxx:160
 RooArgList.cxx:161
 RooArgList.cxx:162
 RooArgList.cxx:163
 RooArgList.cxx:164
 RooArgList.cxx:165
 RooArgList.cxx:166
 RooArgList.cxx:167
 RooArgList.cxx:168
 RooArgList.cxx:169
 RooArgList.cxx:170
 RooArgList.cxx:171
 RooArgList.cxx:172
 RooArgList.cxx:173
 RooArgList.cxx:174
 RooArgList.cxx:175
 RooArgList.cxx:176
 RooArgList.cxx:177
 RooArgList.cxx:178
 RooArgList.cxx:179
 RooArgList.cxx:180
 RooArgList.cxx:181
 RooArgList.cxx:182
 RooArgList.cxx:183
 RooArgList.cxx:184
 RooArgList.cxx:185
 RooArgList.cxx:186
 RooArgList.cxx:187
 RooArgList.cxx:188
 RooArgList.cxx:189
 RooArgList.cxx:190
 RooArgList.cxx:191
 RooArgList.cxx:192
 RooArgList.cxx:193
 RooArgList.cxx:194
 RooArgList.cxx:195
 RooArgList.cxx:196
 RooArgList.cxx:197
 RooArgList.cxx:198
 RooArgList.cxx:199
 RooArgList.cxx:200
 RooArgList.cxx:201
 RooArgList.cxx:202
 RooArgList.cxx:203
 RooArgList.cxx:204
 RooArgList.cxx:205
 RooArgList.cxx:206
 RooArgList.cxx:207
 RooArgList.cxx:208
 RooArgList.cxx:209
 RooArgList.cxx:210
 RooArgList.cxx:211
 RooArgList.cxx:212
 RooArgList.cxx:213
 RooArgList.cxx:214
 RooArgList.cxx:215
 RooArgList.cxx:216
 RooArgList.cxx:217
 RooArgList.cxx:218
 RooArgList.cxx:219
 RooArgList.cxx:220
 RooArgList.cxx:221
 RooArgList.cxx:222
 RooArgList.cxx:223
 RooArgList.cxx:224
 RooArgList.cxx:225
 RooArgList.cxx:226
 RooArgList.cxx:227
 RooArgList.cxx:228
 RooArgList.cxx:229
 RooArgList.cxx:230
 RooArgList.cxx:231
 RooArgList.cxx:232
 RooArgList.cxx:233
 RooArgList.cxx:234
 RooArgList.cxx:235
 RooArgList.cxx:236
 RooArgList.cxx:237
 RooArgList.cxx:238
 RooArgList.cxx:239
 RooArgList.cxx:240
 RooArgList.cxx:241
 RooArgList.cxx:242
 RooArgList.cxx:243
 RooArgList.cxx:244
 RooArgList.cxx:245
 RooArgList.cxx:246
 RooArgList.cxx:247
 RooArgList.cxx:248
 RooArgList.cxx:249
 RooArgList.cxx:250
 RooArgList.cxx:251
 RooArgList.cxx:252
 RooArgList.cxx:253
 RooArgList.cxx:254
 RooArgList.cxx:255
 RooArgList.cxx:256
 RooArgList.cxx:257
 RooArgList.cxx:258
 RooArgList.cxx:259
 RooArgList.cxx:260
 RooArgList.cxx:261
 RooArgList.cxx:262
 RooArgList.cxx:263
 RooArgList.cxx:264
 RooArgList.cxx:265
 RooArgList.cxx:266
 RooArgList.cxx:267
 RooArgList.cxx:268
 RooArgList.cxx:269
 RooArgList.cxx:270
 RooArgList.cxx:271
 RooArgList.cxx:272
 RooArgList.cxx:273
 RooArgList.cxx:274
 RooArgList.cxx:275
 RooArgList.cxx:276
 RooArgList.cxx:277
 RooArgList.cxx:278
 RooArgList.cxx:279
 RooArgList.cxx:280
 RooArgList.cxx:281
 RooArgList.cxx:282
 RooArgList.cxx:283
 RooArgList.cxx:284
 RooArgList.cxx:285
 RooArgList.cxx:286
 RooArgList.cxx:287
 RooArgList.cxx:288
 RooArgList.cxx:289
 RooArgList.cxx:290
 RooArgList.cxx:291
 RooArgList.cxx:292
 RooArgList.cxx:293
 RooArgList.cxx:294
 RooArgList.cxx:295
 RooArgList.cxx:296
 RooArgList.cxx:297
 RooArgList.cxx:298
 RooArgList.cxx:299
 RooArgList.cxx:300
 RooArgList.cxx:301
 RooArgList.cxx:302
 RooArgList.cxx:303
 RooArgList.cxx:304
 RooArgList.cxx:305
 RooArgList.cxx:306
 RooArgList.cxx:307
 RooArgList.cxx:308
 RooArgList.cxx:309
 RooArgList.cxx:310
 RooArgList.cxx:311
 RooArgList.cxx:312
 RooArgList.cxx:313
 RooArgList.cxx:314
 RooArgList.cxx:315
 RooArgList.cxx:316
 RooArgList.cxx:317
 RooArgList.cxx:318
 RooArgList.cxx:319
 RooArgList.cxx:320
 RooArgList.cxx:321
 RooArgList.cxx:322
 RooArgList.cxx:323
 RooArgList.cxx:324
 RooArgList.cxx:325
 RooArgList.cxx:326
 RooArgList.cxx:327
 RooArgList.cxx:328
 RooArgList.cxx:329
 RooArgList.cxx:330
 RooArgList.cxx:331
 RooArgList.cxx:332
 RooArgList.cxx:333
 RooArgList.cxx:334
 RooArgList.cxx:335
 RooArgList.cxx:336
 RooArgList.cxx:337
 RooArgList.cxx:338
 RooArgList.cxx:339
 RooArgList.cxx:340
 RooArgList.cxx:341
 RooArgList.cxx:342
 RooArgList.cxx:343
 RooArgList.cxx:344
 RooArgList.cxx:345
 RooArgList.cxx:346
 RooArgList.cxx:347
 RooArgList.cxx:348
 RooArgList.cxx:349
 RooArgList.cxx:350
 RooArgList.cxx:351
 RooArgList.cxx:352
 RooArgList.cxx:353
 RooArgList.cxx:354
 RooArgList.cxx:355
 RooArgList.cxx:356
 RooArgList.cxx:357
 RooArgList.cxx:358