12#include "AthLinks/ElementLink.h"
37 cell_t (
int the_cell = 0,
39 : cell (the_cell), weight (the_weight) {}
40 bool operator< (
const cell_t& other)
const {
return cell <
other.cell; }
41 bool operator== (
const cell_t& other)
const {
return cell ==
other.cell; }
52const float NWEIGHT_SCALE = 1000;
55const int INDEX_BITS = 18;
58const unsigned int INDEX_MASK = (1<<INDEX_BITS) - 1;
61const int ISEQ_BITS = 32 - INDEX_BITS;
64const unsigned int ISEQ_MAX = (1 << ISEQ_BITS) - 1;
89 "CaloCellLinkContainerCnv_p2")
90 <<
"Inconsistent sequence array lengths: "
97 std::vector<unsigned>::const_iterator cIterI = pers->
m_linkI.begin();
98 std::vector<unsigned>::const_iterator cIterIe = pers->
m_linkI.end();
99 std::vector<float>::const_iterator cIterW = pers->
m_linkW.begin();
100 std::vector<float>::const_iterator cIterWe = pers->
m_linkW.end();
102 for (
unsigned int iCluster=0; iCluster<pers->
m_nClusters; iCluster++) {
104 std::vector<float>::const_iterator cIterWb = cIterW;
108 trans->at(iCluster)=lnk;
114 unsigned int ncells = 0;
115 for(
unsigned iCell=0; iCell<pers->
m_vISizes[iCluster]; iCell++) {
116 if (cIterI >= cIterIe) {
118 "CaloCellLinkContainerCnv_p2")
119 <<
"Cell index array overrun";
123 ncells += (*(cIterI+iCell)) >> INDEX_BITS;
125 if (ncells > 1000) ncells = 1000;
128 for(
unsigned iCell=0; iCell<pers->
m_vISizes[iCluster]; iCell++) {
129 unsigned int compositeI = *cIterI++;
130 unsigned int realI = compositeI & INDEX_MASK;
131 unsigned int lSEQ = compositeI>>INDEX_BITS;
132 for(
unsigned seq=0;seq<lSEQ;seq++) {
134 if (cIterW >= cIterWe) {
136 "CaloCellLinkContainerCnv_p2")
137 <<
"Cell weight array overrun";
141 float compositeW = *cIterW++;
142 nw =
static_cast<unsigned int> (compositeW*(1./NWEIGHT_SCALE));
143 weight = compositeW - (nw*NWEIGHT_SCALE);
154 "CaloCellLinkContainerCnv_p2")
155 <<
"Weight/index arrays out of sync";
159 if (cIterW - cIterWb !=
static_cast<int> (pers->
m_vWSizes[iCluster])) {
161 "CaloCellLinkContainerCnv_p2")
162 <<
"Wrong number of weight sequences";
169 "CaloCellLinkContainerCnv_p2")
170 <<
"Missing cell container name";
176 "CaloCellLinkContainerCnv_p2")
177 <<
"Discarding cluster cells";
197 unsigned int nclus =
trans->size();
206 pers->
m_linkI.reserve (5*nclus);
207 pers->
m_linkW.reserve (5*nclus);
216 std::vector<cell_t> cells;
217 for (
unsigned int iCluster = 0; iCluster < nclus; ++iCluster) {
223 cells.reserve (lnk.
size()+1);
227 for (;it_cell!=it_cell_e;it_cell++) {
232 float weight = citer->second;
234 if (fabs (weight) > NWEIGHT_SCALE) {
236 "CaloCellLinkContainerCnv_p2")
237 <<
"Crazy cluster cell weight " << weight
242 size_t index = citer->first.index();
247 thinningCache->
thinning (citer->first.key());
264 citer->first.source()->tryELRemap (key,
index, key,
index);
267 pers->
m_contName = *citer->first.source()->keyToString (key);
270 else if (first_key != key) {
272 "CaloCellLinkContainerCnv_p2")
273 <<
"Multiple container names seen; "
274 <<
"cannot be persistified correctly: "
276 <<
" != " << *citer->first.source()->keyToString (key)
281 if ((
index & ~INDEX_MASK) != 0) {
283 "CaloCellLinkContainerCnv_p2")
284 <<
"Bad cell index " <<
index
285 <<
" had high bits masked off.";
288 cells.push_back (cell_t (
index, weight));
294 unsigned int& nlseq = pers->
m_vISizes[iCluster];
295 unsigned int& nwseq = pers->
m_vWSizes[iCluster];
298 int last_cell = -9999;
299 float last_weight = -9999;
300 unsigned int nl_in_seq = 0;
301 unsigned int nw_in_seq = 0;
304 cells.push_back (cell_t (-99999, -99999));
306 size_t ncells = cells.size();
307 for (
size_t i = 0; i < ncells; ++i) {
308 const cell_t& cell = cells[i];
310 if (last_cell >= 0 &&
static_cast<int>(last_cell + nl_in_seq) == cell.cell &&
311 nl_in_seq < ISEQ_MAX)
317 pers->
m_linkI.push_back (last_cell | (nl_in_seq << INDEX_BITS));
320 last_cell = cell.cell;
334 float w1 = (nw_in_seq+1)*NWEIGHT_SCALE + last_weight;
335 float w2 = (nw_in_seq+1)*NWEIGHT_SCALE + cell.weight;
337 if (equal (nextafterf (w1, w2), w2) && nw_in_seq < 255)
343 pers->
m_linkW.push_back (nw_in_seq*NWEIGHT_SCALE + last_weight);
346 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.
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.
TH1F * trans(TH1F *h, bool t=false)
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.