ATLAS Offline Software
Loading...
Searching...
No Matches
CutBookkeeperContainer_v1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Implementation file for class CutBookkeeperContainer_v1
7// Author: Karsten Koeneke, May 2014 <karsten.koeneke@cern.ch>
9
11
12namespace xAOD {
13
14
16 // Constructors
18
19 // CutBookkeeperContainer_v1::CutBookkeeperContainer_v1()
20 // : DataVector<CutBookkeeper_v1> (SG::OWN_ELEMENTS)
21 // { }
22
23
29
37
38
42
43
44
45 // CutBookkeeperContainer_v1::CutBookkeeperContainer_v1( const CutBookkeeperContainer_v1& rhs ) :
46 // DataVector<CutBookkeeper_v1> (rhs)
47 // { }
48 //
49 //
50 // CutBookkeeperContainer_v1&
51 // CutBookkeeperContainer_v1::operator=( const CutBookkeeperContainer_v1& rhs ) {
52 // if ( this != &rhs ) {
53 // DataVector<CutBookkeeper_v1>::operator=(rhs);
54 // }
55 // return *this;
56 // }
57 //
58 //
59 // CutBookkeeperContainer_v1::CutBookkeeperContainer_v1( const SG::OwnershipPolicy own ) :
60 // DataVector<CutBookkeeper_v1>(own)
61 // { }
62
63 // Merge the content of another xAOD::CutBookkeeperContainer into this one
65 {
66 // Create an vector of indices of all the newly transferred CutBookkeepers
67 std::vector< std::size_t > newEBKIndices;
68 // Loop through otherCont.
69 // If element already in this container, update event counts, otherwise create new element
70 for ( std::size_t i=0; i<otherCont->size(); ++i ){
71 const xAOD::CutBookkeeper_v1* otherEBK = otherCont->at(i);
72
73 // Loop through this container and see if we find a match
74 bool foundEBKToUpdate(false);
75 for ( std::size_t j=0; j<this->size(); ++j ) {
76 xAOD::CutBookkeeper_v1* ebkToUpdate = this->at(j);
77 // Check if they are identical, if so, update; else add otherEBK
78 if ( otherEBK->isEqualTo(ebkToUpdate) ) {
79 ebkToUpdate->setPayload( ebkToUpdate->payload() + otherEBK->payload() );
80 foundEBKToUpdate = true;
81 break;
82 }
83 } // End: Inner loop over contToUpdate
84 if (!foundEBKToUpdate) {
86 if ( newEBK->usingPrivateStore() ) { newEBK->releasePrivateStore(); }
87 newEBK->makePrivateStore(otherEBK);
88 this->push_back( newEBK );
89 std::size_t ebIdx = newEBK->index();
90 newEBKIndices.push_back(ebIdx);
91 }
92 } // End: Outer loop over contToUpdate
93
94 // Now, we still need to fix the cross-referencing of the newly added CutBookkkeepers
95 for ( std::size_t i=0; i<newEBKIndices.size(); ++i ) {
96 std::size_t otherIndex = newEBKIndices.at(i);
97 xAOD::CutBookkeeper_v1* ebkToModify = this->at(otherIndex);
98
99 // Parent check
100 if ( ebkToModify->hasParent() ) {
101 const xAOD::CutBookkeeper_v1* oldParent = ebkToModify->parent();
102 xAOD::CutBookkeeperContainer_v1::iterator matchIter = std::find( this->begin(),
103 this->end(),
104 oldParent );
105 // If we found it, we can modify
106 if ( matchIter != this->end() ) {
107 ebkToModify->setParent( *matchIter );
108 }
109 // If we didn't find it, we need to add it
110 else {
112 if ( newEBK->usingPrivateStore() ) { newEBK->releasePrivateStore(); }
113 newEBK->makePrivateStore(oldParent);
114 this->push_back( newEBK );
115 ebkToModify->setParent( newEBK );
116 }
117 } // Done fixing parent
118
119 // Children check
120 for ( std::size_t oldIdx=0; oldIdx<ebkToModify->nChildren(); ++oldIdx ) {
121 const xAOD::CutBookkeeper_v1* oldEBK = ebkToModify->child(oldIdx);
122 xAOD::CutBookkeeperContainer_v1::iterator matchIter = std::find( this->begin(),
123 this->end(),
124 oldEBK );
125 // If we found it, we can modify
126 if ( matchIter != this->end() ) {
127 ebkToModify->addChild( *matchIter );
128 }
129 // If we didn't find it, we need to add it
130 else {
132 if ( newEBK->usingPrivateStore() ) { newEBK->releasePrivateStore(); }
133 newEBK->makePrivateStore(oldEBK);
134 this->push_back( newEBK );
135 ebkToModify->addChild( newEBK );
136 }
137 } // Done fixing children
138
139 // Used others check
140 for ( std::size_t oldIdx=0; oldIdx<ebkToModify->nUsedOthers(); ++oldIdx ) {
141 const xAOD::CutBookkeeper_v1* oldEBK = ebkToModify->usedOther(oldIdx);
142 xAOD::CutBookkeeperContainer_v1::iterator matchIter = std::find( this->begin(),
143 this->end(),
144 oldEBK );
145 // If we found it, we can modify
146 if ( matchIter != this->end() ) {
147 ebkToModify->addUsedOther( *matchIter );
148 }
149 // If we didn't find it, we need to add it
150 else {
152 if ( newEBK->usingPrivateStore() ) { newEBK->releasePrivateStore(); }
153 newEBK->makePrivateStore(oldEBK);
154 this->push_back( newEBK );
155 ebkToModify->addUsedOther( newEBK );
156 }
157 } // Done fixing used others
158
159 // Siblings check
160 for ( std::size_t oldIdx=0; oldIdx<ebkToModify->nSiblings(); ++oldIdx ) {
161 const xAOD::CutBookkeeper_v1* oldEBK = ebkToModify->sibling(oldIdx);
162 xAOD::CutBookkeeperContainer_v1::iterator matchIter = std::find( this->begin(),
163 this->end(),
164 oldEBK );
165 // If we found it, we can modify
166 if ( matchIter != this->end() ) {
167 ebkToModify->addSibling( *matchIter );
168 }
169 // If we didn't find it, we need to add it
170 else {
172 if ( newEBK->usingPrivateStore() ) { newEBK->releasePrivateStore(); }
173 newEBK->makePrivateStore(oldEBK);
174 this->push_back( newEBK );
175 ebkToModify->addSibling( newEBK );
176 }
177 } // Done fixing siblings
178 } // Done fixing all cross references
179 return;
180 }
181
182
183 // Get the minimum cycle number of any xAOD::CutBookkeepers in the container
185 {
186 // Now, iterate over all CutBookkeepers and search for the lowest cycle number
187 int minCycle=9999999;
188 for ( std::size_t i=0; i<this->size(); ++i ) {
189 // Get the current old EBK
190 const xAOD::CutBookkeeper_v1* cbk = this->at(i);
191 int inCycle = cbk->cycle();
192 if (inCycle < minCycle) minCycle = inCycle;
193 }
194 if (minCycle==9999999){ minCycle = 0; }
195 return minCycle;
196 }
197
198
199 // Get the maximum cycle number of any xAOD::CutBookkeepers in the container
201 {
202 // Now, iterate over all CutBookkeepers and search for the highest cycle number
203 int maxCycle=0;
204 for ( std::size_t i=0; i<this->size(); ++i ) {
205 // Get the current old EBK
206 const xAOD::CutBookkeeper_v1* cbk = this->at(i);
207 int inCycle = cbk->cycle();
208 if (inCycle > maxCycle) maxCycle = inCycle;
209 }
210 return maxCycle;
211 }
212
213} // namespace xAOD
const T * at(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
DataVector(SG::OwnershipPolicy ownPolicy=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
const_iterator end() const noexcept
const_iterator begin() const noexcept
SG::OwnershipPolicy ownPolicy() const
size_type size() const noexcept
Returns the number of elements in the collection.
void makePrivateStore()
Create a new (empty) private store for this object.
bool usingPrivateStore() const
Test to see if this object is currently using a private store.
void releasePrivateStore()
Release and free any private store associated with this object.
size_t index() const
Return the index of this element within its container.
CutBookkeeperContainer_v1(SG::OwnershipPolicy ownPolicy=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
Default Constructor.
void merge(const CutBookkeeperContainer_v1 *otherCont)
Merge the content of another xAOD::CutBookkeeperContainer into this one.
int minCycle() const
Get the minimum cycle number of any xAOD::CutBookkeepers in the container.
int maxCycle() const
Get the maximum cycle number of any xAOD::CutBookkeepers in the container.
Description of the class that is used to keep track of event counts.
std::size_t nSiblings() const
Check if this CutBookkeeper has siblings.
void addSibling(CutBookkeeper_v1 *siblingsEB)
Add one sibling CutBookkeeper to this one.
void setPayload(const Payload &payload)
Set the whole payload object (which contains all counters) in one go.
const xAOD::CutBookkeeper_v1 * usedOther(std::size_t i) const
Get the usedOther at position i.
bool isEqualTo(const CutBookkeeper_v1 *eb) const
Test for the equality of this CutBookkeeper with another one.
std::size_t nChildren() const
Get the number of children CutBookkeepers of this CutBookkeeper.
void addChild(CutBookkeeper_v1 *childEB)
Add one child to this CutBookkeeper.
const xAOD::CutBookkeeper_v1 * parent() const
Get the parent CutBookkeeper.
int cycle() const
Get the skimming cycle that this CutBookkeeper was running in.
const xAOD::CutBookkeeper_v1 * child(std::size_t i) const
Get the child at position i.
void setParent(const CutBookkeeper_v1 *parentEB)
Set the parent CutBookkeeper of this CutBookkeeper.
Payload payload() const
Get the whole payload object (which contains all counters) in one go.
void addUsedOther(CutBookkeeper_v1 *usedOtherEB)
Add one other CutBookkeeper that is used by this one.
const xAOD::CutBookkeeper_v1 * sibling(std::size_t i) const
Get the sibling number i.
std::size_t nUsedOthers() const
Check if this CutBookkeeper has used others.
bool hasParent() const
Check if there is a parent CutBookkeeper of this CutBookkeeper.
OwnershipPolicy
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.