ATLAS Offline Software
TrigPassFlagsCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <cmath>
7 #include <iostream>
10 #include <stdint.h>
11 
13  TrigPassFlags* transObj,
14  MsgStream &log)
15 {
16 
17  if(log.level()<=MSG::DEBUG)
18  log << MSG::DEBUG << "TrigPassFlagsCnv_p1::persToTrans called " << endmsg;
19 
20  // reserve space in vector<vector<bool> > and set defaults to false
21  transObj->m_flagsPerObject.clear();
22  transObj->m_flagsPerObject.resize(persObj->m_nObjects,
23  std::vector<bool>(persObj->m_nFlags,false));
24 
25  const unsigned int bitsPerWord = sizeof(uint32_t)*8;
26  const unsigned int flagsPerObject = persObj->m_nFlags;
27 
28  // loop over words and fill object/flags of transient
29  unsigned int object = 0;
30  unsigned int flag = 0;
31  for(unsigned int word = 0; word < persObj->m_serialized.size();++word){
32 
33  // loop over bits in the word
34  for(unsigned int bit = 0;bit < bitsPerWord;++bit){
35 
36  if(persObj->m_serialized[word] & (1u << bit) )
37  transObj->m_flagsPerObject[object][flag] = true;
38 
39  flag++;
40 
41  // reset flag index and increment object index if max flags reached
42  if(flag >= flagsPerObject){
43  flag = 0;
44  object++;
45  }
46 
47 
48  }// end for(bit)
49 
50 
51  }// end for(word)
52 
53  if(log.level()<=MSG::DEBUG) {
54  for(unsigned int i=0; i<transObj->size(); i++) {
55  int flag = HLT::FlagAs<int>(transObj->getFlag(i));
56  std::cout << " " << flag << " [0x" << std::hex << flag << "]" << std::dec << std::endl;
57  }
58  }
59 }
60 
61 
63  TrigPassFlags_p1* persObj,
64  MsgStream &log)
65 {
66  if(log.level()<=MSG::DEBUG) {
67  log << MSG::DEBUG << "TrigPassFlagsCnv_p1::transToPers called " << endmsg;
68  for(unsigned int i=0; i<transObj->size(); i++) {
69  int flag = HLT::FlagAs<int>(transObj->getFlag(i));
70  log << " " << flag << " [0x" << std::hex << flag << "]" << std::dec << std::endl;
71  }
72  }
73 
74  // record the number of container objects
75  persObj->m_nObjects = transObj->m_flagsPerObject.size();
76  // record the number of flags per object (should be the same for all so get it from first entry)
77  persObj->m_nFlags = 0;
78  if(persObj->m_nObjects > 0){
79  persObj->m_nFlags = transObj->m_flagsPerObject[0].size();
80  if(persObj->m_nFlags == 0){
81  log << MSG::WARNING << "TrigPassFlagsCnv_p1::transToPers zero flags to save, this is an empty TrigPassFlags" << endmsg;
82  persObj->m_serialized.clear();
83  return;
84  }
85  }
86  else{
87  log << MSG::WARNING << "TrigPassFlagsCnv_p1::transToPers zero objects to save, this is an empty TrigPassFlags" << endmsg;
88  persObj->m_serialized.clear();
89  return;
90  }
91 
92 
93 
94 
95  const unsigned int bitsPerWord = sizeof(uint32_t)*8;
96  const unsigned int word_count = (persObj->m_nFlags * persObj->m_nObjects) / bitsPerWord + 1;
97 
98  // reserve space in vector<uint32_t> to 0
99  persObj->m_serialized.clear();
100  persObj->m_serialized.resize(word_count, 0); // reserve the space and initialize to zero
101 
102  // loop over objects in transient object
103  unsigned int word = 0;
104  unsigned int bit = 0;
105  for(unsigned int object = 0;object < transObj->m_flagsPerObject.size();++object){
106 
107  // loop over the object's flags
108  for(unsigned int flag = 0;flag < transObj->m_flagsPerObject[object].size();++flag){
109 
110  // if the flag is true, set the bit in the vector of words
111  if(transObj->m_flagsPerObject[object][flag])
112  persObj->m_serialized[word] |= (1 << bit);
113 
114  bit++;
115 
116  // reset bit index and increment word index if we reach end of word
117  if(bit >= bitsPerWord){
118  bit = 0;
119  word++;
120  }
121 
122  }// end for(flag)
123 
124 
125  }// end for(object)
126 }
TrigPassFlagsCnv_p1::persToTrans
virtual void persToTrans(const TrigPassFlags_p1 *persObj, TrigPassFlags *transObj, MsgStream &log)
Definition: TrigPassFlagsCnv_p1.cxx:12
TrigPassFlags_p1::m_serialized
std::vector< uint32_t > m_serialized
Definition: TrigPassFlags_p1.h:39
TrigPassFlags_p1
Definition: TrigPassFlags_p1.h:21
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TrigPassFlags::size
unsigned int size() const
gets size of the container object vector
Definition: TrigPassFlags.h:73
TrigPassFlagsCnv_p1.h
TrigPassFlags_p1::m_nObjects
unsigned int m_nObjects
Definition: TrigPassFlags_p1.h:37
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
master.flag
bool flag
Definition: master.py:29
TrigPassFlagsCnv_p1::transToPers
virtual void transToPers(const TrigPassFlags *transObj, TrigPassFlags_p1 *persObj, MsgStream &log)
Definition: TrigPassFlagsCnv_p1.cxx:62
TrigPassFlags_p1.h
TrigPassFlags_p1::m_nFlags
unsigned short int m_nFlags
Definition: TrigPassFlags_p1.h:38
DEBUG
#define DEBUG
Definition: page_access.h:11
TrigPassFlags
A Flag is an ordered collection of bits (vector<bool>) that can hold additional (boolean) information...
Definition: TrigPassFlags.h:29
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TrigPassFlags::getFlag
const std::vector< bool > & getFlag(const unsigned int position) const
Returns the flag (vector<bool>) at index position.
Definition: TrigPassFlags.cxx:54
pickleTool.object
object
Definition: pickleTool.py:30
TrigPassFlags.h
TrigPassFlags::m_flagsPerObject
std::vector< std::vector< bool > > m_flagsPerObject
list of trainsient n-bit value (STL docu assures that a vector of booleans is efficient)
Definition: TrigPassFlags.h:84