ClusterCollection.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // $Id$
  2. // Author: artur 2016/04/07
  3. //_____________________________________________________________________________
  4. //
  5. // ClusterCollection
  6. //_____________________________________________________________________________
  7. #include "ClusterCollection.h"
  8. #include <iostream>
  9. using std::cout;
  10. using std::endl;
  11. ClassImp(ClusterCollection)
  12. //_____________________________________________________________________________
  13. ClusterCollection::ClusterCollection():TNamed("collection","")
  14. {
  15. Id_.Set(3);
  16. }
  17. //_____________________________________________________________________________
  18. ClusterCollection::ClusterCollection(Int_t uid):TNamed("collection","")
  19. {
  20. Id_.Set(3);
  21. Id_[0] = uid;
  22. }
  23. //_____________________________________________________________________________
  24. void ClusterCollection::SetId(Int_t i, Int_t v)
  25. {
  26. if (i < 1) return;
  27. if (i < Id_.fN) { Id_[i] = v; return; }
  28. Id_.Set(i+1);
  29. Id_[i] = v;
  30. }
  31. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  32. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  33. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  34. //_____________________________________________________________________________
  35. const Cluster* ClusterCollection::GetCluster(Int_t id) const
  36. {
  37. if (GetId() < 1) return 0;
  38. if (id < 1) return 0;
  39. CL_CSET::const_iterator it = Clusters_.find(id);
  40. return (it != Clusters_.end()) ? it->second : 0;
  41. }
  42. //_____________________________________________________________________________
  43. Bool_t ClusterCollection::FindCluster(const Cluster* cl) const
  44. {
  45. if (GetId() < 1) return kFALSE;
  46. if (!cl) return kFALSE;
  47. Int_t id = cl->GetId();
  48. CL_CSET::const_iterator it = Clusters_.find(id);
  49. return (it != Clusters_.end());
  50. }
  51. //_____________________________________________________________________________
  52. Bool_t ClusterCollection::FindCluster(Int_t id) const
  53. {
  54. if (GetId() < 1) return kFALSE;
  55. if (id < 1) return kFALSE;
  56. CL_CSET::const_iterator it = Clusters_.find(id);
  57. return (it != Clusters_.end());
  58. }
  59. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  60. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  61. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  62. //_____________________________________________________________________________
  63. Bool_t ClusterCollection::AddCluster(Cluster* cl)
  64. {
  65. if (GetId() < 1) {
  66. cout << "[W]<ClusterCollection::AddCluster> Collection has no ID (<1)" << endl;
  67. return kFALSE;
  68. }
  69. if (!cl) {
  70. cout << "[W]<ClusterCollection::AddCluster> No cluster " << endl;
  71. return kFALSE;
  72. }
  73. Int_t id = cl->GetId();
  74. if (id < 1) {
  75. cout << "[W]<ClusterCollection::AddCluster> Cluster has no ID (<1)" << endl;
  76. return kFALSE;
  77. }
  78. CL_CSET::iterator it = Clusters_.find(id);
  79. if (it == Clusters_.end()) Clusters_.insert(std::pair<Int_t,Cluster*>(id,cl));
  80. cl->AddCollection(GetId());
  81. return kTRUE;
  82. }
  83. //_____________________________________________________________________________
  84. Bool_t ClusterCollection::RemoveCluster(Cluster* cl)
  85. {
  86. if (GetId() < 1) return kFALSE;
  87. if (!cl) return kFALSE;
  88. Int_t id = cl->GetId();
  89. CL_CSET::iterator it = Clusters_.find(id);
  90. if (it != Clusters_.end()) Clusters_.erase(it);
  91. cl->RemoveCollection(GetId());
  92. return kTRUE;
  93. }
  94. //_____________________________________________________________________________
  95. Bool_t ClusterCollection::RemoveCluster(Int_t id)
  96. {
  97. if (GetId() < 1) return kFALSE;
  98. if (id < 1) return kFALSE;
  99. CL_CSET::iterator it = Clusters_.find(id);
  100. if (it != Clusters_.end()) {
  101. it->second->RemoveCollection(GetId());
  102. Clusters_.erase(it);
  103. }
  104. return kTRUE;
  105. }
  106. //_____________________________________________________________________________
  107. void ClusterCollection::RemoveClusters() {
  108. //
  109. CL_CSET::iterator it = Clusters_.begin();
  110. Int_t id = GetId();
  111. for ( ; it != Clusters_.end(); it++) it->second->RemoveCollection(id);
  112. Clusters_.clear();
  113. }
  114. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  115. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  116. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  117. //_____________________________________________________________________________
  118. void ClusterCollection::print(Int_t opt) const
  119. {
  120. }