Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRootObject.hh
Go to the documentation of this file.
1 #ifndef __JGIZMO__JROOTOBJECT__
2 #define __JGIZMO__JROOTOBJECT__
3 
4 #include <string>
5 
6 #include "TObject.h"
7 #include "TString.h"
8 
9 #include "JLang/JPointer.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JGIZMO {}
17 namespace JPP { using namespace JGIZMO; }
18 
19 namespace JGIZMO {
20 
21  static const char LABEL_TERMINATOR = '&'; //!< label terminator
22 
23 
24  /**
25  * Auxiliary data structure for TObject with a user defined label.
26  */
27  class JRootObject :
28  public JLANG::JPointer<TObject>
29  {
30  public:
31  /**
32  * Constructor.
33  *
34  * \param __p pointer to object
35  */
37  JLANG::JPointer<TObject>(__p)
38  {
39  label = get()->GetName();
40  }
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param __p pointer to object
47  * \param __label label
48  */
50  const TString& __label):
51  JLANG::JPointer<TObject>(__p)
52  {
53  this->label = __label;
54  }
55 
56 
57  /**
58  * Get label.
59  *
60  * \return label
61  */
62  TString getLabel() const
63  {
64  TString buffer(this->label);
65 
66  const Ssiz_t pos = buffer.Last(LABEL_TERMINATOR);
67 
68  if (pos != kNPOS) {
69  buffer = buffer(0, pos);
70  }
71 
72  return buffer;
73  }
74 
75 
76  /**
77  * Set label.
78  *
79  * \param label label
80  */
81  void setLabel(const TString& label)
82  {
83  this->label = label;
84  }
85 
86 
87  /**
88  * Draw object.
89  */
90  void Draw(const std::string& option) const
91  {
92  this->get()->Draw(option.c_str());
93  }
94 
95  protected:
96  TString label;
97  };
98 }
99 
100 #endif
TObject * __p
pointer to object
Definition: JPointer.hh:136
Definition: JRoot.hh:19
JRootObject(TObject *__p)
Constructor.
Definition: JRootObject.hh:36
Auxiliary data structure for TObject with a user defined label.
Definition: JRootObject.hh:27
Template implementation of class that holds pointer to object(s).
Definition: JPointer.hh:22
JRootObject(TObject *__p, const TString &__label)
Constructor.
Definition: JRootObject.hh:49
static const char LABEL_TERMINATOR
label terminator
Definition: JRootObject.hh:21
void Draw(const std::string &option) const
Draw object.
Definition: JRootObject.hh:90
TString getLabel() const
Get label.
Definition: JRootObject.hh:62
void setLabel(const TString &label)
Set label.
Definition: JRootObject.hh:81