ATLAS Offline Software
Loading...
Searching...
No Matches
EventFeature.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6
8
10
11#include <algorithm>
12#include <cmath>
13
14const std::map<EventFeature::FeatureType,std::string> EventFeature::m_featureTags = {
15 {ETDENSITY, "ETDENSITY"},
16 {ETDENSITY_JETAREA, "ETDESNSITY_JETAREA"},
17 {ETDENSITY_JETAREA_ETA, "ETDENSITY_JETAREA_ETA"},
18 {ETDENSITY_ETA_WINDOWS, "ETDENSITY_ETA_WINDOWS"},
19 {ETDENSITY_USER, "ETDENSITY_USER"},
20 {UNKNOWN, "UNKNOWN"},
21 {DEFAULT, "DEFAULT"},
22};
23
26
28{
29 std::map<FeatureType,std::string>::const_iterator fMap(m_featureTags.begin());
30 std::map<FeatureType,std::string>::const_iterator lMap(m_featureTags.end());
31 while ( fMap != lMap && tag != fMap->second ) { ++ fMap; }
32 return fMap != lMap ? fMap->first : UNKNOWN;
33}
34
35const std::string& EventFeature::featureTag()
36{
37 auto it = m_featureTags.find(DEFAULT);
38 if (it == m_featureTags.end()) std::abort();
39 return it->second;
40}
41
43{
44 std::map<FeatureType,std::string>::const_iterator fMap(m_featureTags.find(type));
45 if (fMap != m_featureTags.end()) {
46 return fMap->second;
47 }
48 fMap = m_featureTags.find (UNKNOWN);
49 if (fMap == m_featureTags.end()) std::abort();
50 return fMap->second;
51}
52
55 , m_tag("Default")
56 , m_dataWords(0)
57 , m_dataBlocks(0)
59 , m_dataList(std::vector<double>())
60 , m_structureFixed(false)
61{ }
62
64 const std::string& tag,
65 const std::vector<double>& dataList)
66 : m_type(type)
67 , m_tag(tag)
68 , m_dataWords(dataList.size())
69 , m_dataBlocks(1)
70 , m_dataList(dataList.begin(),dataList.end())
71 , m_structureFixed(true)
72{
73 this->setFeatureStructure();
74}
75
77 unsigned int nWords,
78 const std::vector<double>& dataList)
79 : m_type(type)
80 , m_tag(tag)
81 , m_dataWords(nWords)
83 , m_dataList(dataList.begin(),dataList.end())
84 , m_structureFixed(true)
85{
86 this->setFeatureStructure();
87}
88
90 unsigned int nWords)
91 : m_type(type)
92 , m_tag(tag)
93 , m_dataWords(nWords)
94 , m_dataBlocks(0)
95 , m_dataList(std::vector<double>())
96 , m_structureFixed(true)
97{
98 this->setFeatureStructure();
99}
100
102 : m_type(feature.m_type)
103 , m_tag(feature.m_tag)
104 , m_dataWords(feature.m_dataWords)
105 , m_dataBlocks(feature.m_dataBlocks)
106 , m_dataList(feature.dataList().begin(),feature.dataList().end())
108{
109 this->setFeatureStructure();
110}
111
114
116{
117 if (this != &feature) {
118 m_type = feature.m_type;
119 m_tag = feature.m_tag;
120 m_dataWords = feature.m_dataWords;
121 m_dataBlocks = feature.m_dataBlocks;
123 if ( feature.m_dataList.empty() )
124 {
125 m_dataList.clear();
126 }
127 else
128 {
129 m_dataList.resize(feature.m_dataList.size());
130 std::copy(feature.m_dataList.begin(),feature.m_dataList.end(),
131 m_dataList.begin());
132 }
133 this->setFeatureStructure();
134 }
135 return *this;
136}
137
138bool EventFeature::dataBlock(size_t blockIdx,std::vector<double>& data)
139{
140
141 // get index range
142 index_t idx(0,0);
143 if ( !this->indexRange(blockIdx,idx) ) return false;
144 // copy data
145 for ( size_t i(idx.first); i<idx.second; ++i )
146 {
147 data.push_back(m_dataList.at(i));
148 }
149 return !data.empty();
150}
151
152bool EventFeature::setDataBlock(size_t blockIdx,
153 const std::vector<double>& data,
154 bool replace)
155{
156 // get index range and check if replacement
157 index_t idx(0,0);
158 bool inRange(this->indexRange(blockIdx,idx));
159 if ( inRange && !replace ) return false;
160 // replace or add
161 if ( !inRange ) return this->addDataBlock(idx.first,idx.second,data);
162 return this->insertDataBlock(idx.first,idx.second,data);
163}
164
165bool EventFeature::addDataBlock(const std::vector<double>& data)
166{
167 index_t idx(0,0);
168 this->indexRange(m_dataBlocks+1,idx);
169 return addDataBlock(idx.first,idx.second,data);
170}
171
172bool EventFeature::addDataBlock(size_t startIdx,size_t endIdx,
173 const std::vector<double>& data)
174{
176 size_t imax(std::min(endIdx-startIdx,data.size()));
177 for ( size_t i(0); i<imax; ++i ) { m_dataList[i+startIdx] = data.at(i); }
178 this->setFeatureStructure();
179 return imax>0;
180}
181
182bool EventFeature::insertDataBlock(size_t startIdx,size_t endIdx,
183 const std::vector<double>& data)
184{
185 size_t imax(std::min(endIdx-startIdx,data.size()));
186 for ( size_t i(0); i<imax; ++i ) { m_dataList[i+startIdx] = data.at(i); }
187 return imax>0;
188}
189
191{
192 if ( !m_structureFixed && nWords <= (unsigned int)NDATAWORDS )
193 {
194 m_dataWords = nWords;
195 m_dataBlocks = 0;
196 this->setFeatureStructure(true);
197 m_structureFixed = true;
198 }
199}
200
202{
203 if ( nBlocks <= (size_t)
204 (((unsigned int)NDATABLOCKS)>>(unsigned int)BITSHIFT) )
205 {
206 m_dataBlocks = nBlocks;
207 this->setFeatureStructure(true);
208 }
209}
210
212{
213 if ( updateCache )
214 {
215 size_t cacheSize(m_dataWords*m_dataBlocks);
217 }
218 // update
220 // construct feature structure
221 this->buildFeatureStructure();
222}
223
225{
227 (m_dataWords&(unsigned int)NDATAWORDS) |
228 ((m_dataBlocks&(unsigned int)NDATABLOCKS)<<(unsigned int)BITSHIFT);
229 return m_featureStructure;
230}
231
232bool EventFeature::indexRange(size_t startIdx,index_t& idx)
233{
234 this->setFeatureStructure(false);
235 size_t locIdx(startIdx*m_dataWords+m_dataBlocks);
236 if ( locIdx > m_dataList.size() ) return false;
237 idx.first = startIdx;
238 idx.second = locIdx;
239 return true;
240}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
bool inRange(const double *boundaries, const double value, const double tolerance=0.02)
int imax(int i, int j)
std::string m_tag
Internal cache for feature tag.
unsigned int buildFeatureStructure()
Build compressed feature structure.
void setNumberDataWords(size_t nWords)
Set number of data words per block.
static FeatureType featureType()
Default feature type.
FeatureType type() const
Retrieve feature type.
std::vector< double > m_dataList
Internal cache for vector data.
bool setDataBlock(size_t blockIdx, const std::vector< double > &data, bool replace=true)
Set one data block.
EventFeature & operator=(const EventFeature &feature)
Assignment operator.
static const std::map< FeatureType, std::string > m_featureTags
Lookup for feature type and tag matches.
unsigned int m_dataBlocks
Internal cache for data structure descriptor (number of blocks)
void setNumberDataBlocks(size_t nBlocks)
Set number of blocks.
virtual ~EventFeature()
Destructor.
static const std::string & featureTag()
Default feature tag.
FeatureType m_type
Internal cache for feature type.
unsigned int m_dataWords
Internal cache data structure description (words per block)
bool addDataBlock(const std::vector< double > &data)
@ UNKNOWN
Unknown type.
@ DEFAULT
Default type.
void setFeatureStructure(bool updateCache=false)
Set/update feature structure.
bool dataBlock(size_t blockIdx, std::vector< double > &data)
Return one datablock.
const std::vector< double > & dataList() const
Retrieve reference to vector store.
bool indexRange(size_t startIdx, index_t &idx)
bool insertDataBlock(size_t startIdx, size_t endIdx, const std::vector< double > &data)
std::pair< size_t, size_t > index_t
bool m_structureFixed
Control flag for setting number of data words.
unsigned int m_featureStructure
Internal cache for compressed data structure descriptor.
const std::string & tag() const
Retrieve feature tag.
EventFeature()
Default constructor.
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310
STL namespace.
static double invalidValue()
static double nullValue()