ATLAS Offline Software
EventFeature.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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  return m_featureTags.find(DEFAULT)->second;
38 }
39 
41 {
42  std::map<FeatureType,std::string>::const_iterator fMap(m_featureTags.find(type));
43  return fMap != m_featureTags.end() ? fMap->second : m_featureTags.find(UNKNOWN)->second;
44 }
45 
47  : m_type(UNKNOWN)
48  , m_tag("Default")
49  , m_dataWords(0)
50  , m_dataBlocks(0)
51  , m_featureStructure(0)
52  , m_dataList(std::vector<double>())
53  , m_structureFixed(false)
54 { }
55 
57  const std::string& tag,
58  const std::vector<double>& dataList)
59  : m_type(type)
60  , m_tag(tag)
61  , m_dataWords(dataList.size())
62  , m_dataBlocks(1)
63  , m_dataList(dataList.begin(),dataList.end())
64  , m_structureFixed(true)
65 {
66  this->setFeatureStructure();
67 }
68 
70  unsigned int nWords,
71  const std::vector<double>& dataList)
72  : m_type(type)
73  , m_tag(tag)
74  , m_dataWords(nWords)
75  , m_dataBlocks(dataList.size()/m_dataWords)
76  , m_dataList(dataList.begin(),dataList.end())
77  , m_structureFixed(true)
78 {
79  this->setFeatureStructure();
80 }
81 
83  unsigned int nWords)
84  : m_type(type)
85  , m_tag(tag)
86  , m_dataWords(nWords)
87  , m_dataBlocks(0)
88  , m_dataList(std::vector<double>())
89  , m_structureFixed(true)
90 {
91  this->setFeatureStructure();
92 }
93 
95  : m_type(feature.m_type)
96  , m_tag(feature.m_tag)
97  , m_dataWords(feature.m_dataWords)
98  , m_dataBlocks(feature.m_dataBlocks)
99  , m_dataList(feature.dataList().begin(),feature.dataList().end())
100  , m_structureFixed(feature.m_structureFixed)
101 {
102  this->setFeatureStructure();
103 }
104 
106 { }
107 
109 {
110  if (this != &feature) {
111  m_type = feature.m_type;
112  m_tag = feature.m_tag;
113  m_dataWords = feature.m_dataWords;
114  m_dataBlocks = feature.m_dataBlocks;
116  if ( feature.m_dataList.empty() )
117  {
118  m_dataList.clear();
119  }
120  else
121  {
122  m_dataList.resize(feature.m_dataList.size());
123  std::copy(feature.m_dataList.begin(),feature.m_dataList.end(),
124  m_dataList.begin());
125  }
126  this->setFeatureStructure();
127  }
128  return *this;
129 }
130 
131 bool EventFeature::dataBlock(size_t blockIdx,std::vector<double>& data)
132 {
133 
134  // get index range
135  index_t idx(0,0);
136  if ( !this->indexRange(blockIdx,idx) ) return false;
137  // copy data
138  for ( size_t i(idx.first); i<idx.second; ++i )
139  {
140  data.push_back(m_dataList.at(i));
141  }
142  return !data.empty();
143 }
144 
145 bool EventFeature::setDataBlock(size_t blockIdx,
146  const std::vector<double>& data,
147  bool replace)
148 {
149  // get index range and check if replacement
150  index_t idx(0,0);
151  bool inRange(this->indexRange(blockIdx,idx));
152  if ( inRange && !replace ) return false;
153  // replace or add
154  if ( !inRange ) return this->addDataBlock(idx.first,idx.second,data);
155  return this->insertDataBlock(idx.first,idx.second,data);
156 }
157 
158 bool EventFeature::addDataBlock(const std::vector<double>& data)
159 {
160  index_t idx(0,0);
161  this->indexRange(m_dataBlocks+1,idx);
162  return addDataBlock(idx.first,idx.second,data);
163 }
164 
165 bool EventFeature::addDataBlock(size_t startIdx,size_t endIdx,
166  const std::vector<double>& data)
167 {
169  size_t imax(std::min(endIdx-startIdx,data.size()));
170  for ( size_t i(0); i<imax; ++i ) { m_dataList[i+startIdx] = data.at(i); }
171  this->setFeatureStructure();
172  return imax>0;
173 }
174 
175 bool EventFeature::insertDataBlock(size_t startIdx,size_t endIdx,
176  const std::vector<double>& data)
177 {
178  size_t imax(std::min(endIdx-startIdx,data.size()));
179  for ( size_t i(0); i<imax; ++i ) { m_dataList[i+startIdx] = data.at(i); }
180  return imax>0;
181 }
182 
184 {
185  if ( !m_structureFixed && nWords <= (unsigned int)NDATAWORDS )
186  {
187  m_dataWords = nWords;
188  m_dataBlocks = 0;
189  this->setFeatureStructure(true);
190  m_structureFixed = true;
191  }
192 }
193 
195 {
196  if ( nBlocks <= (size_t)
197  (((unsigned int)NDATABLOCKS)>>(unsigned int)BITSHIFT) )
198  {
199  m_dataBlocks = nBlocks;
200  this->setFeatureStructure(true);
201  }
202 }
203 
204 void EventFeature::setFeatureStructure(bool updateCache)
205 {
206  if ( updateCache )
207  {
208  size_t cacheSize(m_dataWords*m_dataBlocks);
209  m_dataList.resize(cacheSize,EventShapeConstants::invalidValue());
210  }
211  // update
212  if ( m_dataWords > 0 ) m_dataBlocks = m_dataList.size()/m_dataWords;
213  // construct feature structure
214  this->buildFeatureStructure();
215 }
216 
218 {
220  (m_dataWords&(unsigned int)NDATAWORDS) |
221  ((m_dataBlocks&(unsigned int)NDATABLOCKS)<<(unsigned int)BITSHIFT);
222  return m_featureStructure;
223 }
224 
225 bool EventFeature::indexRange(size_t startIdx,index_t& idx)
226 {
227  this->setFeatureStructure(false);
228  size_t locIdx(startIdx*m_dataWords+m_dataBlocks);
229  if ( locIdx > m_dataList.size() ) return false;
230  idx.first = startIdx;
231  idx.second = locIdx;
232  return true;
233 }
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
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
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:158
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
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:217
EventFeature::NDATABLOCKS
@ NDATABLOCKS
Definition: EventFeature.h:42
EventFeature::m_tag
std::string m_tag
Internal cache for feature tag.
Definition: EventFeature.h:225
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
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:225
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:183
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:46
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:175
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:108
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:105
EventFeature::setDataBlock
bool setDataBlock(size_t blockIdx, const std::vector< double > &data, bool replace=true)
Set one data block.
Definition: EventFeature.cxx:145
EventFeature::FeatureType
FeatureType
@
Definition: EventFeature.h:24
EventFeature::tag
const std::string & tag() const
Retrieve feature tag.
Definition: EventFeature.h:280
EventFeature.h
EventFeature::BITSHIFT
@ BITSHIFT
Definition: EventFeature.h:49
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:131
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
calibdata.copy
bool copy
Definition: calibdata.py:27
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
EventFeature::setNumberDataBlocks
void setNumberDataBlocks(size_t nBlocks)
Set number of blocks.
Definition: EventFeature.cxx:194
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:204
EventFeature::NDATAWORDS
@ NDATAWORDS
Definition: EventFeature.h:39