ATLAS Offline Software
Loading...
Searching...
No Matches
CaloSamplingData.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef CALOEVENT_CALOSAMPLINGDATA_H
8#define CALOEVENT_CALOSAMPLINGDATA_H
9
10#include "CaloGeoHelpers/CaloSampling.h"
13
14#include <vector>
15#include <algorithm>
16
18{
19 public:
20
25
27 typedef double value_type;
29 typedef std::vector<value_type> variable_store_type;
30
32 typedef std::vector<value_type> const_vector_type;
34 typedef std::vector<value_type> vector_type;
35
39 CaloSamplingData(unsigned int varTypePattern);
41 explicit CaloSamplingData(const CaloSamplingData& rData);
42 explicit CaloSamplingData(const CaloSamplingData* pData);
46
47 void swap (CaloSamplingData& other);
48
51
53 size_t getNumberOfSamplings() const;
55 size_t getNumberOfSamplings(variable_key_type theVariable) const;
56
58 size_t getNumberOfVariableTypes() const;
59
62 sampling_key_type theSampling) const;
65 sampling_key_type theSampling);
67 bool retrieveData(variable_key_type theVariable,
68 vector_type& theData) const;
69
71 bool removeVariable(variable_key_type theVariable,
72 sampling_key_type theSampling);
74 bool removeVariable(variable_key_type theVariable);
76 bool removeVariable(sampling_key_type theSampling);
77 /*{! \brief Clear the store */
78 bool removeVariable();
79 bool clearStore();
81
83 bool storeData(variable_key_type theVariable,
84 sampling_key_type theSampling,
85 value_type theData);
87 bool storeData(variable_key_type theVariable,
88 const vector_type& theData);
90 template <class Iterator>
91 bool storeData(variable_key_type theVariable, Iterator beg, Iterator end);
92
94 bool contains(variable_key_type theVariable) const;
95
96 protected:
97
99 {
100 public:
101 bool operator()(value_type theData)
102 { return theData != value_type(); }
103 };
104
105 private:
114
116
117 unsigned int m_varTypePattern;
118
119 bool setupStores();
120
121 unsigned int getBitPattern(variable_key_type theVariable) const;
122
123 bool checkBitPattern(variable_key_type theVariable);
124 bool testBitPattern(variable_key_type theVariable) const;
125 bool clearBitPattern(variable_key_type theVariable);
126 bool clearBitPattern();
127 bool testConstPattern() const;
128
129 size_t index (size_t theVariable, size_t theSampling) const;
130 size_t fastNsamp() const;
131};
132
150
151
155
159
163
167
171
172
174
176// Retrieve Data Helpers //
178
188
191
207 sampling_key_type theSampling)
208{
209 m_varTypePattern = m_varTypePattern | this->getBitPattern(theVariable);
210 return m_dataStore[index(theVariable, theSampling)];
211}
212
226 sampling_key_type theSampling) const
227{
228 return m_dataStore[index(theVariable, theSampling)];
229}
230
232// Store And Erase Data Helper //
234
235
247inline bool
249 sampling_key_type theSampling)
250{
251 m_dataStore[index(theVariable,theSampling)] = value_type();
252 return true;
253}
254inline bool
256{
257 variable_store_type::iterator beg =
258 m_dataStore.begin() + index (0, theSampling);
259 variable_store_type::iterator end = m_dataStore.end();
260 int nsamp = fastNsamp();
261 for (; beg < end; beg += nsamp)
262 *beg = value_type();
263 return true;
264}
265inline bool
267{
268 size_t idx = index (theVariable, 0);
269 std::fill_n (m_dataStore.begin() + idx, fastNsamp(), value_type());
270 return true;
271}
272inline bool
274{
275 std::fill (m_dataStore.begin(), m_dataStore.end(), value_type());
276 return this->clearBitPattern();
277}
278inline bool CaloSamplingData::clearStore() { return this->removeVariable(); }
280
281inline bool
283{ return this->testBitPattern(theVariable); }
284
285inline unsigned int
288
289inline bool
291{
292 unsigned int testBit(this->getBitPattern(theVariable));
293 if (testBit == 0) return false;
294 return ( m_varTypePattern & testBit ) == testBit;
295}
296
299
300inline
301size_t CaloSamplingData::index (size_t theVariable, size_t theSampling) const
302{
303 return theVariable * fastNsamp() + theSampling;
304}
305
306inline
308{
309 return (size_t)(CaloSampling::Unknown);
310}
311
312
313template <class Iterator>
315 Iterator beg, Iterator end)
316{
317 //Check const bit and set m_varTypePattern
318 if (!this->checkBitPattern (theVariable))
319 return false;
320 if (beg == end)
321 return false;
322 variable_store_type::iterator output =
323 m_dataStore.begin() + index(theVariable, 0);
324 CxxUtils::copy_bounded (beg, end, output, output + fastNsamp());
325 return true;
326
327}
328
329#endif
Functor to check if data is valid (non-zero)
bool operator()(value_type theData)
std::vector< value_type > const_vector_type
Vector type for data exchange (read only)
unsigned int getBitPattern(variable_key_type theVariable) const
void swap(CaloSamplingData &other)
size_t fastNsamp() const
size_t index(size_t theVariable, size_t theSampling) const
size_t getNumberOfSamplings() const
Set variable type pattern for this store.
friend class CaloSamplingDataCnv_p1
std::vector< value_type > vector_type
Vector type for data exchange (read/write)
friend class CaloClusterContainerCnv_p6
CaloVariableType::VariableType variable_key_type
Variable look-up type.
unsigned int m_varTypePattern
bool checkBitPattern(variable_key_type theVariable)
CaloSamplingData()
Constructor.
value_type retrieveData(variable_key_type theVariable, sampling_key_type theSampling) const
Retrieve const reference to individual variable.
double value_type
General data type.
bool testConstPattern() const
CaloSampling::CaloSample sampling_key_type
Sampling look-up key type.
friend class CaloClusterContainerCnvTest_p7
friend class CaloSamplingDataContainerCnv_p1
size_t getNumberOfVariableTypes() const
Return number of variable types.
virtual ~CaloSamplingData()
Destructor.
std::vector< value_type > variable_store_type
Sampling look-up table type, internal use only.
bool testBitPattern(variable_key_type theVariable) const
CaloSamplingData(const CaloSamplingData &rData)
Copy constructor.
friend class CaloClusterContainerCnv_p4
friend class CaloClusterContainerCnv_p7
friend class CaloClusterContainerCnv_p5
bool storeData(variable_key_type theVariable, sampling_key_type theSampling, value_type theData)
}
friend class CaloClusterContainerCnvTest_p6
CaloSamplingData & operator=(const CaloSamplingData &)
variable_store_type m_dataStore
bool contains(variable_key_type theVariable) const
Check on available variable types.
static constexpr unsigned int getNumberOfSamplings()
Get number of available samplings.
Copy a range with bounds restriction.
OutputIterator copy_bounded(InputIterator begi, InputIterator endi, OutputIterator bego, OutputIterator endo)
Copy a range with bounds restriction.
Definition index.py:1
static unsigned int getVariableBit(const VariableType &varType)
static bool checkConst(const unsigned int &bitPattern)
static unsigned int getNumberOfVariables()