2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5 * @file TileEvent/TileMutableDataContainer.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Helper for holding non-const raw data prior to recording in SG.
17 * @param createColl If true, create all collections now.
18 * @param type Hash type (from TileFragHash::TYPE).
19 * @param unit Measurement units for amplitude data.
20 * @param ownPolicy Ownership mode for collections.
22 * Call status() after this to check for errors.
25TileMutableDataContainer<BASE>::TileMutableDataContainer
26 (bool createColl /*= false*/,
27 TYPE type /*= TileFragHash::Default*/,
28 UNIT unit /*= TileRawChannelUnit::ADCcounts*/,
29 SG::OwnershipPolicy ownPolicy /*= SG::OWN_ELEMENTS*/)
30 : BASE (false, type, unit, ownPolicy),
32 m_sc (StatusCode::SUCCESS),
37 // Create all collections.
38 const TileFragHash& hashFunc = this->hashFunc();
39 int ncoll = hashFunc.max();
40 for (int i=0; i<ncoll;++i) {
41 TileFragHash::ID frag = hashFunc.identifier(i);
42 auto coll = std::make_unique<Collection> (frag, ownPolicy) ;
43 if (addCollection (std::move (coll),
44 static_cast<IdentifierHash>(i)).isFailure())
46 m_sc = StatusCode::FAILURE;
54 * @brief Copy constructor.
55 * @param other Container to copy.
57 * This is a deep copy; all contained collections and channels will be copied.
58 * Call status() after this to check for errors.
61TileMutableDataContainer<BASE>::TileMutableDataContainer
68 m_sc (StatusCode::SUCCESS),
69 m_defaultType (other.get_type()),
70 m_defaultUnit (other.get_unit())
72 this->set_bsflags (other.get_bsflags());
73 for (IdentifierHash hash : other.GetAllCurrentHashes()) {
74 const Collection* coll = other.indexFindPtr (hash);
75 auto newColl = std::make_unique<Collection> (*coll);
76 if (addCollection (std::move (newColl), hash).isFailure()) {
77 m_sc = StatusCode::FAILURE;
84 * @brief Add a collection to the container.
85 * @param coll Collection ot add.
86 * @param hash Hash value for the collection.
88 * We maintain a non-const reference to the collection.
92TileMutableDataContainer<BASE>::addCollection (std::unique_ptr<Collection> coll,
95 if (!hash.is_valid()) {
96 throw std::out_of_range ("TileMutableDataContainer::addCollection");
98 if (hash >= m_mutableCollections.size()) {
99 m_mutableCollections.resize (hash+1);
101 m_mutableCollections.at(hash) = coll.get();
102 return BASE::addOrDelete (std::move (coll), hash);
107 * @brief Add a new channel.
108 * @param rch Channel to add.
110 * This should be used for owning container (created with SG::OWN_ELEMENTS).
111 * A new collection will be created if needed.
112 * In that case, we maintain a non-const reference to it.
116TileMutableDataContainer<BASE>::push_back (std::unique_ptr<Element> rch)
118 int frag = rch->frag_ID();
119 IdentifierHash hash = static_cast<IdentifierHash>(this->hashFunc()(frag));
121 // Find the collection; create a new one if needed.
122 Collection* coll = indexFindPtr (hash);
124 auto newColl = std::make_unique<Collection> (frag, SG::OWN_ELEMENTS);
125 coll = newColl.get();
126 if (addCollection (std::move (newColl), hash).isFailure()) {
127 return StatusCode::FAILURE;
131 coll->push_back (std::move (rch));
132 return StatusCode::SUCCESS;
137 * @brief Add a new channel.
138 * @param rch Channel to add.
140 * This should be used for non-owning container (created with SG::VIEW_ELEMENTS).
141 * A new collection will be created if needed.
142 * In that case, we maintain a non-const reference to it.
146TileMutableDataContainer<BASE>::push_back (Element* rch)
148 int frag = rch->frag_ID();
149 IdentifierHash hash = static_cast<IdentifierHash>(this->hashFunc()(frag));
151 // Find the collection; create a new one if needed.
152 Collection* coll = indexFindPtr (hash);
154 auto newColl = std::make_unique<Collection> (frag, SG::OWN_ELEMENTS);
155 coll = newColl.get();
156 if (addCollection (std::move (newColl), hash).isFailure()) {
157 return StatusCode::FAILURE;
161 coll->push_back (rch);
162 return StatusCode::SUCCESS;
167 * @brief Look up a (non-const) collection via hash.
168 * @param hash Hash value to find.
171//coverity[BAD_OVERRIDE]
172typename TileMutableDataContainer<BASE>::Collection*
173TileMutableDataContainer<BASE>::indexFindPtr (IdentifierHash hash)
175 if (!m_locked && hash < m_mutableCollections.size()) {
176 return m_mutableCollections[hash];
183 * @brief Return the error status from the constructors.
186StatusCode TileMutableDataContainer<BASE>::status() const
193 * @brief Lock this object.
195 * Called when this object is locked in SG.
196 * Prohibit non-const acces to this container.
199void TileMutableDataContainer<BASE>::lock()
206 * @brief Recycle this object for use in another event.
208 * This is called from AthenaKernel/RecyclableDataObject when this object
209 * is released by StoreGate. Unlock the object so that non-const access
210 * is again possible, and clear out the contents if the collections.
213void TileMutableDataContainer<BASE>::recycle()
215 // ??? Try to verify that this object is not in SG? Check refcount??
217 for (IdentifierHash hash : this->GetAllCurrentHashes()) {
218 Collection* coll = this->indexFindPtr (hash);
222 this->set_type (m_defaultType);
223 this->set_unit (m_defaultUnit);
224 this->set_bsflags (0);