ATLAS Offline Software
MetaObject.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef SAMPLE_HANDLER_META_OBJECT_HH
6 #define SAMPLE_HANDLER_META_OBJECT_HH
7 
8 // - 2012.
9 // Distributed under the Boost Software License, Version 1.0.
10 // (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12 
13 // Please feel free to contact me (krumnack@iastate.edu) for bug
14 // reports, feature suggestions, praise and complaints.
15 
16 
17 
18 #include <SampleHandler/Global.h>
19 #include <RootCoreUtils/Assert.h>
20 
21 #include <string>
22 #include <TCollection.h>
23 
24 namespace SH
25 {
37  std::string dbg (const MetaObject& obj, unsigned verbosity = 0);
38 
39 
46 
47 
48 
55  class MetaObject : public TCollection
56  {
57  //
58  // public interface
59  //
60 
62  public:
63  enum CastMode
64  {
68 
71 
75 
79  };
80 
81 
82 
87  public:
88  void testInvariant () const;
89 
90 
97  public:
99 
100 
107  public:
108  MetaObject (const MetaObject& that);
109 
110 
115  public:
116  virtual ~MetaObject ();
117 
118 
127  public:
129 
130 
135  public:
136  void swap (MetaObject& that);
137 
138 
146  public:
147  void remove (const std::string& name);
148 
149 
160  public:
161  void addReplace (TNamed *meta_swallow);
162 
163 
171  public:
172  TObject *get (const std::string& name);
173  const TObject *get (const std::string& name) const;
174 
175 
186  public:
187  [[deprecated("please use castDouble instead")]]
188  double getDouble (const std::string& name, double def_val = 0) const;
189 
204  public:
205  [[deprecated("please use castString instead")]]
206  std::string getString (const std::string& name, const std::string& def_val = "") const;
207 
208 
219  public:
220  template<class T> T castT(const std::string& name, T def_val,
221  CastMode mode) const;
222 
223 
234  public:
235  double castDouble (const std::string& name, double def_val = 0,
236  CastMode mode = CAST_ERROR_THROW) const;
237 
252  public:
253  std::string castString (const std::string& name, const std::string& def_val = "",
254  CastMode mode = CAST_ERROR_THROW) const;
255 
256 
267  public:
268  int castInteger (const std::string& name, int def_val = 0,
269  CastMode mode = CAST_ERROR_THROW) const;
270 
271 
282  public:
283  bool castBool (const std::string& name, bool def_val = false,
284  CastMode mode = CAST_ERROR_THROW) const;
285 
294  public:
295  void setDouble (const std::string& name, double value);
296 
305  public:
306  void setString (const std::string& name, const std::string& value);
307 
316  public:
317  void setInteger (const std::string& name, int value);
318 
327  public:
328  void setBool (const std::string& name, bool value);
329 
338  public:
339  template<class T> void setT(const std::string& name, T value){
340  RCU_CHANGE_INVARIANT (this);
341  addReplace (new MetaData<T> (name, value));
342  }
343 
357  public:
358  void fetch (const MetaObject& source);
359 
360 
368  public:
370 
371 
383  public:
384  void fetchFromString(const std::string& source);
385 
386 
394  public:
395  std::string dumpToString();
396 
397 
398  //
399  // method inherited from TCollection
400  //
401 
409  public:
410  virtual void Add (TObject *meta_swallow);
411 
412 
417  public:
418  virtual void Clear (Option_t *option = "");
419 
420 
425  public:
426  virtual void Delete (Option_t *option = "");
427 
428 
433  public:
434  virtual Int_t GetEntries () const;
435 
436 
446  public:
447  virtual TObject **GetObjectRef (const TObject *meta) const;
448 
449 
457  public:
458  virtual TIterator *MakeIterator (Bool_t dir = kIterForward) const;
459 
460 
468  public:
469  virtual TObject *Remove (TObject *meta);
470 
471  //
472  // private interface
473  //
474 
476  private:
477  TList *m_dataList;
478 
480  };
481 }
482 
483 #endif
SH::MetaObject::CAST_ERROR_DEFAULT
@ CAST_ERROR_DEFAULT
cast and return the default value if the cast fails
Definition: MetaObject.h:70
SH::MetaObject::CAST_NOCAST_DEFAULT
@ CAST_NOCAST_DEFAULT
cast and return the default value if the input has the wrong type
Definition: MetaObject.h:78
SH::MetaObject
A class that manages meta-data to be associated with an object.
Definition: MetaObject.h:56
SH::MetaObject::MetaObject
MetaObject()
standard constructor
SH::MetaObject::castBool
bool castBool(const std::string &name, bool def_val=false, CastMode mode=CAST_ERROR_THROW) const
the meta-data boolean with the given name
SH::MetaObject::remove
void remove(const std::string &name)
remove all meta-information with the given name
SH::MetaObject::setT
void setT(const std::string &name, T value)
set the meta-data element with the given name
Definition: MetaObject.h:339
SH::MetaObject::GetObjectRef
virtual TObject ** GetObjectRef(const TObject *meta) const
return pointer to pointer of object meta
SH::MetaObject::fetchFromString
void fetchFromString(const std::string &source)
fetch the meta-data from a given string
SH::MetaObject::CAST_ERROR_THROW
@ CAST_ERROR_THROW
cast and throw if the cast fails (not if the input is not found)
Definition: MetaObject.h:67
athena.value
value
Definition: athena.py:124
SH::MetaObject::dumpToString
std::string dumpToString()
dump the meta-data to a string
Assert.h
SH::MetaObject::setBool
void setBool(const std::string &name, bool value)
set the meta-data boolean with the given name
SH::MetaObject::fetch
void fetch(const MetaObject &source)
fetch the meta-data from the given sample.
SH::MetaObject::castInteger
int castInteger(const std::string &name, int def_val=0, CastMode mode=CAST_ERROR_THROW) const
the meta-data integer with the given name
SH::MetaObject::swap
void swap(MetaObject &that)
standard swap
SH::MetaObject::GetEntries
virtual Int_t GetEntries() const
return the number of entries of this collection
SH::MetaObject::CastMode
CastMode
the different modes for casts
Definition: MetaObject.h:64
SH::MetaObject::CAST_NOCAST_THROW
@ CAST_NOCAST_THROW
do not cast and throw if the input has the wrong type (not if the input is not found)
Definition: MetaObject.h:74
SH::MetaObject::getDouble
double getDouble(const std::string &name, double def_val=0) const
the meta-data double with the given name
SH::MetaObject::~MetaObject
virtual ~MetaObject()
standard destructor
SH::MetaObject::operator=
MetaObject & operator=(const MetaObject &that)
standard assignment operator
SH::MetaObject::get
const TObject * get(const std::string &name) const
SH::MetaObject::Add
virtual void Add(TObject *meta_swallow)
add another object to the collection
SH::MetaObject::Delete
virtual void Delete(Option_t *option="")
clear out the content of the collection
Preparation.mode
mode
Definition: Preparation.py:94
SH::MetaObject::castString
std::string castString(const std::string &name, const std::string &def_val="", CastMode mode=CAST_ERROR_THROW) const
the meta-data string with the given name
SH::MetaObject::swap
void swap(MetaObject &a, MetaObject &b)
standard swap
SH::MetaObject::MakeIterator
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
make a new iterator for this collection
SH::MetaObject::addReplace
void addReplace(TNamed *meta_swallow)
add a meta-data object and remove any existing meta-data with the same name
SH::MetaObject::setString
void setString(const std::string &name, const std::string &value)
set the meta-data string with the given name
beamspotman.dir
string dir
Definition: beamspotman.py:623
SH::MetaObject::castT
T castT(const std::string &name, T def_val, CastMode mode) const
the meta-data element with the given name
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SH::MetaObject::setInteger
void setInteger(const std::string &name, int value)
set the meta-data integer with the given name
SH::MetaObject::ClassDef
ClassDef(MetaObject, 1)
covarianceTool.verbosity
verbosity
Definition: covarianceTool.py:513
SH::MetaObject::Remove
virtual TObject * Remove(TObject *meta)
remove the given object from the list
SH::MetaObject::fetchDefaults
void fetchDefaults(const MetaObject &source)
fetch the meta-data from the given sample not present in this sample.
SH::MetaObject::get
TObject * get(const std::string &name)
the meta-data object with the given name
runJobs.deprecated
deprecated
Definition: runJobs.py:191
a
TList * a
Definition: liststreamerinfos.cxx:10
SH::MetaObject::m_dataList
TList * m_dataList
the actual meta-data list
Definition: MetaObject.h:477
SH::MetaData
A class implementing a templatized version of the meta-data.
Definition: D3PDTools/SampleHandler/SampleHandler/Global.h:36
SH::MetaObject::castDouble
double castDouble(const std::string &name, double def_val=0, CastMode mode=CAST_ERROR_THROW) const
the meta-data double with the given name
SH::MetaObject::Clear
virtual void Clear(Option_t *option="")
clear out the content of the collection
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
SH::MetaObject::dbg
std::string dbg(const MetaObject &obj, unsigned verbosity=0)
the debugging info of this object
copySelective.source
string source
Definition: copySelective.py:32
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
SH::MetaObject::testInvariant
void testInvariant() const
test the invariant of this object
python.PyAthena.obj
obj
Definition: PyAthena.py:132
Global.h
SH::MetaObject::getString
std::string getString(const std::string &name, const std::string &def_val="") const
the meta-data string with the given name
SH::MetaObject::setDouble
void setDouble(const std::string &name, double value)
set the meta-data double with the given name
SH::MetaObject::MetaObject
MetaObject(const MetaObject &that)
standard copy constructor