12#include "AthLinks/ElementLink.h"
36 cell_t (
int the_cell = 0,
38 : cell (the_cell), weight (the_weight) {}
39 bool operator< (
const cell_t& other)
const {
return cell <
other.cell; }
40 bool operator== (
const cell_t& other)
const {
return cell ==
other.cell; }
51const float NWEIGHT_SCALE = 1000;
54const int INDEX_BITS = 18;
57const unsigned int INDEX_MASK = (1<<INDEX_BITS) - 1;
60const int ISEQ_BITS = 32 - INDEX_BITS;
63const unsigned int ISEQ_MAX = (1 << ISEQ_BITS) - 1;
88 "CaloCellLinkContainerCnv_p2")
89 <<
"Inconsistent sequence array lengths: "
96 std::vector<unsigned>::const_iterator cIterI = pers->
m_linkI.begin();
97 std::vector<unsigned>::const_iterator cIterIe = pers->
m_linkI.end();
98 std::vector<float>::const_iterator cIterW = pers->
m_linkW.begin();
99 std::vector<float>::const_iterator cIterWe = pers->
m_linkW.end();
101 for (
unsigned int iCluster=0; iCluster<pers->
m_nClusters; iCluster++) {
103 std::vector<float>::const_iterator cIterWb = cIterW;
107 trans->
at(iCluster)=lnk;
113 unsigned int ncells = 0;
114 for(
unsigned iCell=0; iCell<pers->
m_vISizes[iCluster]; iCell++) {
115 if (cIterI >= cIterIe) {
117 "CaloCellLinkContainerCnv_p2")
118 <<
"Cell index array overrun";
122 ncells += (*(cIterI+iCell)) >> INDEX_BITS;
124 if (ncells > 1000) ncells = 1000;
127 for(
unsigned iCell=0; iCell<pers->
m_vISizes[iCluster]; iCell++) {
128 unsigned int compositeI = *cIterI++;
129 unsigned int realI = compositeI & INDEX_MASK;
130 unsigned int lSEQ = compositeI>>INDEX_BITS;
131 for(
unsigned seq=0;seq<lSEQ;seq++) {
133 if (cIterW >= cIterWe) {
135 "CaloCellLinkContainerCnv_p2")
136 <<
"Cell weight array overrun";
140 float compositeW = *cIterW++;
141 nw =
static_cast<unsigned int> (compositeW*(1./NWEIGHT_SCALE));
142 weight = compositeW - (nw*NWEIGHT_SCALE);
153 "CaloCellLinkContainerCnv_p2")
154 <<
"Weight/index arrays out of sync";
158 if (cIterW - cIterWb !=
static_cast<int> (pers->
m_vWSizes[iCluster])) {
160 "CaloCellLinkContainerCnv_p2")
161 <<
"Wrong number of weight sequences";
168 "CaloCellLinkContainerCnv_p2")
169 <<
"Missing cell container name";
175 "CaloCellLinkContainerCnv_p2")
176 <<
"Discarding cluster cells";
196 unsigned int nclus = trans->
size();
205 pers->
m_linkI.reserve (5*nclus);
206 pers->
m_linkW.reserve (5*nclus);
215 std::vector<cell_t> cells;
216 for (
unsigned int iCluster = 0; iCluster < nclus; ++iCluster) {
222 cells.reserve (lnk.
size()+1);
226 for (;it_cell!=it_cell_e;it_cell++) {
231 float weight = citer->second;
233 if (fabs (weight) > NWEIGHT_SCALE) {
235 "CaloCellLinkContainerCnv_p2")
236 <<
"Crazy cluster cell weight " << weight
241 size_t index = citer->first.index();
246 thinningCache->
thinning (citer->first.key());
263 citer->first.source()->tryELRemap (key,
index, key,
index);
266 pers->
m_contName = *citer->first.source()->keyToString (key);
269 else if (first_key != key) {
271 "CaloCellLinkContainerCnv_p2")
272 <<
"Multiple container names seen; "
273 <<
"cannot be persistified correctly: "
275 <<
" != " << *citer->first.source()->keyToString (key)
280 if ((
index & ~INDEX_MASK) != 0) {
282 "CaloCellLinkContainerCnv_p2")
283 <<
"Bad cell index " <<
index
284 <<
" had high bits masked off.";
287 cells.push_back (cell_t (
index, weight));
293 unsigned int& nlseq = pers->
m_vISizes[iCluster];
294 unsigned int& nwseq = pers->
m_vWSizes[iCluster];
297 int last_cell = -9999;
298 float last_weight = -9999;
299 unsigned int nl_in_seq = 0;
300 unsigned int nw_in_seq = 0;
303 cells.push_back (cell_t (-99999, -99999));
305 size_t ncells = cells.size();
306 for (
size_t i = 0; i < ncells; ++i) {
307 const cell_t& cell = cells[i];
309 if (last_cell >= 0 &&
static_cast<int>(last_cell + nl_in_seq) == cell.cell &&
310 nl_in_seq < ISEQ_MAX)
316 pers->
m_linkI.push_back (last_cell | (nl_in_seq << INDEX_BITS));
319 last_cell = cell.cell;
333 float w1 = (nw_in_seq+1)*NWEIGHT_SCALE + last_weight;
334 float w2 = (nw_in_seq+1)*NWEIGHT_SCALE + cell.weight;
336 if (equal (nextafterf (w1, w2), w2) && nw_in_seq < 255)
342 pers->
m_linkW.push_back (nw_in_seq*NWEIGHT_SCALE + last_weight);
345 last_weight = cell.weight;
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
bool operator<(const DataVector< T > &a, const DataVector< T > &b)
Vector ordering relation.
bool operator==(const DataVector< T > &a, const DataVector< T > &b)
Vector equality comparison.
Hold thinning decisions for one container.
virtual void transToPersWithKey(const CaloCellLinkContainer *trans, CaloCellLinkContainer_p2 *pers, const std::string &key, MsgStream &log) const override
Convert from transient to persistent object.
virtual void persToTransWithKey(const CaloCellLinkContainer_p2 *pers, CaloCellLinkContainer *trans, const std::string &key, MsgStream &log) const override
Convert from persistent to transient object.
std::vector< unsigned > m_linkI
std::vector< unsigned > m_vISizes
std::vector< unsigned > m_vWSizes
std::vector< float > m_linkW
Container class for CaloCellLink.
Simple store for CaloCell links.
Navigable< CaloCellContainer, double >::object_iter cell_iterator
Forward internal iterator type to clients.
void resize(size_type sz)
Resizes the collection to the specified number of elements.
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
void clear()
Erase all the elements in the collection.
ElementLink implementation for ROOT usage.
COLL::const_iterator getInternalIterator() const
virtual unsigned int size() const
virtual object_iter begin() const
void insertElement(const CONT *objectContainer, const constituent_type *constituentObject, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
virtual object_iter end() const
constituent_coll::const_iterator constituent_const_iter
Cache thinning decisions for converters.
const ThinningDecisionBase * thinning(const std::string &key) const
Return thinning for key.
Hold thinning decisions for one container.
static const std::size_t RemovedIdx
Flag used to show that an index has been thinned away.
size_t index(size_t ndxOrig) const
Return the index corresponding to ndxOrig after thinning.
Workaround x86 precision issues for FP inequality comparisons.
Helpers to retrieve the current thinning cache from the event context.
bool equal(double a, double b)
Compare two FP numbers, working around x87 precision issues.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
const SG::ThinningCache * getThinningCache()
Retrieve the current thinning cache from the current event context.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.