ATLAS Offline Software
Loading...
Searching...
No Matches
TrigPassBitsCnv_p1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <cmath>
7#include <iostream>
10
11
12
13void store_bits(const std::vector<bool>& bits, std::vector<uint32_t>& store ){
14 const unsigned word_count = store.size();
15 const unsigned bits_count = bits.size();
16
17 for ( unsigned word = 0; word < word_count; ++word) {
18 uint32_t& temp(store[word]);
19
20 for ( unsigned bit = 0; bit < 32; ++bit) {
21 const unsigned position = word*32+bit;
22 if (position >= bits_count )
23 return;
24 if (bits[position])
25 temp |= (1 << bit);
26 }
27 }
28}
29
30void restore_bits(std::vector<bool>& bits, const std::vector<uint32_t>& store) {
31 const unsigned word_count = store.size();
32 const unsigned bits_count = bits.size();
33
34
35 for ( unsigned word = 0; word < word_count; ++word) {
36 const uint32_t& temp(store[word]);
37
38 for ( unsigned bit = 0; bit < 32; ++bit) {
39 const unsigned position = word*32+bit;
40 if (position >= bits_count )
41 return;
42
43 if (temp & (1 << bit))
44 bits[position] = true;
45 else
46 bits[position] = false;
47 }
48 }
49}
50
51
52unsigned necessary_words(unsigned size) {
53 return (size ? 1 : 0) + size/32;
54}
55
56
57
59 TrigPassBits* transObj,
60 MsgStream &log)
61{
62 log << MSG::DEBUG << "TrigPassBitsCnv_p1::persToTrans called " << endmsg;
63
64 transObj->m_decisions.resize(persObj->m_size, false); // reserve space and set defaults to 0
65
66 restore_bits(transObj->m_decisions, persObj->m_serialized); // get back the bits
67
68}
69
70
72 TrigPassBits_p1* persObj,
73 MsgStream &log)
74{
75 log << MSG::DEBUG << "TrigPassBitsCnv_p1::transToPers called " << endmsg;
76 persObj->m_size = transObj->m_decisions.size();
77
78 persObj->m_serialized.resize(necessary_words(persObj->m_size), 0); // reserve the space and set the content to 0
79
80 store_bits(transObj->m_decisions, persObj->m_serialized); // pack the bits
81}
#define endmsg
void store_bits(const std::vector< bool > &bits, std::vector< uint32_t > &store)
unsigned necessary_words(unsigned size)
void restore_bits(std::vector< bool > &bits, const std::vector< uint32_t > &store)
virtual void transToPers(const TrigPassBits *transObj, TrigPassBits_p1 *persObj, MsgStream &log)
virtual void persToTrans(const TrigPassBits_p1 *persObj, TrigPassBits *transObj, MsgStream &log)
unsigned int m_size
std::vector< uint32_t > m_serialized
std::vector< bool > m_decisions
trainsient bits storage (STL docu assures that this is efficient)