ATLAS Offline Software
HitIdHelper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <cassert>
7 #include <bit>
8 #include <iostream>
9 
10 void HitIdHelper::InitializeField(const std::string& n, int vmn, int vmx)
11 {
12  int field = vmx - vmn + 1;
13  int nb = std::bit_width(static_cast<unsigned>(field - 1));
14  IdField id={n,vmn,vmx,nb,m_currentStorage+1};
15  m_IDs.push_back(std::move(id));
17  assert (m_currentStorage<33);
18 }
19 
20 void HitIdHelper::InitializeField(const std::string& n,int nb)
21 {
22  int vmn=0;
23  int vmx = (1 << nb) - 1;
24  IdField id={n,vmn,vmx,nb,m_currentStorage+1};
25  m_IDs.push_back(std::move(id));
27  assert (m_currentStorage<33);
28 }
29 
30 void HitIdHelper::SetFieldValue(const std::string& name, int n, HitID& targetID) const
31 {
32  for (unsigned int i=0;i<m_IDs.size();i++)
33  {
34  if (m_IDs[i].fieldName==name)
35  {
36  if (n<m_IDs[i].vMin || n>m_IDs[i].vMax)
37  std::cout<<"HitIdHelper: field "<<name<<": supplied value "<<n<<
38  " is not within the allowed range ["<<m_IDs[i].vMin<<","<<m_IDs[i].vMax
39  <<"] : the result of this action is unpredictable "<<std::endl;
40  n-=m_IDs[i].vMin;
41  Store(targetID,n,m_IDs[i].firstBit,m_IDs[i].nBits);
42  break;
43  }
44  }
45 }
46 
47 int HitIdHelper::GetFieldValue(const std::string& name, HitID targetID) const
48 {
49  for (unsigned int i=0;i<m_IDs.size();i++)
50  {
51  if (m_IDs[i].fieldName==name)
52  {
53  int n=Retrieve(targetID,m_IDs[i].firstBit,m_IDs[i].nBits);
54  return n+m_IDs[i].vMin;
55  }
56  }
57  std::cout<<"HitIdHelper: field "<<name<<" not found: returning 0"<<
58  std::endl;
59  return 0;
60 }
61 
63 {
64  for (unsigned int i=0;i<m_IDs.size();i++)
65  {
66  std::cout<<"-- Field "<<m_IDs[i].fieldName<<"\t["<<m_IDs[i].vMin
67  <<","<<m_IDs[i].vMax<<"]\tnBits "<<m_IDs[i].nBits
68  <<"\tfirst Bit "<<m_IDs[i].firstBit<<std::endl;
69  }
70 }
71 
72 void HitIdHelper::Print(int id)
73 {
74  for (unsigned int i=0;i<8*sizeof(int);i++)
75  {
76  if ((id & (1u<<i))) std::cout<<"1";
77  else std::cout<<"0";
78  }
79  std::cout<<std::endl;
80 }
81 
82 void HitIdHelper::SetBit(int& i, int bitpos)
83 {
84  int l=1;
85  l<<=(bitpos-1);
86  i|=l;
87 }
88 void HitIdHelper::UnsetBit(int& i, int bitpos)
89 {
90  int l=0;
91  SetBit(l,bitpos);
92  int k=~l;
93  i&=k;
94 }
95 
96 void HitIdHelper::Store(int& id, int value, int firstbit, int field)
97 {
98  int l=0;
99  for (int i=0;i<field;i++)
100  UnsetBit(id,i+firstbit);
101  l=value<<(firstbit-1);
102  id |= l;
103 }
104 
105 int HitIdHelper::Retrieve(int id, int first, int field)
106 {
107  int j=0;
108  for (int i=0;i<field;i++)
109  SetBit(j,(i+first));
110  int l=id&j;
111  return l>>(first-1);
112 }
HitIdHelper::m_IDs
IdFields m_IDs
Definition: HitIdHelper.h:34
IdField
Definition: HitIdHelper.h:13
HitIdHelper::SetFieldValue
void SetFieldValue(const std::string &name, int n, HitID &targetID) const
Definition: HitIdHelper.cxx:30
HitIdHelper::InitializeField
void InitializeField(const std::string &n, int vmn, int vmx)
Definition: HitIdHelper.cxx:10
HitIdHelper::PrintFields
void PrintFields()
Definition: HitIdHelper.cxx:62
athena.value
value
Definition: athena.py:124
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
HitIdHelper::SetBit
static void SetBit(int &i, int bitpos)
Definition: HitIdHelper.cxx:82
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
HitIdHelper::Print
static void Print(int id)
Definition: HitIdHelper.cxx:72
HitIdHelper::GetFieldValue
int GetFieldValue(const std::string &name, HitID targetID) const
Definition: HitIdHelper.cxx:47
lumiFormat.i
int i
Definition: lumiFormat.py:85
HitIdHelper::Store
static void Store(int &id, int value, int first, int field)
Definition: HitIdHelper.cxx:96
beamspotman.n
n
Definition: beamspotman.py:727
HitIdHelper::UnsetBit
static void UnsetBit(int &i, int bitpos)
Definition: HitIdHelper.cxx:88
HitIdHelper::Retrieve
static int Retrieve(int id, int first, int field)
Definition: HitIdHelper.cxx:105
taskman.fieldName
fieldName
Definition: taskman.py:489
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
HitIdHelper.h
DeMoScan.first
bool first
Definition: DeMoScan.py:534
HitIdHelper::m_currentStorage
int m_currentStorage
Definition: HitIdHelper.h:35
HitID
int HitID
Definition: GenericMuonSimHit.h:13
hotSpotInTAG.nb
nb
Definition: hotSpotInTAG.py:163
fitman.k
k
Definition: fitman.py:528