16#include <TCollection.h>
21#include <TSeqCollection.h>
25 fArrayObjects =
new TObjArray(1);
26 fArrayObjects->SetName(
"ArrayObjects");
27 fArrayObjects->SetOwner(kTRUE);
29 fNameClass = (
"Hal::Package");
35 fArrayObjects =
new TObjArray(1);
36 fArrayObjects->SetName(
"ArrayObjects");
37 fArrayObjects->SetOwner(kTRUE);
39 fNameClass = (
object->ClassName());
41 TString temp = fNameClass.String();
42 TPRegexp regs(
"[A-z,0-9,:]+");
43 TString temp2 = temp(regs);
44 fNameClass.SetString(temp2);
53 if (i < fNo && i >= 0)
54 return fArrayObjects->At(i);
56 Cout::PrintInfo(
"No object at such index in Hal::Package", Hal::EInfo::kWarning);
69 for (Int_t i = 0; i < fNo; i++) {
70 TString temp_name = ((fArrayObjects->At(i))->
GetName());
71 if (name.EqualTo(temp_name)) {
73 if (counter > index)
return fArrayObjects->At(i);
77 Cout::PrintInfo(Form(
"object named %s not found in package %s", name.Data(), (fNameClass.GetString()).Data()),
78 Hal::EInfo::kLowWarning);
82 void Package::PrintInfo(Int_t counter, Int_t deep)
const {
85 Cout::ShiftInStars(deep, Form(
"ClassName : %s", (fNameClass.GetString()).Data()), kGreen);
86 Cout::ShiftText(deep, Form(
"Comment : %s", fComment.GetString().Data()),
"L");
89 for (Int_t i = 0; i < fNo; i++) {
90 TString index = Hal::Std::RoundToString(i);
91 TString type = (fArrayObjects->At(i))->ClassName();
92 TString name = (fArrayObjects->At(i))->GetName();
96 if (counter >= deep) {
98 for (
int i = 0; i < fNo; i++) {
99 TString index = Hal::Std::RoundToString(i);
100 TString type = (fArrayObjects->At(i))->ClassName();
101 TString name = (fArrayObjects->At(i))->GetName();
102 if (type ==
"TList") {
103 TList* list = (TList*) fArrayObjects->At(i);
106 for (
int j = 0; j <= list->LastIndex(); j++) {
107 if (list->At(j)->ClassName() == this->ClassName()) {
109 ((
Package*) list->At(j))->PrintInfo(counter, deep + 1);
112 TString Index = Hal::Std::RoundToString(j);
113 TString Type = list->At(j)->ClassName();
114 TString Name = list->At(j)->GetName();
120 }
else if (name == this->ClassName()) {
122 ((
Package*) fArrayObjects->At(i))->PrintInfo(counter, deep + 1);
126 Cout::ShiftInStars(deep, Form(
"End of %s package", fNameClass.GetString().Data()), kCyan);
134 for (Int_t i = 0; i < fNo; i++) {
142 void Package::SumHalParameter(TObject* first,
const TObject* second) {
143 TString name = first->ClassName();
147 void Package::SumHistograms(TObject* first,
const TObject* second) {
148 TString name = first->ClassName();
149 ((TH1*) first)->Add((TH1*) second);
152 void Package::SumOther(TObject* first,
const TObject* second) {
154 Cout::PrintInfo(Form(
"For class %s %s", second->ClassName(), first->ClassName()), Hal::EInfo::kLowWarning);
157 void Package::SumPackages(TObject* first,
const TObject* second) { ((
Package*) first)->Add((
Package*) second); }
159 void Package::SumList(TObject* first,
const TObject* second) {
160 TList* fst = (TList*) first;
161 TList* sec = (TList*) second;
162 for (
int i = 0; i < fst->GetEntries(); i++) {
163 MergeObjects(fst->At(i), sec->At(i));
171 for (Int_t i = 0; i < fNo; i++) {
172 TString namet = (fArrayObjects->At(i))->ClassName();
173 if (name.EqualTo(namet)) {
175 if (counter > index)
return fArrayObjects->At(i);
179 Cout::PrintInfo(Form(
"class %s not found in package %s", name.Data(), (fNameClass.GetString()).Data()), Hal::EInfo::kWarning);
183 void Package::SumPack(TObject* first,
const TObject* second) { ((
Object*) first)->Add((
Object*) second); }
185 void Package::SumTObjString(TObject* first,
const TObject* second) {
186 TString stringA = ((TObjString*) first)->GetString();
187 TString stringB = ((TObjString*) second)->GetString();
188 if (stringA.EqualTo(stringB)) {
191 Cout::PrintInfo(Form(
"TObjString not compatible (%s vs %s", stringA.Data(), stringB.Data()), Hal::EInfo::kLowWarning);
197 for (
int i = 0; i < fArrayObjects->GetEntries(); i++) {
198 TObject* obj = fArrayObjects->At(i);
199 b->Add(obj, obj->GetName());
204 Package::~Package() {
205 fArrayObjects->Delete();
206 delete fArrayObjects;
210 if (
object != NULL) {
211 fArrayObjects->AddLast(
object);
214 Cout::PrintInfo(
"Cannot add NULL object to Hal::Package", Hal::EInfo::kError);
219 if (this->fNameClass.GetString().EqualTo(rhs.fNameClass.GetString())) {
220 Cout::PrintInfo(
"Trying to merging incompatibile Hal::Packages ! This can result in "
222 Hal::EInfo::kLowWarning);
224 for (Int_t i = 0; i < fNo; i++) {
225 MergeObjects(this->fArrayObjects->At(i), rhs.fArrayObjects->At(i));
227 this->fNo += rhs.fNo;
231 void Package::MergeObjects(TObject* first,
const TObject* second) {
232 TString name = first->ClassName();
233 TString name2 = second->ClassName();
235 Cout::PrintInfo(Form(
"No compatybile classes %s %s", first->ClassName(), second->ClassName()), Hal::EInfo::kCriticalError);
237 if (name ==
"Hal::Package") {
238 SumPackages(first, second);
239 }
else if (first->InheritsFrom(
"TH1")) {
240 SumHistograms(first, second);
241 }
else if ((first->InheritsFrom(
"Hal::Parameter"))) {
242 SumHalParameter(first, second);
243 }
else if (name ==
"TList") {
244 SumList(first, second);
245 }
else if (first->InheritsFrom(
"Hal::Object")) {
246 SumPack(first, second);
247 }
else if (name.EqualTo(
"TObjString")) {
248 SumTObjString(first, second);
250 SumOther(first, second);
255 if (this->fNameClass.GetString().EqualTo(pack->fNameClass.GetString())) {
257 Cout::PrintInfo(
"Trying to merging incompatibile Hal::Packages ! This can result in "
259 Hal::EInfo::kLowWarning);
261 if (this->fNo != pack->fNo) {
262 Cout::PrintInfo(
"Different number of object in Hal::PackageArray this may result in "
264 Hal::EInfo::kLowWarning);
266 for (Int_t i = 0; i < fNo; i++) {
267 TString name = (fArrayObjects->At(i)->ClassName());
268 MergeObjects(this->fArrayObjects->At(i), pack->fArrayObjects->At(i));
270 this->fMerged += pack->fMerged;
273 void Package::PrintInfo(Int_t max_deep)
const { PrintInfo(max_deep - 1, 0); }
277 for (
int i = 0; i < I; i++) {
280 TString final_text = Form(
"%s %s No [%i]", text.Data(), this->ClassName(), Index);
281 if (Index < 0) Index = 0;
283 for (Int_t i = 0; i < fNo; i++) {
284 TString index = Hal::Std::RoundToString(i);
285 TString type = (fArrayObjects->At(i))->ClassName();
286 TString name = (fArrayObjects->At(i))->GetName();
287 if (name == this->ClassName()) { ((
Package*) fArrayObjects->At(i))->PrintStruct(I + 1, i); }
301 TString option = opt;
304 for (Int_t i = 0; i < fNo; i++) {
305 TString temp_name = (TString)((fArrayObjects->At(i))->GetName());
306 if (name.EqualTo(temp_name)) {
308 if (counter > index)
return kTRUE;
311 }
else if (option ==
"index") {
312 if (index < fNo && index >= 0)
return kTRUE;
313 }
else if (option ==
"classname") {
315 for (Int_t i = 0; i < fNo; i++) {
316 TString namet = (fArrayObjects->At(i))->ClassName();
317 if (name.EqualTo(namet)) {
319 if (counter > index)
return kTRUE;
322 }
else if (option ==
"name") {
323 for (Int_t i = 0; i < fNo; i++) {
324 TString temp_name = (TString)((fArrayObjects->At(i))->GetName());
325 if (name.EqualTo(temp_name)) {
return kTRUE; }
334 for (Int_t i = 0; i < fNo; i++) {
335 TString temp_name = ((fArrayObjects->At(i))->
GetName());
336 if (name.EqualTo(temp_name)) {
338 if (counter > index) {
339 obj = fArrayObjects->RemoveAt(i);
341 fArrayObjects->Compress();
345 if (obj && remove) {
delete obj; }
351 TIter iterator(collection);
352 while ((pack = (
Package*) iterator())) {
static void Text(TString text, TString option="L", Color_t color=-1)
static void PrintInfo(TString text, Hal::EInfo status)
static void Stars(Color_t color=-1)
static void ShiftDatabase(Int_t shift, Int_t no...)
static void ShiftInStars(Int_t shift, TString text, Color_t color=-1)
static void ShiftText(Int_t shift, TString text, TString option, Color_t color=-1)
Bool_t Exist(TString name, Int_t index=0, Option_t *opt=" ") const
TObject * GetObject(Int_t i) const
virtual Long64_t Merge(TCollection *collection)
void RemoveObjectByName(TString name, Int_t index=0, Bool_t delete_obj=kTRUE)
void SetAdditionalCounter(Int_t counter)
TString GetComment() const
TObject * GetObjectByName(TString name, Int_t index=0, Bool_t quited=kFALSE) const
void Add(const Package *pack)
Package & operator+(const Package &rhs)
TObject * GetObjectByClassName(TString name, Int_t index=0) const
const char * GetName() const
void SetComment(TString name)
void SetName(TString name)
virtual void Browse(TBrowser *b)
void AddObject(TObject *object)