KaliVeda
Toolkit for HIC analysis
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 
15 using 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) {
41  fgCleanups = new THashList;
42  fgCleanups->SetName("KVSeqCollection_Cleanups");
43  gROOT->GetListOfCleanups()->Add(fgCleanups);
44  }
45 }
46 
47 
48 
52 
54 {
55  // Default constructor
56  //Info("KVSeqCollection","def con");
57  fCollection = nullptr;
58  ResetBit(kSignals);
59  init();
60 }
61 
62 
63 
68 
70  : TSeqCollection()
71 {
72  // Copy constructor
73  // See KVSeqCollection::Copy
74 
75  //Info("KVSeqCollection","copy con");
77  col.Copy(*this);
78  init();
80 }
81 
82 
83 
90 
92  : KVSeqCollection()
93 {
94  // Move constructor
95  //
96  // We simply transfer the embedded collection to this object, and leave
97  // the other in an empty state
98 
99  //Info("KVSeqCollection","move con");
100  SetCollection(other.CollectionClassName());
101  operator=(std::move(other));
102 }
103 
104 
105 
112 
114 {
115  // Move assignment operator
116  //
117  // We simply copy all the object pointers from other to this object,
118  // and remove them from the other
119 
120  //Info("operator=","move ass");
121  if (&other != this) {
122  // remove any previous objects from this list
123  Clear();
124  // copy pointers from other
125  AddAll(&other);
126  // remove pointers from other - do not delete any objects!
127  //Info("operator=&&", "do not delete anything!");
128  other.Clear("nodelete"); // clear (do not delete) object pointers
129  //Info("operator=&&", "how did i do?");
130  //set ownership
131  set_ownership(other.IsOwner());
132  //set cleanup status
133  SetCleanup(other.IsCleanup());
134  //set signal&slot status
135  SendModifiedSignals(other.IsSendingModifiedSignals());
136  }
137  return *this;
138 }
139 
140 
141 
145 
146 KVSeqCollection::KVSeqCollection(const TString& collection_classname)
147 {
148  // Create new extended collection of class "collection_classname".
149  // Must be the name of a class derived from TSeqCollection.
150 
151  fCollection = nullptr;
152  SetCollection(collection_classname);
153  if (!fCollection) MakeZombie();
155  init();
157 }
158 
159 
160 
164 
166 {
167  // Create TSeqCollection-derived object of class 'class_name'
168  // and set as the embedded collection fCollection.
169  TClass* cl = TClass::GetClass(class_name);
170  if (!cl) {
171  Error("SetCollection(const Char_t*)", "Called for unknown class: %s",
172  class_name.Data());
173  return;
174  }
175  if (!cl->InheritsFrom("TSeqCollection")) {
176  Error("SetCollection(const Char_t*)",
177  "Called for class %s which does not inherit from TSeqCollection",
178  class_name.Data());
179  return;
180  }
181  fCollection = (TSeqCollection*)cl->New();
182  // if name of KVSeqCollection has already been set (i.e. if this is not
183  // being called by one of the constructors), we set the name of the
184  // embedded TSeqCollection object
185  if (strcmp(GetName(), "KVSeqCollection"))
187 }
188 
189 
190 
196 
198 {
199  // Destructor
200  // If the cleanup mechanism is in use, we first remove the list from
201  // the list of cleanups
202 
203  //Info("~KVSeqCollection","destroy");
204  if (IsCleanup()) {
205  while (fgCleanups->Remove(this))
206  ;
207  }
208  if (fCollection && !IsOwner()) {
209  // ROOT6: when Clear() is called for a TList/THashList containing invalid pointers
210  // (i.e. addresses of previously deleted objects), even if the list is not the owner
211  // of the objects (i.e. the Clear() should not attempt to delete anything), then
212  // calling Clear() without the option "nodelete" leads to false-positive warnings
213  // like this: Error in <***::Clear>: A list is accessing an object (0x5632b51c08b0) already deleted...
214  // As the TList and THashList destructors contain a call to their Clear() method,
215  // here we pre-emptively Clear("nodelete") the collection before deleting it
216  fCollection->Clear("nodelete");
217  }
219  --fgCounter;//decrease instance count
220  if (fgCounter == 0 && fgCleanups) {
221  // delete cleanups list if this is the last KVSeqCollection
222  while (gROOT->GetListOfCleanups()->Remove(fgCleanups))
223  ;
224  fgCleanups->Clear();
225  delete fgCleanups;
226  fgCleanups = NULL;
227  }
228 }
229 
230 
231 
245 
247 {
248  // Copy a list of objects.
249  //
250  // The name of the list is only copied if the list is not IsCleanup().
251  // Cleanup lists must have unique names otherwise the THashList which contains them cannot function correctly.
252  //
253  // If this list owns its objects, we make new Clones of all objects in the list
254  // (N.B. the Clone() method must work correctly for the objects in question)
255  // and put them in the copy list, the copy will own these new objects.
256  //
257  // Copy will have same IsOwner() and IsCleanup() status as this list.
258  //
259  // If this list sends Modified() signal, the copy will do too.
260 
261  TSeqCollection::Copy(obj); //in fact this calls TObject::Copy, no Copy method defined for collection classes
262  KVSeqCollection& copy = (KVSeqCollection&) obj;
263 
264  // if the list is to be placed in the list of cleanups, it must have
265  // a unique name. otherwise the name of the list can be copied.
266  if (!IsCleanup()) copy.SetName(GetName());
267 
268  //clear any pre-existing objects in copy list
269  if (copy.IsOwner()) copy.Delete();
270  else copy.Clear();
271 
272  //set ownership
273  copy.set_ownership(IsOwner());
274  //set cleanup status
275  copy.SetCleanup(IsCleanup());
276  //set signal&slot status
278 
279  //copy or clone list members
280  TObject* b;
281  TIter next(fCollection);
282  while ((b = next())) {
283  if (IsOwner())
284  copy.Add(b->Clone());
285  else
286  copy.Add(b);
287  }
288 }
289 
290 
291 
294 
296 {
297  //Info("operator=","copy ass");
298  if (&c != this) { // check for self-assignment
299  c.Copy(*this);
300  }
301  return (*this);
302 }
303 
304 
305 
314 
316 {
317  // PROTECTED method
318  // Creates and returns pointer to a new (empty) KVSeqCollection
319  // (or derived class) with the same characteristics
320  // as this one :
321  // - class of embedded collection
322  // - collection is owner of objects ?
323  // - objects are in cleanup list ?
324 
325  KVSeqCollection* newCol = (KVSeqCollection*)IsA()->New();
326  if (!newCol->fCollection) newCol->SetCollection(fCollection->ClassName());
327  newCol->set_ownership(IsOwner());
328  newCol->SetCleanup(IsCleanup());
329  return newCol;
330 }
331 
332 
333 
343 
345 {
346  // Clear the list of objects. If list is 'owner', this will delete the objects.
347  //
348  // \param[in] option if option "nodelete", no objects are deleted even if the list is 'owner'
349  //
350  // If the cleanup mechanism is in use, and the objects belong to the list
351  // and option "nodelete" is not given
352  // (i.e. Clear() will in fact delete all the objects) we first remove this list
353  // from the list of cleanups in order to avoid recursive deletes
354 
355  TString opt(option);
356  opt.ToLower();
357  auto nodelete = opt.Contains("nodelete");
358 
359  Bool_t cleaner = kFALSE;
360  if (IsCleanup()) {
361  if (IsOwner() && !nodelete) {
362  cleaner = kTRUE;
364  }
365  }
366  if (!IsOwner()) {
367  // ROOT6: when Clear() is called for a TList/THashList containing invalid pointers
368  // (i.e. addresses of previously deleted objects), even if the list is not the owner
369  // of the objects (i.e. the Clear() should not attempt to delete anything), then
370  // calling Clear() without the option "nodelete" leads to false-positive warnings
371  // like this: Error in <***::Clear>: A list is accessing an object (0x5632b51c08b0) already deleted...
372  fCollection->Clear("nodelete");
373  }
374  else if(IsOwner() && nodelete)
375  {
376  // THashList::Clear("nodelete") calls TList::Delete() if the list is owner, and deletes
377  // the objects anyway!!! This is to make sure that nothing gets deleted when it shouldn't
381  }
382  else
384  if (cleaner) SetCleanup();
385  Changed();
386 }
387 
388 
389 
395 
397 {
398  // Delete all heap-based objects in the list.
399  //
400  // If the cleanup mechanism is in use we first remove this list
401  // from the list of cleanups in order to avoid recursive deletes
402 
403  Bool_t cleaner = kFALSE;
404  if (IsCleanup()) {
405  if (IsOwner()) {
406  cleaner = kTRUE;
408  }
409  }
411  if (cleaner) SetCleanup();
412  Changed();
413 }
414 
415 
416 
419 
421 {
422  // Return reference to object.
423  return fCollection->GetObjectRef(obj);
424 }
425 
426 
427 
430 
432 {
433  // Make and return iterator for the list.
434  return fCollection->MakeIterator(dir);
435 }
436 
437 
438 
441 
443 {
444  // Remove object from list.
445 
446  TObject* result = fCollection->Remove(obj);
447  if (result) Changed();
448  return result;
449 }
450 
451 
452 
461 
463 {
464  // Remove object from this collection and recursively remove the object
465  // from all other objects (and collections).
466  //
467  // NOTE: lists which are 'cleanup' and 'sendmodifiedsignals':
468  // the list will not emit 'Modified()' when objects in the
469  // list are deleted elsewhere, they are then removed by the cleanup mechanism
470  // by calling this method.
471 
473 }
474 
475 
476 
479 
481 {
482  // Overrides TCollection::PrintCollectionHeader to show the class name of the embedded list
484  printf("Collection name='%s', embedded list class='%s', size=%d\n", GetName(),
486 }
487 
488 
489 
494 
496 {
497  // Will return object with given type (value of KVBase::GetType() method).
498  // Objects in list which do not inherit KVBase do not have GetType() method,
499  // and are ignored.
500 
501  TIter next(fCollection);
502  TObject* obj;
503  while ((obj = next())) {
505  if (((KVBase*)obj)->IsType(type))
506  return obj;
507  }
508  }
509  return nullptr;
510 }
511 
512 
513 
516 
518 {
519  // Will return object with given title (value of TObject::GetTitle() method).
520 
521  TIter next(fCollection);
522  TObject* obj;
523  while ((obj = next())) {
524  if (!strcmp(obj->GetTitle(), title))
525  return obj;
526  }
527  return nullptr;
528 }
529 
530 
531 
534 
536 {
537  // Return (first) object in embedded list with given class.
538 
539  TIter next(fCollection);
540  TObject* obj;
541  while ((obj = next())) {
542  if (obj->IsA() == cl) return obj;
543  }
544  return nullptr;
545 }
546 
547 
548 
551 
553 {
554  // Return (first) object in embedded list with given class.
555 
557 }
558 
559 
560 
565 
567 {
568  // Will return object with given label (value of KVBase::GetLabel() method).
569  // Objects in list which do not inherit KVBase do not have GetLabel() method,
570  // and are ignored.
571 
572  TIter next(fCollection);
573  TObject* obj;
574  while ((obj = next())) {
576  if (!strcmp(((KVBase*)obj)->GetLabel(), label)) return obj;
577  }
578  }
579  return nullptr;
580 }
581 
582 
583 
584 
589 
591 {
592  // Will return object with given number (value of KVBase::GetNumber() method).
593  // Objects in list which do not inherit KVBase do not have GetNumber() method,
594  // and are ignored.
595 
596  TIter next(fCollection);
597  TObject* obj;
598  while ((obj = next())) {
600  if (((KVBase*)obj)->GetNumber() == num) return obj;
601  }
602  }
603  return nullptr;
604 }
605 
606 
607 
612 
614 {
615  // Return object with specified name AND type (value of KVBase::GetType() method).
616  // Objects in list which do not inherit KVBase do not have GetType() method,
617  // and are ignored.
618 
619  TIter next(fCollection);
620  TObject* obj;
621  while ((obj = next())) {
622  if (obj->TestBit(KVBase::kIsKaliVedaObject) && !strcmp(obj->GetName(), name)) {
623  if (!strcmp(((KVBase*)obj)->GetType(), type)) return obj;
624  }
625  }
626  return nullptr;
627 }
628 
629 
630 
639 
640 TObject* KVSeqCollection::FindObjectWithMethod(const Char_t* retvalue, const Char_t* method) const
641 {
642  // Find the first object in the list for which the given method returns the given return value:
643  // e.g. if method = "GetName" and retvalue = "john", we return the
644  // first object in this list for which GetName() returns "john".
645  //
646  // For each object of the list, the existence of the given method is checked using TMethodCall::IsValid()
647  // if the method is valid and the return value is equal to the input one (retvalue) object is returned
648  // Supported return types are those defined in TMethodCall::ReturnType()
649 
650  if (retvalue && method) {
651  KVString RV(retvalue);
652  KVString MTH(method);
653  Bool_t wildcard = RV.Contains("*");
654  TIter next(fCollection);
655  TObject* obj;
656  while ((obj = next())) {
657  TMethodCall mt;
658  mt.InitWithPrototype(obj->IsA(), MTH.Data(), "");
659  if (mt.IsValid()) {
660  if (mt.ReturnType() == TMethodCall::kString) {
661  Char_t* ret;
662  mt.Execute(obj, "", &ret);
663  if (ret != nullptr) {
664  if (!wildcard) {
665  if (RV == ret) {
666  return obj;
667  }
668  }
669  else {
670  if (KVString(ret).Match(RV)) {
671  return obj;
672  }
673  }
674  }
675  }
676  else if (mt.ReturnType() == TMethodCall::kLong) {
677  Long_t ret;
678  mt.Execute(obj, "", ret);
679  if (ret == RV.Atoi()) {
680  return obj;
681  }
682  }
683  else if (mt.ReturnType() == TMethodCall::kDouble) {
684  Double_t ret;
685  mt.Execute(obj, "", ret);
686  if (ret == RV.Atof()) {
687  return obj;
688  }
689  }
690  else Error("FindObjectWithMethod", "Return type %d is not supported", (int)mt.ReturnType());
691  }
692  }
693  }
694  return nullptr;
695 
696 }
697 
698 
699 
704 
705 void KVSeqCollection::Execute(const char* method, const char* params, Int_t* error)
706 {
707  //Redefinition of TObject::Execute(const char *, const char *, Int_t *) method.
708  //TObject::Execute is called for each object in the embedded list in order, meaning that for each
709  //object the method "method" is executed with arguments "params".
710 
711  TIter next(fCollection);
712  TObject* obj;
713  while ((obj = next())) {
714  obj->Execute(method, params, error);
715  }
716 }
717 
718 
719 
720 
725 
726 void KVSeqCollection::Execute(TMethod* method, TObjArray* params, Int_t* error)
727 {
728  //Redefinition of TObject::Execute(TMethod *, TObjArray *, Int_t *) method.
729  //TObject::Execute is called for each object in the embedded list in order, meaning that for each
730  //object the method "method" is executed with arguments "params".
731 
732  TIter next(fCollection);
733  TObject* obj;
734  while ((obj = next())) {
735  obj->Execute(method, params, error);
736  }
737 }
738 
739 
740 
741 
756 
757 TObject* KVSeqCollection::FindObjectAny(const Char_t* att, const Char_t* keys, Bool_t contains_all, Bool_t case_sensitive) const
758 {
759  //Find an object in the list, if one of its characteristics 'att' contains any or all of
760  //the keywords contained in the string 'keys'
761  //
762  // att = "name", "title", "class", "type", "label",
763  // WARNING: when using "type" or "label", any objects in list which do
764  // not inherit from KVBase are ignored
765  // keys = list of keywords, separated by spaces
766  //
767  // contains_all = kFALSE (default) : object found if any keyword occurs in the characteristic 'att'
768  // contains_all = kTRUE : object found if all keywords occur in the characteristic 'att'
769  //
770  // case_sensitive = kTRUE (default) : case-sensitive comparison
771  // case_sensitive = kFALSE : ignore case of keywords
772 
773  int char_test = -1;
774  enum { kName, kTitle, kClass, kType, kLabel };
775  if (!strcmp(att, "name")) char_test = kName;
776  else if (!strcmp(att, "title")) char_test = kTitle;
777  else if (!strcmp(att, "type")) char_test = kType;
778  else if (!strcmp(att, "label")) char_test = kLabel;
779  else if (!strcmp(att, "class")) char_test = kClass;
780  else return nullptr;
781 
782  TString::ECaseCompare casecmp;
783  if (case_sensitive) casecmp = TString::kExact;
784  else casecmp = TString::kIgnoreCase;
785 
786  TString _keys(keys);
787  unique_ptr<TObjArray> keywords(_keys.Tokenize(' '));
788  if (!keywords.get()) return nullptr;
789  int nkeys;
790  if (!(nkeys = keywords->GetEntries())) {
791  return nullptr;
792  }
793 
794  int nmatches;
795  TIter next(fCollection);
796  TString _att;
797  TObject* obj(nullptr);
798  while ((obj = next())) {
799 
800  if (char_test > kClass && !obj->TestBit(KVBase::kIsKaliVedaObject)) {
801  continue;
802  }
803  KVBase* kvobj = dynamic_cast<KVBase*>(obj);
804  switch (char_test) {
805  case kName:
806  _att = obj->GetName();
807  break;
808  case kTitle:
809  _att = obj->GetTitle();
810  break;
811  case kClass:
812  _att = obj->ClassName();
813  break;
814  case kLabel:
815  _att = kvobj->GetLabel();
816  break;
817  case kType:
818  _att = kvobj->GetType();
819  break;
820  }
821  nmatches = 0;
822  for (int i = 0; i < nkeys; i++) {
823  nmatches += (_att.Contains(((TObjString*)keywords->At(i))->String(), casecmp));
824  }
825  if ((nmatches && !contains_all) || ((nmatches == nkeys) && contains_all)) {
826  return obj;
827  }
828  }
829  return nullptr;
830 }
831 
832 
833 
842 
844 {
845  // Create and fill a (sub)list with objects in this list of the given class.
846  // This new list will be of the same kind as this one.
847  // The objects in the sublist do not belong to the sublist.
848  //
849  // *** WARNING *** : DELETE the KVSeqCollection returned by this method after using it !!!
850  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
851  // unique_ptr<KVSeqCollection> ptr(GetSubListWithClass(...));
852 
854  sublist->set_ownership(kFALSE);
855  _GetSubListWithClass(sublist, fCollection, _class);
856  return sublist;
857 }
858 
859 
860 
862 
863 void KVSeqCollection::_GetSubListWithClass(KVSeqCollection* outputList, TCollection* Col, const TClass* _class) const
864 {
865  if (_class) {
866  TIter next(Col);
867  TObject* ob;
868  while ((ob = next())) {
869  if (_class == ob->IsA()) outputList->Add(ob);
870  // if we are looking for objects of class "TList" or some other TCollection, they will all be included!
871  if (ob->InheritsFrom("TCollection")) _GetSubListWithClass(outputList, (TCollection*)ob, _class);
872  }
873  }
874 }
875 
876 
877 
886 
888 {
889  // Recursively create and fill a (sub)list with objects in this list (and any sublists) of the given class.
890  // This new list will be of the same kind as this one.
891  // The objects in the sublist do not belong to the sublist.
892  //
893  // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
894  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
895  // unique_ptr<KVSeqCollection> ptr(GetSubListWithClass(...));
896 
897  if (class_name) {
898  return GetSubListWithClass(TClass::GetClass(class_name));
899  }
900  else return nullptr;
901 }
902 
903 
904 
920 
922 {
923  // Recursively create and fill a (sub)list with objects in this list (and any sublists) for which the
924  // given method returns the given return value:
925  // e.g. if method = "GetName" and retvalue = "john", we return the
926  // (sub)list of objects in this list for which GetName() returns "john".
927  //
928  // This new list will be of the same kind as this one.
929  // The objects in the sublist do not belong to the sublist.
930  // *** WARNING *** : DELETE the list returned by this method after using it !!!
931  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
932  // unique_ptr<KVSeqCollection> ptr(GetSubListWithMethod(...));
933  //
934  // For each object of the list, the existence of the given method is checked using TMethodCall::IsValid()
935  // if the method is valid and the return value is equal to the input one (retvalue) object is added to the subKVList
936  // return type supported are those defined in TMethodCall::ReturnType()
937 
939  sublist->set_ownership(kFALSE);
940  _GetSubListWithMethod(sublist, fCollection, retvalue, method);
941  return sublist;
942 }
943 
944 
945 
947 
948 void KVSeqCollection::_GetSubListWithMethod(KVSeqCollection* outputList, TCollection* Col, const Char_t* retvalue, const Char_t* method) const
949 {
950  if (retvalue && method) {
951  KVString RV(retvalue);
952  KVString MTH(method);
953  Bool_t wildcard = RV.Contains("*");
954  TIter next(Col);
955  TObject* ob;
956  while ((ob = next())) {
957  // recursive search in subidrectories
958  if (ob->InheritsFrom("TCollection")) {
959  _GetSubListWithMethod(outputList, (TCollection*)ob, retvalue, method);
960  continue;
961  }
962  TMethodCall mt;
963  mt.InitWithPrototype(ob->IsA(), MTH.Data(), "");
964  if (mt.IsValid()) {
965  //cout << "it is valid" << endl;
966  if (mt.ReturnType() == TMethodCall::kString) {
967  Char_t* ret;
968  mt.Execute(ob, "", &ret);
969  if (!wildcard) {
970  if (RV == ret) outputList->Add(ob);
971  }
972  else {
973  if (KVString(ret).Match(RV)) outputList->Add(ob);
974  }
975  }
976  else if (mt.ReturnType() == TMethodCall::kLong) {
977  Long_t ret;
978  mt.Execute(ob, "", ret);
979  if (ret == RV.Atoi()) outputList->Add(ob);
980  }
981  else if (mt.ReturnType() == TMethodCall::kDouble) {
982  Double_t ret;
983  mt.Execute(ob, "", ret);
984  if (ret == RV.Atof()) outputList->Add(ob);
985  }
986  else std::cout << "this type is not supported " << (int)mt.ReturnType() << std::endl;
987  }
988  }
989  }
990 }
991 
992 
993 
1003 
1005 {
1006  // Create and fill a (sub)list with all objects in this list whose name
1007  // (i.e. string returned by GetName()) is "retvalue"
1008  // This new list will be of the same kind as this one.
1009  // The objects in the sublist do not belong to the sublist.
1010  //
1011  // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1012  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1013  // unique_ptr<KVSeqCollection> ptr(GetSubListWithName(...));
1014 
1015  return GetSubListWithMethod(retvalue, "GetName");
1016 }
1017 
1018 
1019 
1029 
1031 {
1032  // Create and fill a (sub)list with all objects in this list whose label
1033  // (i.e. string returned by GetLabel()) is "retvalue"
1034  // This new list will be of the same kind as this one.
1035  // The objects in the sublist do not belong to the sublist.
1036  //
1037  // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1038  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1039  // unique_ptr<KVSeqCollection> ptr(GetSubListWithLabel(...));
1040 
1041  return GetSubListWithMethod(retvalue, "GetLabel");
1042 }
1043 
1044 
1045 
1055 
1057 {
1058  // Create and fill a (sub)list with all objects in this list whose type
1059  // (i.e. string returned by GetType()) is "retvalue"
1060  // This new list will be of the same kind as this one.
1061  // The objects in the sublist do not belong to the sublist.
1062  //
1063  // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1064  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1065  // unique_ptr<KVSeqCollection> ptr(GetSubListWithType(...));
1066 
1067  return GetSubListWithMethod(retvalue, "GetType");
1068 }
1069 
1070 
1071 
1081 
1083 {
1084  //Static method create a list containing all objects contain of a file
1085  //The file can be closed after this method, objects stored in the
1086  //list still remains valid
1087  //if file=NULL, the current directory is considered
1088  //
1089  // *** WARNING *** : DELETE the KVSeqCollection returned by this method after using it !!!
1090  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1091  // unique_ptr<KVSeqCollection> ptr(MakeListFromFile(...));
1092 
1093  KVSeqCollection* ll = new KVSeqCollection("TList");
1094  ll->SetOwner(kFALSE);
1095 
1096  TKey* key = 0;
1097  if (!file) {
1098  TIter next_ps(gDirectory->GetListOfKeys());
1099  while ((key = (TKey*) next_ps())) ll->Add(key->ReadObj());
1100  }
1101  else {
1102  TIter next_ps(file->GetListOfKeys());
1103  while ((key = (TKey*) next_ps())) ll->Add(key->ReadObj());
1104 
1105  }
1106  return ll;
1107 }
1108 
1109 
1110 
1119 
1121 {
1122  //Static method create a list containing all objects whose "method" returns "retvalue" in a file
1123  //WARNING list has to be empty with KVSeqCollection::Clear() method before closing file
1124  //if file=NULL, the current directory is considered
1125  //
1126  // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1127  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1128  // unique_ptr<KVSeqCollection> ptr(MakeListFromFileWithMethod(...));
1129 
1130  unique_ptr<KVSeqCollection> l1(MakeListFromFile(file));
1131  KVSeqCollection* l2 = l1->GetSubListWithMethod(retvalue, method);
1132  l1->Clear();
1133  return l2;
1134 }
1135 
1136 
1137 
1146 
1148 {
1149  //Static method create a list containing all objects of given class in a file
1150  //WARNING list has to be empty with KVList::Clear() method before closing file
1151  //if file=NULL, the current directory is considered
1152  //
1153  // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1154  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1155  // unique_ptr<KVSeqCollection> ptr(MakeListFromFileWithClass(...));
1156 
1157  unique_ptr<KVSeqCollection> l1(MakeListFromFile(file));
1158  KVSeqCollection* l2 = l1->GetSubListWithClass(_class);
1159  l1->Clear();
1160  return l2;
1161 }
1162 
1163 
1164 
1173 
1175 {
1176  //Static method create a list containing all objects of given class in a file
1177  //WARNING list has to be empty with KVList::Clear() method before closing file
1178  //if file=NULL, the current directory is considered
1179  //
1180  // *** WARNING *** : DELETE the KVList returned by this method after using it !!!
1181  // *** RECOMMENDED *** : store the returned value in a std::unique_ptr
1182  // unique_ptr<KVSeqCollection> ptr(MakeListFromFileWithClass(...));
1183 
1184  unique_ptr<KVSeqCollection> l1(MakeListFromFile(file));
1185  KVSeqCollection* l2 = l1->GetSubListWithClass(class_name);
1186  l1->Clear();
1187  return l2;
1188 }
1189 
1190 
1191 
1192 
1196 
1198 {
1199  // To use the ROOT cleanup mechanism to ensure that any objects in the list which get
1200  // deleted elsewhere are removed from this list, call SetCleanup(kTRUE)
1201 
1202  SetBit(kCleanup, enable);
1203  if (enable) {
1204  // make sure there is not already a list with the same name in the list
1205  auto l = fgCleanups->FindObject(GetName());
1206  if (l) {
1207  if (l != this) {
1208  SetName(Form("KVSeqCollection_%lld", fSCCounter));
1209  fSCCounter++;//always increases, so names are different
1210  Info("SetCleanup", "A list with same name (%s) is already in cleanups list. Changed to %s.",
1211  l->GetName(), GetName());
1212  fgCleanups->Add(this);
1213  }
1214  }
1215  else
1216  fgCleanups->Add(this);
1217  fCollection->R__FOR_EACH(TObject, SetBit)(kMustCleanup);
1218  }
1219  else {
1220  fgCleanups->Remove(this);
1221  }
1222 }
1223 
1224 
1225 
1227 
1229 {
1230  ((THashList*)fgCleanups)->Rehash(fgCleanups->GetSize());
1231 }
1232 
1233 
1234 
1237 
1239 {
1240  // Stream an object of class KVSeqCollection.
1241 
1242  UInt_t R__s, R__c;
1243  if (R__b.IsReading()) {
1244  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1246  if (R__v < 3) {
1247  // correct legacy BIT(16) used for fCleanup
1248  SetCleanup(TestBit(BIT(16)));
1249 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
1250  // for ROOT6 we reset BIT(16) if it was set, assuming that
1251  // default is 0 (used by TCollection::IsUsingRWLock())
1252  ResetBit(BIT(16));
1253 #endif
1254  }
1255  fQObject.Streamer(R__b);
1256  if (fCollection) {
1257  Bool_t owns = fCollection->IsOwner();
1258  fCollection->SetOwner(kFALSE);
1259  fCollection->Streamer(R__b);
1260  fCollection->SetOwner(owns);
1261  }
1262  else R__b >> fCollection;
1263  R__b.CheckByteCount(R__s, R__c, KVSeqCollection::IsA());
1264  }
1265  else {
1266  R__c = R__b.WriteVersion(KVSeqCollection::IsA(), kTRUE);
1268  fQObject.Streamer(R__b);
1269  if (fCollection) {
1270  fCollection->Streamer(R__b);
1271  }
1272  else R__b << fCollection;
1273  R__b.SetByteCount(R__c, kTRUE);
1274  }
1275 }
1276 
1277 
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:139
virtual const Char_t * GetType() const
Definition: KVBase.h:176
const Char_t * GetLabel() const
Definition: KVBase.h:198
@ kIsKaliVedaObject
Definition: KVBase.h:159
KaliVeda extensions to ROOT collection classes.
virtual TObject * FindObjectByLabel(const Char_t *) const
void Copy(TObject &obj) const override
static Long64_t fSCCounter
counter used to give unique names to all lists
TObject ** GetObjectRef(const TObject *obj) const override
Return reference to object.
void Execute(const char *method, const char *params, Int_t *error=0) override
virtual ~KVSeqCollection()
KVSeqCollection * GetSubListWithName(const Char_t *retvalue) const
KVSeqCollection * GetSubListWithMethod(const Char_t *retvalue, const Char_t *method) const
KVSeqCollection & operator=(const KVSeqCollection &)
Info("operator=","copy ass");.
static TSeqCollection * fgCleanups
regroup all lists which are to be cleaned up
virtual void SendModifiedSignals(Bool_t yes=kTRUE)
KVSeqCollection * NewCollectionLikeThisOne() const
TObject * Remove(TObject *obj) override
Remove object from list.
void Add(TObject *obj) override
KVSeqCollection * GetSubListWithClass(const TClass *_class) const
TSeqCollection * fCollection
Pointer to embedded ROOT collection.
void Changed() override
@ kCleanup
in ROOT v6 BIT(16) is used by TCollection - without changing the class version
virtual TObject * FindObjectAny(const Char_t *att, const Char_t *keys, Bool_t contains_all=kFALSE, Bool_t case_sensitive=kTRUE) const
void SetCollection(const TString &)
TObject * FindObjectByClass(const Char_t *) const
Return (first) object in embedded list with given class.
KVSeqCollection * GetSubListWithType(const Char_t *retvalue) const
void set_ownership(Bool_t enable)
virtual void _GetSubListWithMethod(KVSeqCollection *, TCollection *, const Char_t *, const Char_t *) const
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Make and return iterator for the list.
void RecursiveRemove(TObject *obj) override
virtual Bool_t IsSendingModifiedSignals() const
void PrintCollectionHeader(Option_t *option) const override
Overrides TCollection::PrintCollectionHeader to show the class name of the embedded list.
Int_t GetSize() const override
static void RehashCleanupList()
void Clear(Option_t *option="") override
static Int_t fgCounter
counts instances
virtual void SetCleanup(Bool_t enable=kTRUE)
Bool_t IsCleanup() const
void SetOwner(Bool_t enable=kTRUE) override
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).
TString CollectionClassName() const
void Delete(Option_t *option="") override
virtual TObject * FindObjectWithNameAndType(const Char_t *name, const Char_t *type) const
KVSeqCollection * GetSubListWithLabel(const Char_t *retvalue) const
static KVSeqCollection * MakeListFromFileWithMethod(TFile *file, const Char_t *retvalue, const Char_t *method)
void _GetSubListWithClass(KVSeqCollection *, TCollection *, const TClass *) const
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
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
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)
virtual void AddAll(const TCollection *col)
const char * GetName() 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
void ToLower()
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
gr SetName("gr")
void init()
Type GetType(const std::string &Name)
TLine l
ClassImp(TPyArg)