Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:18

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooArgList.h,v 1.14 2007/05/11 09:11:30 verkerke Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_ARG_LIST
0017 #define ROO_ARG_LIST
0018 
0019 #include "RooAbsCollection.h"
0020 
0021 
0022 class RooArgList : public RooAbsCollection {
0023 public:
0024 
0025   // Constructors, assignment etc.
0026   RooArgList();
0027   RooArgList(const RooAbsCollection& coll) ;
0028   explicit RooArgList(const TCollection& tcoll, const char* name="") ;
0029   explicit RooArgList(const char *name);
0030   /// Construct a (non-owning) RooArgList from one or more
0031   /// RooFit objects.
0032   /// \param arg A RooFit object to be put in the set.
0033   ///            Note that you can also pass a `double` as first argument
0034   ///            when constructing a RooArgList, and another templated
0035   ///            constructor will be used where a RooConstVar is implicitly
0036   ///            created from the `double` value.
0037   /// \param moreArgsOrName Arbitrary number of
0038   ///   - RooFit objects deriving from RooAbsArg.
0039   ///   - `double`s from which a RooConstVar is implicitly created via `RooFit::RooConst`.
0040   ///   - A c-string to name the set.
0041 
0042   template<typename... Args_t>
0043   RooArgList(RooAbsArg const& arg, Args_t &&... moreArgsOrName)
0044   /*NB: Making this a delegating constructor led to linker errors with MSVC*/
0045   {
0046     // This constructor should cause a failed static_assert if any of the input
0047     // arguments is a temporary (r-value reference), which will be checked in
0048     // processArg. This works statically because of the universal reference
0049     // mechanism with templated functions.
0050     // Unfortunately, we can't check the first arg, because it's type can't be
0051     // a template parameter and hence a universal reference can't be used.
0052     // This problem is solved by introducing another templated constructor below,
0053     // which accepts a RooAbsArg && as the first argument which is forwarded to
0054     // be the second argument for this constructor.
0055     processArgs(arg, std::forward<Args_t>(moreArgsOrName)...);
0056   }
0057 
0058   /// This constructor will provoke a `static_assert`, because passing a
0059   /// RooAbsArg as r-value reference is not allowed.
0060   template<typename... Args_t>
0061   RooArgList(RooAbsArg && arg, Args_t &&... moreArgsOrName)
0062     : RooArgList{arg, std::move(arg), std::forward<Args_t>(moreArgsOrName)...} {}
0063 
0064   template<typename... Args_t>
0065   explicit RooArgList(double arg, Args_t &&... moreArgsOrName) {
0066     processArgs(arg, std::forward<Args_t>(moreArgsOrName)...);
0067   }
0068 
0069   /// Construct from iterators.
0070   /// \tparam Iterator_t An iterator pointing to RooFit objects or pointers/references thereof.
0071   /// \param beginIt Iterator to first element to add.
0072   /// \param endIt Iterator to end of range to be added.
0073   /// \param name Optional name of the collection.
0074   template<typename Iterator_t,
0075       typename value_type = typename std::remove_pointer<typename std::iterator_traits<Iterator_t>::value_type>,
0076       typename = std::enable_if<std::is_convertible<const value_type*, const RooAbsArg*>::value> >
0077   RooArgList(Iterator_t beginIt, Iterator_t endIt, const char* name="") :
0078   RooArgList(name) {
0079     for (auto it = beginIt; it != endIt; ++it) {
0080       processArg(*it);
0081     }
0082   }
0083 
0084   /// Construct a non-owning RooArgList from a vector of RooAbsArg pointers.
0085   /// This constructor is mainly intended for pyROOT. With cppyy, a Python list
0086   /// or tuple can be implicitly converted to an std::vector, and by enabling
0087   /// implicit construction of a RooArgList from a std::vector, we indirectly
0088   /// enable implicit conversion from a Python list/tuple to RooArgLists.
0089   /// \param vec A vector with pointers to the arguments or doubles for RooFit::RooConst().
0090   RooArgList(std::vector<RooAbsArgPtrOrDouble> const& vec) {
0091     for(auto const& arg : vec) {
0092       if(arg.hasPtr) processArg(arg.ptr);
0093       else processArg(arg.val);
0094     }
0095   }
0096 
0097   ~RooArgList() override;
0098   // Create a copy of an existing list. New variables cannot be added
0099   // to a copied list. The variables in the copied list are independent
0100   // of the original variables.
0101   RooArgList(const RooArgList& other, const char *name="");
0102   /// Move constructor.
0103   RooArgList(RooArgList && other) : RooAbsCollection(std::move(other)) {}
0104   TObject* clone(const char* newname) const override { return new RooArgList(*this,newname); }
0105   TObject* create(const char* newname) const override { return new RooArgList(newname); }
0106   RooArgList& operator=(const RooArgList& other) { RooAbsCollection::operator=(other) ; return *this ; }
0107 
0108 
0109   /// Return object at given index, or nullptr if index is out of range
0110   inline RooAbsArg* at(Int_t idx) const {
0111 
0112     if (idx >= static_cast<Int_t>(_list.size()))
0113       return nullptr;
0114 
0115     return _list[idx];
0116   }
0117 
0118   // I/O streaming interface (machine readable)
0119   virtual bool readFromStream(std::istream& is, bool compact, bool verbose=false);
0120   virtual void writeToStream(std::ostream& os, bool compact);
0121 
0122   /// Access element by index.
0123   RooAbsArg& operator[](Int_t idx) const {
0124     assert(0 <= idx && idx < static_cast<Int_t>(_list.size()));
0125     return *_list[idx];
0126   }
0127 
0128 protected:
0129   bool canBeAdded(RooAbsArg const&, bool) const override  { return true; }
0130 
0131 private:
0132   template<typename... Args_t>
0133   void processArgs(Args_t &&... args) {
0134     // Expand parameter pack in C++ 11 way:
0135     int dummy[] = { 0, (processArg(std::forward<Args_t>(args)), 0) ... };
0136     (void)dummy;
0137   }
0138   void processArg(const RooAbsArg& arg) { add(arg); }
0139   void processArg(const RooAbsArg* arg) { add(*arg); }
0140   void processArg(RooAbsArg* arg) { add(*arg); }
0141   template<class Arg_t>
0142   void processArg(Arg_t && arg) {
0143     assert_is_no_temporary(std::forward<Arg_t>(arg));
0144     add(arg);
0145   }
0146   void processArg(const char* name) { _name = name; }
0147   void processArg(double value);
0148 
0149   ClassDefOverride(RooArgList,1) // Ordered list of RooAbsArg objects
0150 };
0151 
0152 
0153 namespace RooFitShortHand {
0154 
0155 template<class... Args_t>
0156 RooArgList L(Args_t&&... args) {
0157   return {std::forward<Args_t>(args)...};
0158 }
0159 
0160 } // namespace RooFitShortHand
0161 
0162 
0163 #endif