ATLAS Offline Software
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 
14 const 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 
25 { return EventFeature::DEFAULT; }
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 
35 const 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 
54  : m_type(UNKNOWN)
55  , m_tag("Default")
56  , m_dataWords(0)
57  , m_dataBlocks(0)
58  , m_featureStructure(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)
82  , m_dataBlocks(dataList.size()/m_dataWords)
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())
107  , m_structureFixed(feature.m_structureFixed)
108 {
109  this->setFeatureStructure();
110 }
111 
113 { }
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 
138 bool 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 
152 bool 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 
165 bool 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 
172 bool 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 
182 bool 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 
211 void EventFeature::setFeatureStructure(bool updateCache)
212 {
213  if ( updateCache )
214  {
215  size_t cacheSize(m_dataWords*m_dataBlocks);
216  m_dataList.resize(cacheSize,EventShapeConstants::invalidValue());
217  }
218  // update
219  if ( m_dataWords > 0 ) m_dataBlocks = m_dataList.size()/m_dataWords;
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 
232 bool 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 }
python.StoreID.UNKNOWN
int UNKNOWN
Definition: StoreID.py:16
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
DEFAULT
@ DEFAULT
Definition: sTGCenumeration.h:15
EventFeature::m_featureTags
static const std::map< FeatureType, std::string > m_featureTags
Lookup for feature type and tag matches.
Definition: EventFeature.h:242
EventFeature::m_structureFixed
bool m_structureFixed
Control flag for setting number of data words.
Definition: EventFeature.h:239
EventFeature::m_type
FeatureType m_type
Internal cache for feature type.
Definition: EventFeature.h:223
EventShapeConstants::nullValue
static double nullValue()
Definition: StaticConstants.h:24
EventFeature::m_dataBlocks
unsigned int m_dataBlocks
Internal cache for data structure descriptor (number of blocks)
Definition: EventFeature.h:229
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
EventFeature::addDataBlock
bool addDataBlock(const std::vector< double > &data)
Definition: EventFeature.cxx:165
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:407
EventFeature::featureType
static FeatureType featureType()
Default feature type.
Definition: EventFeature.cxx:24
EventFeature
Basic container for event feature data.
Definition: EventFeature.h:18
EventFeature::DEFAULT
@ DEFAULT
Default type.
Definition: EventFeature.h:32
EventFeature::type
FeatureType type() const
Retrieve feature type.
Definition: EventFeature.h:283
EventFeature::buildFeatureStructure
unsigned int buildFeatureStructure()
Build compressed feature structure.
Definition: EventFeature.cxx:224
EventFeature::NDATABLOCKS
@ NDATABLOCKS
Definition: EventFeature.h:42
EventFeature::m_tag
std::string m_tag
Internal cache for feature tag.
Definition: EventFeature.h:225
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
EventFeature::m_featureStructure
unsigned int m_featureStructure
Internal cache for compressed data structure descriptor.
Definition: EventFeature.h:231
EventFeature::indexRange
bool indexRange(size_t startIdx, index_t &idx)
Definition: EventFeature.cxx:232
EventFeature::index_t
std::pair< size_t, size_t > index_t
Definition: EventFeature.h:206
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
EventFeature::UNKNOWN
@ UNKNOWN
Unknown type.
Definition: EventFeature.h:31
lumiFormat.i
int i
Definition: lumiFormat.py:85
StaticConstants.h
vector
Definition: MultiHisto.h:13
EventFeature::setNumberDataWords
void setNumberDataWords(size_t nWords)
Set number of data words per block.
Definition: EventFeature.cxx:190
EventShapeConstants::invalidValue
static double invalidValue()
Definition: StaticConstants.h:22
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
EventFeature::EventFeature
EventFeature()
Default constructor.
Definition: EventFeature.cxx:53
imax
int imax(int i, int j)
Definition: TileLaserTimingTool.cxx:33
EventFeature::insertDataBlock
bool insertDataBlock(size_t startIdx, size_t endIdx, const std::vector< double > &data)
Definition: EventFeature.cxx:182
EventFeature::m_dataWords
unsigned int m_dataWords
Internal cache data structure description (words per block)
Definition: EventFeature.h:227
EventFeature::operator=
EventFeature & operator=(const EventFeature &feature)
Assignment operator.
Definition: EventFeature.cxx:115
inRange
bool inRange(const double *boundaries, const double value, const double tolerance=0.02)
Definition: LArSCIdVsIdTest.cxx:5
EventFeature::~EventFeature
virtual ~EventFeature()
Destructor.
Definition: EventFeature.cxx:112
EventFeature::setDataBlock
bool setDataBlock(size_t blockIdx, const std::vector< double > &data, bool replace=true)
Set one data block.
Definition: EventFeature.cxx:152
EventFeature::FeatureType
FeatureType
@
Definition: EventFeature.h:24
EventFeature::tag
const std::string & tag() const
Retrieve feature tag.
Definition: EventFeature.h:280
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
EventFeature.h
EventFeature::BITSHIFT
@ BITSHIFT
Definition: EventFeature.h:49
EventFeature::m_dataList
std::vector< double > m_dataList
Internal cache for vector data.
Definition: EventFeature.h:233
EventFeature::dataBlock
bool dataBlock(size_t blockIdx, std::vector< double > &data)
Return one datablock.
Definition: EventFeature.cxx:138
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
calibdata.copy
bool copy
Definition: calibdata.py:26
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:23
EventFeature::setNumberDataBlocks
void setNumberDataBlocks(size_t nBlocks)
Set number of blocks.
Definition: EventFeature.cxx:201
EventFeature::featureTag
static const std::string & featureTag()
Default feature tag.
Definition: EventFeature.cxx:35
EventFeature::setFeatureStructure
void setFeatureStructure(bool updateCache=false)
Set/update feature structure.
Definition: EventFeature.cxx:211
EventFeature::NDATAWORDS
@ NDATAWORDS
Definition: EventFeature.h:39