HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hcategorymanager.h
Go to the documentation of this file.
1 #ifndef __HCATEGORYMANAGER_H__
2 #define __HCATEGORYMANAGER_H__
3 
4 
5 
6 #include "hades.h"
7 #include "hrecevent.h"
8 #include "hcategory.h"
9 #include "hlocation.h"
10 
11 #include "TObject.h"
12 #include "TString.h"
13 
14 
15 class HCategoryManager: public TObject
16 {
17 private:
18  static HLocation loc; //!
19 
20 public:
23 
24  static HCategory *getCategory(Short_t num,Int_t warn = 0, TString name = "");
25  static HCategory *addCategory(Short_t num,TString name = "",Int_t size = 1000,TString partev = "", Bool_t dynamicsize = kFALSE);
26 
27  template<class T> static T* getObject(T* pout,Short_t num = -1, Int_t index = -1,Bool_t silent=kFALSE)
28  {
29  // returns object with index index from category with number num.
30  // In error case return 0.
31 
32  HCategory *cat = 0;
33  pout = 0;
34  if (index < 0 || num < 0) { return pout; }
36  if (ev) {
37  cat = ev->getCategory(num);
38  if (!cat) {
39  if(!silent) ::Error("getObject()", "Cannot get category cat num = %i", num);
40  return pout;
41  } else {
42  pout = (T*) cat->getObject(index);
43  if (!pout) {
44  if(!silent) ::Error("getObject()", "ZERO pointer retrieved for object!");
45  return pout;
46  }
47  }
48  } else {
49  ::Error("getObject()", "ZERO pointer retrieved for event!");
50  return pout;
51  }
52  return pout;
53  }
54 
55  template<class T> static T* getObject(T* pout,HCategory* cat = 0, Int_t index = -1,Bool_t silent=kFALSE)
56  {
57  // returns object with index index from category cat.
58  // In error case return 0.
59  pout = 0;
60  if (index < 0 || cat == 0) { return pout; }
61  pout = (T*) cat->getObject(index);
62  if (!pout) {
63  if(!silent) ::Error("getObject()", "ZERO pointer retrieved for object!");
64  return pout;
65  }
66  return pout;
67  }
68 
69  template<class T> static T* newObject(T* pout,Short_t num , Int_t& index)
70  {
71  // returns new object with index index from category with number num.
72  // In error case return 0.
73  HCategory *cat = 0;
74  pout = 0;
75  if (num < 0) { return pout; }
77  if (ev) {
78  cat = ev->getCategory(num);
79  if (!cat) {
80  ::Error("newObject()", "Cannot get category cat num = %i", num);
81  return pout;
82  } else {
83  pout = (T*) cat->getNewSlot(loc,&index);
84  if (!pout) {
85  ::Error("newObject()", "ZERO pointer retrieved for object!");
86  return pout;
87  }
88  pout = new (pout) T;
89  }
90  } else {
91  ::Error("newObject()", "ZERO pointer retrieved for event!");
92  return pout;
93  }
94  return pout;
95  }
96 
97  template<class T> static T* newObject(T* pout,HCategory* cat, Int_t& index)
98  {
99  // returns new object with index index from category cat.
100  // In error case return 0.
101  pout = 0;
102  if (cat == 0) { return pout; }
103 
104  pout = (T*) cat->getNewSlot(loc,&index);
105  if (!pout) {
106  ::Error("newObject()", "ZERO pointer retrieved for object!");
107  return pout;
108  }
109  pout = new (pout) T;
110 
111  return pout;
112  }
113 
114  template<class T> static T* newObject(T* pout,const T* pin,Short_t num , Int_t& index)
115  {
116  // returns new object with index index from category with number num.
117  // the new object is created via copy constructor
118  // In error case return 0.
119  HCategory *cat = 0;
120  pout = 0;
121  if (num < 0) { return pout; }
123  if (ev) {
124  cat = ev->getCategory(num);
125  if (!cat) {
126  ::Error("newObject()", "Cannot get category cat num = %i", num);
127  return pout;
128  } else {
129  pout = (T*) cat->getNewSlot(loc,&index);
130  if (!pout) {
131  ::Error("newObject()", "ZERO pointer retrieved for object!");
132  return pout;
133  }
134  pout = new (pout) T(*pin);
135  }
136  } else {
137  ::Error("newObject()", "ZERO pointer retrieved for event!");
138  return pout;
139  }
140  return pout;
141  }
142 
143  template<class T> static T* newObjectCopy(T* pout,T* pin,HCategory* cat, Int_t& index)
144  {
145  // returns new object with index index from category cat.
146  // created via copy contructor!
147  // In error case return 0.
148  pout = 0;
149  if (cat == 0) { return pout; }
150 
151  pout = (T*) cat->getNewSlot(loc,&index);
152  if (!pout) {
153  ::Error("newObject()", "ZERO pointer retrieved for object!");
154  return pout;
155  }
156  pout = new (pout) T(*pin);
157 
158  return pout;
159  }
160 
161 
162  template<class T> static T* newSlot(T* pout,Short_t num , Int_t& index)
163  {
164  // returns new object pointer (no object yet) with index index from category with number num.
165  // In error case return 0.
166  HCategory *cat = 0;
167  pout = 0;
168  if (num < 0) { return pout; }
170  if (ev) {
171  cat = ev->getCategory(num);
172  if (!cat) {
173  ::Error("getObject()", "Cannot get category cat num = %i", num);
174  return pout;
175  } else {
176  pout = (T*) cat->getNewSlot(loc,&index);
177  if (!pout) {
178  ::Error("getObject()", "ZERO pointer retrieved for object!");
179  return pout;
180  }
181  return pout;
182  }
183  }
184  }
185 
186  template<class T> static T* newSlot(T* pout,HCategory* cat , Int_t& index)
187  {
188  // returns new object pointer (no object yet) with index index from category cat.
189  // In error case return 0.
190  pout = 0;
191  if (cat == 0) { return pout; }
192  pout = (T*) cat->getNewSlot(loc,&index);
193  if (!pout) {
194  ::Error("newSlot()", "ZERO pointer retrieved for object!");
195  return pout;
196  }
197  return pout;
198  }
199 
200  ClassDef(HCategoryManager, 0) // A simple helper object
201 };
202 
203 
204 #endif // __HCATEGORYMANAGER_H__
static HLocation loc
HCategory * getCategory(Cat_t aCat)
Definition: hrecevent.cc:264
HEvent *& getCurrentEvent(void)
Definition: hades.cc:422
static T * newObject(T *pout, const T *pin, Short_t num, Int_t &index)
static T * getObject(T *pout, Short_t num=-1, Int_t index=-1, Bool_t silent=kFALSE)
static HCategory * getCategory(Short_t num, Int_t warn=0, TString name="")
static T * newObject(T *pout, Short_t num, Int_t &index)
static T * newObject(T *pout, HCategory *cat, Int_t &index)
static T * newSlot(T *pout, HCategory *cat, Int_t &index)
Hades * gHades
Definition: hades.cc:1213
static T * newObjectCopy(T *pout, T *pin, HCategory *cat, Int_t &index)
static T * getObject(T *pout, HCategory *cat=0, Int_t index=-1, Bool_t silent=kFALSE)
static HCategory * addCategory(Short_t num, TString name="", Int_t size=1000, TString partev="", Bool_t dynamicsize=kFALSE)
static T * newSlot(T *pout, Short_t num, Int_t &index)