KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVSeqCollection.cpp
1//Created by KVClassFactory on Fri Jun 19 18:51:28 2009
2//Author: John Frankland,,,
3
4#include "KVSeqCollection.h"
5#include "TClass.h"
6#include "TROOT.h"
7#include "KVBase.h"
8#include "TMethodCall.h"
9#include "Riostream.h"
10#include "TKey.h"
11
12#include <THashList.h>
13#include <TObjString.h>
14
15using namespace std;
16
18
19
20
24
25
30
32{
33 // Default initialisation called by ctors
34 // Make sure all lists have individual names to ensure rapid look-up
35 // in fgCleanups which is a THashList
36
37 SetName(Form("KVSeqCollection_%lld", fSCCounter));
38 fSCCounter++;//always increases, so names are different
39 ++fgCounter;//decreased by dtor, counts instances
40 if (!fgCleanups) {
42 fgCleanups->SetName("KVSeqCollection_Cleanups");
43 gROOT->GetListOfCleanups()->Add(fgCleanups);
44 }
45}
46
47
48
51
53{
54 // Default constructor
55 fCollection = 0;
57 init();
58}
59
60
61
65
68{
69 // Copy constructor
70 // See KVSeqCollection::Copy
71
73 col.Copy(*this);
74 init();
76}
77
78
79
83
84KVSeqCollection::KVSeqCollection(const Char_t* collection_classname)
85{
86 // Create new extended collection of class "collection_classname".
87 // Must be the name of a class derived from TSeqCollection.
88
89 fCollection = 0;
90 SetCollection(collection_classname);
91 if (!fCollection) MakeZombie();
93 init();
95}
96
97
98
102
104{
105 // Create TSeqCollection-derived object of class 'class_name'
106 // and set as the embedded collection fCollection.
107 TClass* cl = TClass::GetClass(class_name);
108 if (!cl) {
109 Error("SetCollection(const Char_t*)", "Called for unknown class: %s",
110 class_name);
111 return;
112 }
113 if (!cl->InheritsFrom("TSeqCollection")) {
114 Error("SetCollection(const Char_t*)",
115 "Called for class %s which does not inherit from TSeqCollection",
116 class_name);
117 return;
118 }
119 fCollection = (TSeqCollection*)cl->New();
120 // if name of KVSeqCollection has already been set (i.e. if this is not
121 // being called by one of the constructors), we set the name of the
122 // embedded TSeqCollection object
123 if (strcmp(GetName(), "KVSeqCollection"))
125}
126
127
128
133
135{
136 // Destructor
137 // If the cleanup mechanism is in use, we first remove the list from
138 // the list of cleanups
139
140 if (IsCleanup()) {
141 while (fgCleanups->Remove(this))
142 ;
143 }
144 if (fCollection && !IsOwner()) {
145 // ROOT6: when Clear() is called for a TList/THashList containing invalid pointers
146 // (i.e. addresses of previously deleted objects), even if the list is not the owner
147 // of the objects (i.e. the Clear() should not attempt to delete anything), then
148 // calling Clear() without the option "nodelete" leads to false-positive warnings
149 // like this: Error in <***::Clear>: A list is accessing an object (0x5632b51c08b0) already deleted...
150 // As the TList and THashList destructors contain a call to their Clear() method,
151 // here we pre-emptively Clear("nodelete") the collection before deleting it
152 fCollection->Clear("nodelete");
153 }
155 --fgCounter;//decrease instance count
156 if (fgCounter == 0 && fgCleanups) {
157 // delete cleanups list if this is the last KVSeqCollection
158 while (gROOT->GetListOfCleanups()->Remove(fgCleanups))
159 ;
160 fgCleanups->Clear();
161 delete fgCleanups;
162 fgCleanups = NULL;
163 }
164}
165
166
167
181
183{
184 // Copy a list of objects.
185 //
186 // The name of the list is only copied if the list is not IsCleanup().
187 // Cleanup lists must have unique names otherwise the THashList which contains them cannot function correctly.
188 //
189 // If this list owns its objects, we make new Clones of all objects in the list
190 // (N.B. the Clone() method must work correctly for the objects in question)
191 // and put them in the copy list, the copy will own these new objects.
192 //
193 // Copy will have same IsOwner() and IsCleanup() status as this list.
194 //
195 // If this list sends Modified() signal, the copy will do too.
196
197 TSeqCollection::Copy(obj); //in fact this calls TObject::Copy, no Copy method defined for collection classes
198 KVSeqCollection& copy = (KVSeqCollection&) obj;
199
200 // if the list is to be placed in the list of cleanups, it must have
201 // a unique name. otherwise the name of the list can be copied.
202 if (!IsCleanup()) copy.SetName(GetName());
203
204 //clear any pre-existing objects in copy list
205 if (copy.IsOwner()) copy.Delete();
206 else copy.Clear();
207
208 //set ownership
209 copy.SetOwner(IsOwner());
210 //set cleanup status
211 copy.SetCleanup(IsCleanup());
212 //set signal&slot status
214
215 //copy or clone list members
216 TObject* b;
217 TIter next(fCollection);
218 while ((b = next())) {
219 if (IsOwner())
220 copy.Add(b->Clone());
221 else
222 copy.Add(b);
223 }
224}
225
226
227
229
231{
232 if (&c != this) { // check for self-assignment
233 c.Copy(*this);
234 }
235 return (*this);
236}
237
238
239
248
250{
251 // PROTECTED method
252 // Creates and returns pointer to a new (empty) KVSeqCollection
253 // (or derived class) with the same characteristics
254 // as this one :
255 // - class of embedded collection
256 // - collection is owner of objects ?
257 // - objects are in cleanup list ?
258
259 KVSeqCollection* newCol = (KVSeqCollection*)IsA()->New();
260 if (!newCol->fCollection) newCol->SetCollection(fCollection->ClassName());
261 newCol->SetOwner(IsOwner());
262 newCol->SetCleanup(IsCleanup());
263 return newCol;
264}
265
266
267
273
275{
276 // Clear the list of objects.
277 // If the cleanup mechanism is in use, and the objects belong to the list
278 // (i.e. Clear() will in fact delete all the objects) we first remove this list
279 // from the list of cleanups in order to avoid recursive deletes
280
281 Bool_t cleaner = kFALSE;
282 if (IsCleanup()) {
283 if (IsOwner()) {
284 cleaner = kTRUE;
286 }
287 }
288 if (!IsOwner()) {
289 // ROOT6: when Clear() is called for a TList/THashList containing invalid pointers
290 // (i.e. addresses of previously deleted objects), even if the list is not the owner
291 // of the objects (i.e. the Clear() should not attempt to delete anything), then
292 // calling Clear() without the option "nodelete" leads to false-positive warnings
293 // like this: Error in <***::Clear>: A list is accessing an object (0x5632b51c08b0) already deleted...
294 fCollection->Clear("nodelete");
295 }
296 else
298 if (cleaner) SetCleanup();
299 Changed();
300}
301
302
303
308
310{
311 // Delete all heap-based objects in the list.
312 // If the cleanup mechanism is in use we first remove this list
313 // from the list of cleanups in order to avoid recursive deletes
314
315 Bool_t cleaner = kFALSE;
316 if (IsCleanup()) {
317 if (IsOwner()) {
318 cleaner = kTRUE;
320 }
321 }
323 if (cleaner) SetCleanup();
324 Changed();
325}
326
327
328
331
333{
334 // Return reference to object.
335 return fCollection->GetObjectRef(obj);
336}
337
338
339
342
344{
345 // Make and return iterator for the list.
346 return fCollection->MakeIterator(dir);
347}
348
349
350
353
355{
356 // Remove object from list.
357
359 if (result) Changed();
360 return result;
361}
362
363
364
373
375{
376 // Remove object from this collection and recursively remove the object
377 // from all other objects (and collections).
378 //
379 // NOTE: lists which are 'cleanup' and 'sendmodifiedsignals':
380 // the list will not emit 'Modified()' when objects in the
381 // list are deleted elsewhere, they are then removed by the cleanup mechanism
382 // by calling this method.
383
385}
386
387
388
391
393{
394 // Overrides TCollection::PrintCollectionHeader to show the class name of the embedded list
396 printf("Collection name='%s', embedded list class='%s', size=%d\n", GetName(),
398}
399
400
401
406
408{
409 // Will return object with given type (value of KVBase::GetType() method).
410 // Objects in list which do not inherit KVBase do not have GetType() method,
411 // and are ignored.
412
413 TIter next(fCollection);
414 TObject* obj;
415 while ((obj = next())) {
417 if (((KVBase*)obj)->IsType(type))
418 return obj;
419 }
420 }
421 return nullptr;
422}
423
424
425
428
430{
431 // Will return object with given title (value of TObject::GetTitle() method).
432
433 TIter next(fCollection);
434 TObject* obj;
435 while ((obj = next())) {
436 if (!strcmp(obj->GetTitle(), title))
437 return obj;
438 }
439 return nullptr;
440}
441
442
443
446
448{
449 // Return (first) object in embedded list with given class.
450
451 TIter next(fCollection);
452 TObject* obj;
453 while ((obj = next())) {
454 if (obj->IsA() == cl) return obj;
455 }
456 return nullptr;
457}
458
459
460
463
465{
466 // Return (first) object in embedded list with given class.
467
468 return FindObjectByClass(TClass::GetClass(cl));
469}
470
471
472
477
479{
480 // Will return object with given label (value of KVBase::GetLabel() method).
481 // Objects in list which do not inherit KVBase do not have GetLabel() method,
482 // and are ignored.
483
484 TIter next(fCollection);
485 TObject* obj;
486 while ((obj = next())) {
488 if (!strcmp(((KVBase*)obj)->GetLabel(), label)) return obj;
489 }
490 }
491 return nullptr;
492}
493
494
495
496
501
503{
504 // Will return object with given number (value of KVBase::GetNumber() method).
505 // Objects in list which do not inherit KVBase do not have GetNumber() method,
506 // and are ignored.
507
508 TIter next(fCollection);
509 TObject* obj;
510 while ((obj = next())) {
512 if (((KVBase*)obj)->GetNumber() == num) return obj;
513 }
514 }
515 return nullptr;
516}
517
518
519
524
526{
527 // Return object with specified name AND type (value of KVBase::GetType() method).
528 // Objects in list which do not inherit KVBase do not have GetType() method,
529 // and are ignored.
530
531 TIter next(fCollection);
532 TObject* obj;
533 while ((obj = next())) {
534 if (obj->TestBit(KVBase::kIsKaliVedaObject) && !strcmp(obj->GetName(), name)) {
535 if (!strcmp(((KVBase*)obj)->GetType(), type)) return obj;
536 }
537 }
538 return nullptr;
539}
540
541
542
551
552TObject* KVSeqCollection::FindObjectWithMethod(const Char_t* retvalue, const Char_t* method) const
553{
554 // Find the first object in the list for which the given method returns the given return value:
555 // e.g. if method = "GetName" and retvalue = "john", we return the
556 // first object in this list for which GetName() returns "john".
557 //
558 // For each object of the list, the existence of the given method is checked using TMethodCall::IsValid()
559 // if the method is valid and the return value is equal to the input one (retvalue) object is returned
560 // Supported return types are those defined in TMethodCall::ReturnType()
561
562 if (retvalue && method) {
563 KVString RV(retvalue);
564 KVString MTH(method);
565 Bool_t wildcard = RV.Contains("*");
566 TIter next(fCollection);
567 TObject* obj;
568 while ((obj = next())) {
569 TMethodCall mt;
570 mt.InitWithPrototype(obj->IsA(), MTH.Data(), "");
571 if (mt.IsValid()) {
572 if (mt.ReturnType() == TMethodCall::kString) {
573 Char_t* ret;
574 mt.Execute(obj, "", &ret);
575 if (ret != nullptr) {
576 if (!wildcard) {
577 if (RV == ret) {
578 return obj;
579 }
580 }
581 else {
582 if (KVString(ret).Match(RV)) {
583 return obj;
584 }
585 }
586 }
587 }
588 else if (mt.ReturnType() == TMethodCall::kLong) {
589 Long_t ret;
590 mt.Execute(obj, "", ret);
591 if (ret == RV.Atoi()) {
592 return obj;
593 }
594 }
595 else if (mt.ReturnType() == TMethodCall::kDouble) {
596 Double_t ret;
597 mt.Execute(obj, "", ret);
598 if (ret == RV.Atof()) {
599 return obj;
600 }
601 }
602 else Error("FindObjectWithMethod", "Return type %d is not supported", (int)mt.ReturnType());
603 }
604 }
605 }
606 return nullptr;
607
608}
609
610
611
616
617void KVSeqCollection::Execute(const char* method, const char* params, Int_t* error)
618{
619 //Redefinition of TObject::Execute(const char *, const char *, Int_t *) method.
620 //TObject::Execute is called for each object in the embedded list in order, meaning that for each
621 //object the method "method" is executed with arguments "params".
622
623 TIter next(fCollection);
624 TObject* obj;
625 while ((obj = next())) {
626 obj->Execute(method, params, error);
627 }
628}
629
630
631
632
637
638void KVSeqCollection::Execute(TMethod* method, TObjArray* params, Int_t* error)
639{
640 //Redefinition of TObject::Execute(TMethod *, TObjArray *, Int_t *) method.
641 //TObject::Execute is called for each object in the embedded list in order, meaning that for each
642 //object the method "method" is executed with arguments "params".
643
644 TIter next(fCollection);
645 TObject* obj;
646 while ((obj = next())) {
647 obj->Execute(method, params, error);
648 }
649}
650
651
652
653
668
669TObject* KVSeqCollection::FindObjectAny(const Char_t* att, const Char_t* keys, Bool_t contains_all, Bool_t case_sensitive) const
670{
671 //Find an object in the list, if one of its characteristics 'att' contains any or all of
672 //the keywords contained in the string 'keys'
673 //
674 // att = "name", "title", "class", "type", "label",
675 // WARNING: when using "type" or "label", any objects in list which do
676 // not inherit from KVBase are ignored
677 // keys = list of keywords, separated by spaces
678 //
679 // contains_all = kFALSE (default) : object found if any keyword occurs in the characteristic 'att'
680 // contains_all = kTRUE : object found if all keywords occur in the characteristic 'att'
681 //
682 // case_sensitive = kTRUE (default) : case-sensitive comparison
683 // case_sensitive = kFALSE : ignore case of keywords
684
685 int char_test = -1;
686 enum { kName, kTitle, kClass, kType, kLabel };
687 if (!strcmp(att, "name")) char_test = kName;
688 else if (!strcmp(att, "title")) char_test = kTitle;
689 else if (!strcmp(att, "type")) char_test = kType;
690 else if (!strcmp(att, "label")) char_test = kLabel;
691 else if (!strcmp(att, "class")) char_test = kClass;
692 else return nullptr;
693
694 TString::ECaseCompare casecmp;
695 if (case_sensitive) casecmp = TString::kExact;
696 else casecmp = TString::kIgnoreCase;
697
698 TString _keys(keys);
699 unique_ptr<TObjArray> keywords(_keys.Tokenize(' '));
700 if (!keywords.get()) return nullptr;
701 int nkeys;
702 if (!(nkeys = keywords->GetEntries())) {
703 return nullptr;
704 }
705
706 int nmatches;
707 TIter next(fCollection);
708 TString _att;
709 TObject* obj(nullptr);
710 while ((obj = next())) {
711
712 if (char_test > kClass && !obj->TestBit(KVBase::kIsKaliVedaObject)) {
713 continue;
714 }
715 KVBase* kvobj = dynamic_cast<KVBase*>(obj);
716 switch (char_test) {
717 case kName:
718 _att = obj->GetName();
719 break;
720 case kTitle:
721 _att = obj->GetTitle();
722 break;
723 case kClass:
724 _att = obj->ClassName();
725 break;
726 case kLabel:
727 _att = kvobj->GetLabel();
728 break;
729 case kType:
730 _att = kvobj->GetType();
731 break;
732 }
733 nmatches = 0;
734 for (int i = 0; i < nkeys; i++) {
735 nmatches += (_att.Contains(((TObjString*)keywords->At(i))->String(), casecmp));
736 }
737 if ((nmatches && !contains_all) || ((nmatches == nkeys) && contains_all)) {
738 return obj;
739 }
740 }
741 return nullptr;
742}
743
744
745
754
756{
757 // Create and fill a (sub)list with objects in this list of the given class.
758 // This new list will be of the same kind as this one.
759 // The objects in the sublist do not belong to the sublist.
760 //
761 // *** WARNING *** : DELETE the KVSeqCollection returned by this method after using it !!!
762 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
763 // unique_ptr<KVSeqCollection> ptr(GetSubListWithClass(...));
764
766 sublist->SetOwner(kFALSE);
767 _GetSubListWithClass(sublist, fCollection, _class);
768 return sublist;
769}
770
771
772
774
776{
777 if (_class) {
778 TIter next(Col);
779 TObject* ob;
780 while ((ob = next())) {
781 if (_class == ob->IsA()) outputList->Add(ob);
782 // if we are looking for objects of class "TList" or some other TCollection, they will all be included!
783 if (ob->InheritsFrom("TCollection")) _GetSubListWithClass(outputList, (TCollection*)ob, _class);
784 }
785 }
786}
787
788
789
798
800{
801 // Recursively create and fill a (sub)list with objects in this list (and any sublists) of the given class.
802 // This new list will be of the same kind as this one.
803 // The objects in the sublist do not belong to the sublist.
804 //
805 // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
806 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
807 // unique_ptr<KVSeqCollection> ptr(GetSubListWithClass(...));
808
809 if (class_name) {
810 return GetSubListWithClass(TClass::GetClass(class_name));
811 }
812 else return nullptr;
813}
814
815
816
832
834{
835 // Recursively create and fill a (sub)list with objects in this list (and any sublists) for which the
836 // given method returns the given return value:
837 // e.g. if method = "GetName" and retvalue = "john", we return the
838 // (sub)list of objects in this list for which GetName() returns "john".
839 //
840 // This new list will be of the same kind as this one.
841 // The objects in the sublist do not belong to the sublist.
842 // *** WARNING *** : DELETE the list returned by this method after using it !!!
843 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
844 // unique_ptr<KVSeqCollection> ptr(GetSubListWithMethod(...));
845 //
846 // For each object of the list, the existence of the given method is checked using TMethodCall::IsValid()
847 // if the method is valid and the return value is equal to the input one (retvalue) object is added to the subKVList
848 // return type supported are those defined in TMethodCall::ReturnType()
849
851 sublist->SetOwner(kFALSE);
852 _GetSubListWithMethod(sublist, fCollection, retvalue, method);
853 return sublist;
854}
855
856
857
859
860void KVSeqCollection::_GetSubListWithMethod(KVSeqCollection* outputList, TCollection* Col, const Char_t* retvalue, const Char_t* method) const
861{
862 if (retvalue && method) {
863 KVString RV(retvalue);
864 KVString MTH(method);
865 Bool_t wildcard = RV.Contains("*");
866 TIter next(Col);
867 TObject* ob;
868 while ((ob = next())) {
869 // recursive search in subidrectories
870 if (ob->InheritsFrom("TCollection")) {
871 _GetSubListWithMethod(outputList, (TCollection*)ob, retvalue, method);
872 continue;
873 }
874 TMethodCall mt;
875 mt.InitWithPrototype(ob->IsA(), MTH.Data(), "");
876 if (mt.IsValid()) {
877 //cout << "it is valid" << endl;
878 if (mt.ReturnType() == TMethodCall::kString) {
879 Char_t* ret;
880 mt.Execute(ob, "", &ret);
881 if (!wildcard) {
882 if (RV == ret) outputList->Add(ob);
883 }
884 else {
885 if (KVString(ret).Match(RV)) outputList->Add(ob);
886 }
887 }
888 else if (mt.ReturnType() == TMethodCall::kLong) {
889 Long_t ret;
890 mt.Execute(ob, "", ret);
891 if (ret == RV.Atoi()) outputList->Add(ob);
892 }
893 else if (mt.ReturnType() == TMethodCall::kDouble) {
894 Double_t ret;
895 mt.Execute(ob, "", ret);
896 if (ret == RV.Atof()) outputList->Add(ob);
897 }
898 else std::cout << "this type is not supported " << (int)mt.ReturnType() << std::endl;
899 }
900 }
901 }
902}
903
904
905
915
917{
918 // Create and fill a (sub)list with all objects in this list whose name
919 // (i.e. string returned by GetName()) is "retvalue"
920 // This new list will be of the same kind as this one.
921 // The objects in the sublist do not belong to the sublist.
922 //
923 // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
924 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
925 // unique_ptr<KVSeqCollection> ptr(GetSubListWithName(...));
926
927 return GetSubListWithMethod(retvalue, "GetName");
928}
929
930
931
941
943{
944 // Create and fill a (sub)list with all objects in this list whose label
945 // (i.e. string returned by GetLabel()) is "retvalue"
946 // This new list will be of the same kind as this one.
947 // The objects in the sublist do not belong to the sublist.
948 //
949 // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
950 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
951 // unique_ptr<KVSeqCollection> ptr(GetSubListWithLabel(...));
952
953 return GetSubListWithMethod(retvalue, "GetLabel");
954}
955
956
957
967
969{
970 // Create and fill a (sub)list with all objects in this list whose type
971 // (i.e. string returned by GetType()) is "retvalue"
972 // This new list will be of the same kind as this one.
973 // The objects in the sublist do not belong to the sublist.
974 //
975 // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
976 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
977 // unique_ptr<KVSeqCollection> ptr(GetSubListWithType(...));
978
979 return GetSubListWithMethod(retvalue, "GetType");
980}
981
982
983
993
995{
996 //Static method create a list containing all objects contain of a file
997 //The file can be closed after this method, objects stored in the
998 //list still remains valid
999 //if file=NULL, the current directory is considered
1000 //
1001 // *** WARNING *** : DELETE the KVSeqCollection returned by this method after using it !!!
1002 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1003 // unique_ptr<KVSeqCollection> ptr(MakeListFromFile(...));
1004
1005 KVSeqCollection* ll = new KVSeqCollection("TList");
1006 ll->SetOwner(kFALSE);
1007
1008 TKey* key = 0;
1009 if (!file) {
1010 TIter next_ps(gDirectory->GetListOfKeys());
1011 while ((key = (TKey*) next_ps())) ll->Add(key->ReadObj());
1012 }
1013 else {
1014 TIter next_ps(file->GetListOfKeys());
1015 while ((key = (TKey*) next_ps())) ll->Add(key->ReadObj());
1016
1017 }
1018 return ll;
1019}
1020
1021
1022
1031
1033{
1034 //Static method create a list containing all objects whose "method" returns "retvalue" in a file
1035 //WARNING list has to be empty with KVSeqCollection::Clear() method before closing file
1036 //if file=NULL, the current directory is considered
1037 //
1038 // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1039 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1040 // unique_ptr<KVSeqCollection> ptr(MakeListFromFileWithMethod(...));
1041
1042 unique_ptr<KVSeqCollection> l1(MakeListFromFile(file));
1043 KVSeqCollection* l2 = l1->GetSubListWithMethod(retvalue, method);
1044 l1->Clear();
1045 return l2;
1046}
1047
1048
1049
1058
1060{
1061 //Static method create a list containing all objects of given class in a file
1062 //WARNING list has to be empty with KVList::Clear() method before closing file
1063 //if file=NULL, the current directory is considered
1064 //
1065 // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1066 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1067 // unique_ptr<KVSeqCollection> ptr(MakeListFromFileWithClass(...));
1068
1069 unique_ptr<KVSeqCollection> l1(MakeListFromFile(file));
1070 KVSeqCollection* l2 = l1->GetSubListWithClass(_class);
1071 l1->Clear();
1072 return l2;
1073}
1074
1075
1076
1085
1087{
1088 //Static method create a list containing all objects of given class in a file
1089 //WARNING list has to be empty with KVList::Clear() method before closing file
1090 //if file=NULL, the current directory is considered
1091 //
1092 // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1093 // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1094 // unique_ptr<KVSeqCollection> ptr(MakeListFromFileWithClass(...));
1095
1096 unique_ptr<KVSeqCollection> l1(MakeListFromFile(file));
1097 KVSeqCollection* l2 = l1->GetSubListWithClass(class_name);
1098 l1->Clear();
1099 return l2;
1100}
1101
1102
1103
1104
1108
1110{
1111 // To use the ROOT cleanup mechanism to ensure that any objects in the list which get
1112 // deleted elsewhere are removed from this list, call SetCleanup(kTRUE)
1113
1114 SetBit(kCleanup, enable);
1115 if (enable) {
1116 // make sure there is not already a list with the same name in the list
1117 auto l = fgCleanups->FindObject(GetName());
1118 if (l) {
1119 if (l != this) {
1120 SetName(Form("KVSeqCollection_%lld", fSCCounter));
1121 fSCCounter++;//always increases, so names are different
1122 Info("SetCleanup", "A list with same name (%s) is already in cleanups list. Changed to %s.",
1123 l->GetName(), GetName());
1124 fgCleanups->Add(this);
1125 }
1126 }
1127 else
1128 fgCleanups->Add(this);
1129 fCollection->R__FOR_EACH(TObject, SetBit)(kMustCleanup);
1130 }
1131 else {
1132 fgCleanups->Remove(this);
1133 }
1134}
1135
1136
1137
1139
1144
1145
1146
1149
1151{
1152 // Stream an object of class KVSeqCollection.
1153
1154 UInt_t R__s, R__c;
1155 if (R__b.IsReading()) {
1156 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1158 if (R__v < 3) {
1159 // correct legacy BIT(16) used for fCleanup
1160 SetCleanup(TestBit(BIT(16)));
1161#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
1162 // for ROOT6 we reset BIT(16) if it was set, assuming that
1163 // default is 0 (used by TCollection::IsUsingRWLock())
1164 ResetBit(BIT(16));
1165#endif
1166 }
1167 fQObject.Streamer(R__b);
1168 if (fCollection) {
1169 Bool_t owns = fCollection->IsOwner();
1170 fCollection->SetOwner(kFALSE);
1171 fCollection->Streamer(R__b);
1172 fCollection->SetOwner(owns);
1173 }
1174 else R__b >> fCollection;
1175 R__b.CheckByteCount(R__s, R__c, KVSeqCollection::IsA());
1176 }
1177 else {
1178 R__c = R__b.WriteVersion(KVSeqCollection::IsA(), kTRUE);
1180 fQObject.Streamer(R__b);
1181 if (fCollection) {
1182 fCollection->Streamer(R__b);
1183 }
1184 else R__b << fCollection;
1185 R__b.SetByteCount(R__c, kTRUE);
1186 }
1187}
1188
1189
int Int_t
unsigned int UInt_t
long Long_t
#define SafeDelete(p)
#define c(i)
bool Bool_t
short Version_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
#define BIT(n)
#define gDirectory
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
#define gROOT
char * Form(const char *fmt,...)
kClass
kName
kTitle
Base class for KaliVeda framework.
Definition KVBase.h:142
@ kIsKaliVedaObject
Definition KVBase.h:163
const Char_t * GetLabel() const
Definition KVBase.h:199
virtual const Char_t * GetType() const
Definition KVBase.h:177
KaliVeda extensions to ROOT collection classes.
virtual TObject * FindObjectByLabel(const Char_t *) const
static Long64_t fSCCounter
counter used to give unique names to all lists
virtual void Copy(TObject &obj) const
KVSeqCollection * GetSubListWithName(const Char_t *retvalue) const
KVSeqCollection * GetSubListWithMethod(const Char_t *retvalue, const Char_t *method) const
KVSeqCollection & operator=(const KVSeqCollection &)
virtual TObject ** GetObjectRef(const TObject *obj) const
Return reference to object.
static TSeqCollection * fgCleanups
regroup all lists which are to be cleaned up
virtual void SendModifiedSignals(Bool_t yes=kTRUE)
virtual KVSeqCollection * NewCollectionLikeThisOne() const
virtual Bool_t IsCleanup() const
virtual void SetCollection(const Char_t *)
KVSeqCollection * GetSubListWithClass(const TClass *_class) const
TSeqCollection * fCollection
Pointer to embedded ROOT collection.
virtual void SetOwner(Bool_t enable=kTRUE)
virtual void Clear(Option_t *option="")
virtual Int_t GetSize() const
virtual TObject * FindObjectAny(const Char_t *att, const Char_t *keys, Bool_t contains_all=kFALSE, Bool_t case_sensitive=kTRUE) const
TObject * FindObjectByClass(const Char_t *) const
Return (first) object in embedded list with given class.
KVSeqCollection * GetSubListWithType(const Char_t *retvalue) const
virtual void _GetSubListWithMethod(KVSeqCollection *, TCollection *, const Char_t *, const Char_t *) const
virtual void Execute(const char *method, const char *params, Int_t *error=0)
KVSeqCollection()
Default constructor.
virtual Bool_t IsSendingModifiedSignals() const
static void RehashCleanupList()
virtual void Changed()
static Int_t fgCounter
counts instances
virtual void PrintCollectionHeader(Option_t *option) const
Overrides TCollection::PrintCollectionHeader to show the class name of the embedded list.
virtual void SetCleanup(Bool_t enable=kTRUE)
static KVSeqCollection * MakeListFromFileWithClass(TFile *file, const TClass *_class)
virtual TObject * FindObjectByNumber(UInt_t num) const
virtual TObject * FindObjectWithMethod(const Char_t *retvalue, const Char_t *method) const
static KVSeqCollection * MakeListFromFile(TFile *file)
virtual TObject * FindObjectByType(const Char_t *) const
virtual TObject * FindObjectByTitle(const Char_t *) const
Will return object with given title (value of TObject::GetTitle() method).
virtual void Add(TObject *obj)
virtual TObject * FindObjectWithNameAndType(const Char_t *name, const Char_t *type) const
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Make and return iterator for the list.
KVSeqCollection * GetSubListWithLabel(const Char_t *retvalue) const
virtual TObject * Remove(TObject *obj)
Remove object from list.
virtual void Delete(Option_t *option="")
static KVSeqCollection * MakeListFromFileWithMethod(TFile *file, const Char_t *retvalue, const Char_t *method)
@ kCleanup
in ROOT v6 BIT(16) is used by TCollection - without changing the class version
void _GetSubListWithClass(KVSeqCollection *, TCollection *, const TClass *) const
virtual void RecursiveRemove(TObject *obj)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const char *classname)=0
Bool_t IsReading() const
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
virtual TObject ** GetObjectRef(const TObject *obj) const=0
virtual TObject * Remove(TObject *obj)=0
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const=0
void RecursiveRemove(TObject *obj) override
void SetName(const char *name)
void Streamer(TBuffer &) override
const char * GetName() const override
TClass * IsA() const override
virtual void SetOwner(Bool_t enable=kTRUE)
Bool_t IsOwner() const
TObject * FindObject(const char *name) const override
void Delete(Option_t *option="") override=0
void Clear(Option_t *option="") override=0
virtual Int_t GetSize() const
virtual TObject * ReadObj()
EReturnType ReturnType()
static const EReturnType kLong
void InitWithPrototype(const char *function, const char *proto, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
static const EReturnType kString
Bool_t IsValid() const
static const EReturnType kDouble
void Execute()
virtual const char * GetName() const
void SetBit(UInt_t f)
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual const char * ClassName() const
virtual void Execute(const char *method, const char *params, Int_t *error=nullptr)
virtual Bool_t InheritsFrom(const char *classname) const
virtual void Copy(TObject &object) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual const char * GetTitle() const
virtual TClass * IsA() const
void MakeZombie()
void ResetBit(UInt_t f)
virtual void Info(const char *method, const char *msgfmt,...) const
static void IndentLevel()
TClass * IsA() const override
void Streamer(TBuffer &) override
void Add(TObject *obj) override
Int_t Atoi() const
Double_t Atof() const
const char * Data() const
TObjArray * Tokenize(const TString &delim) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
long long Long64_t
Type GetType(const std::string &Name)
TLine l
ClassImp(TPyArg)