ATLAS Offline Software
Loading...
Searching...
No Matches
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}
#define endmsg
virtual void persToTrans(const TrigPassFlags_p1 *persObj, TrigPassFlags *transObj, MsgStream &log)
virtual void transToPers(const TrigPassFlags *transObj, TrigPassFlags_p1 *persObj, MsgStream &log)
unsigned int m_nObjects
unsigned short int m_nFlags
std::vector< uint32_t > m_serialized
A Flag is an ordered collection of bits (vector<bool>) that can hold additional (boolean) information...
const std::vector< bool > & getFlag(const unsigned int position) const
Returns the flag (vector<bool>) at index position.
std::vector< std::vector< bool > > m_flagsPerObject
list of trainsient n-bit value (STL docu assures that a vector of booleans is efficient)
unsigned int size() const
gets size of the container object vector
T FlagAs(const std::vector< bool > &flag)