ATLAS Offline Software
TileMuonReceiverObjCnv_p1.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // TileMuonReceiverObjCnv_p1.cxx
8 // Implementation file for class TileMuonReceiverObjCnv_p1
9 // Author: Joao Gentil Saraiva <joao.gentil.saraiva@cern.ch>
10 // Date: March 2014
12 
13 // TileEvent includes
15 
16 // TileTPCnv includes
18 
19 //#define DEBUG_OUTPUT 1
20 
21 void TileMuonReceiverObjCnv_p1::transToPers(const TileMuonReceiverObj* transObj, TileMuonReceiverObj_p1* persObj, MsgStream &/*log*/) const {
22 
23  // module id
24  persObj->m_id = std::max(std::min(transObj->identify(),0xFFF),0);
25 
26  if (persObj->m_id > 0 && persObj->m_id < 0xFFF) { // standard object with decision
27 
28  size_t maxsize=8; // keep only 8 decision bits maximum
29 
30  // decision
31  if (transObj->GetDecision().size()>0) {
32  persObj->m_id |= std::min(transObj->GetDecision().size(),maxsize) << 20;
33  unsigned int bit=0x1000;
34  for (std::vector<bool>::const_iterator it = transObj->GetDecision().begin(); it != transObj->GetDecision().end(); ++it) {
35  if (*it) {
36  persObj->m_id |= bit;
37  }
38  bit <<= 1;
39  if (bit >= 0x100000) break; // keep only 8 bits maximum
40  }
41  }
42 
43  maxsize=15; // keep only 15 vords from every vector maximum
44 
45  // energy
46  if (!transObj->GetEne().empty()) {
47  persObj->m_id |= std::min(transObj->GetEne().size(),maxsize) << 24;
48  size_t cnt=0;
49  for (float f : transObj->GetEne()) {
50  persObj->m_data.push_back(f);
51  if ((++cnt)>=maxsize) break;
52  }
53  }
54 
55  // time
56  if (!transObj->GetTime().empty()) {
57  persObj->m_id |= std::min(transObj->GetTime().size(),maxsize) << 28;
58  size_t cnt=0;
59  for (float f : transObj->GetTime()) {
60  persObj->m_data.push_back(f);
61  if ((++cnt)>=maxsize) break;
62  }
63  }
64 
65  } else { // non-standard object with thresholds
66 
67  size_t maxsize=255; // upper limit for word counter (but keep all threshold words anyway)
68 
69  // thresholds
70  if ( transObj->identify()==0 && !transObj->GetThresholds().empty()) {
71  persObj->m_id |= std::min(transObj->GetThresholds().size(),maxsize) << 24;
72  persObj->m_data.insert (persObj->m_data.end(),
73  transObj->GetThresholds().begin(),
74  transObj->GetThresholds().end());
75  }
76 
77  }
78 
79 #ifdef DEBUG_OUTPUT
80  transObj->print();
81  std::cout << "Persistent_TMRO " << transObj->m_id << " id " << std::hex << persObj->m_id
82  << " size " << std::dec << ((persObj->m_id>>20)&0xF) << " " << persObj->m_data.size() << " val ";
83  for (unsigned int i=0; i<((persObj->m_id>>20)&0xF); ++i) {
84  std::cout << " " << (persObj->m_id>>(12+i) & 1);
85  }
86  std::cout << " ";
87  for (std::vector<float>::const_iterator it = persObj->m_data.begin(); it != persObj->m_data.end(); ++it) {
88  std::cout << " " << (*it);
89  }
90  std::cout << std::endl;
91 #endif
92 }
93 
94 
95 void TileMuonReceiverObjCnv_p1::persToTrans(const TileMuonReceiverObj_p1* persObj, TileMuonReceiverObj* transObj, MsgStream &/*log*/) const {
96 
97  unsigned int id=persObj->m_id;
98  int trans_id = id & 0xFFF;
99 
100  size_t n_elements = persObj->m_data.size();
101  std::vector<float>::const_iterator it = persObj->m_data.begin();
102 
103  std::vector<bool> decision;
104  std::vector<float> ene;
105  std::vector<float> time;
106  if (trans_id > 0 && trans_id < 0xFFF) { // standard object with decision
107 
108  size_t n0 = (id >> 20) & 0xF;
109  size_t n1 = (id >> 24) & 0xF;
110  size_t n2 = (id >> 28) & 0xF;
111 
112  if (n0) {
113  id >>= 12;
114  decision.reserve(n0);
115  for (size_t i=0; i<n0; ++i) {
116  decision.push_back((bool) (id & 1) );
117  id >>= 1;
118  }
119  }
120 
121  // energy
122  if (n1>n_elements) n1=n_elements;
123  ene.assign (it, it+n1);
124  it += n1;
125  n_elements -= n1;
126 
127  // time
128  if (n2>n_elements) n2=n_elements;
129  time.assign (it, it+n2);
130  it += n2;
131  n_elements -= n2;
132  }
133 
134  // remaining elements go to thresholds
135  std::vector<float> thresholds (it, persObj->m_data.end());
136 
137  *transObj = TileMuonReceiverObj (trans_id,
138  std::move(ene),
139  std::move(time),
140  std::move(decision),
141  std::move(thresholds));
142 
143 #ifdef DEBUG_OUTPUT
144  transObj->print();
145  std::cout << "Persistent_TMRO " << transObj->m_id << " id " << std::hex << persObj->m_id
146  << " size " << std::dec << ((persObj->m_id>>20)&0xF) << " " << persObj->m_data.size() << " val ";
147  for (unsigned int i=0; i<((persObj->m_id>>20)&0xF); ++i) {
148  std::cout << " " << (persObj->m_id>>(12+i) & 1);
149  }
150  std::cout << " ";
151  for (std::vector<float>::const_iterator it = persObj->m_data.begin(); it != persObj->m_data.end(); ++it) {
152  std::cout << " " << (*it);
153  }
154  std::cout << std::endl;
155 #endif
156 }
TileMuonReceiverObjCnv_p1::transToPers
virtual void transToPers(const TileMuonReceiverObj *transObj, TileMuonReceiverObj_p1 *persObj, MsgStream &log) const override
Method creating the persistent representation TileMuonReceiverObj_p1 from its transient representatio...
Definition: TileMuonReceiverObjCnv_p1.cxx:21
TileMuonReceiverObj::m_id
int m_id
Definition: TileMuonReceiverObj.h:126
TileMuonReceiverObj_p1::m_data
std::vector< float > m_data
Definition: TileMuonReceiverObj_p1.h:33
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TileMuonReceiverObj::print
void print(void) const
Definition: TileMuonReceiverObj.cxx:30
TileMuonReceiverObj::GetTime
const std::vector< float > & GetTime() const
Definition: TileMuonReceiverObj.h:112
TileMuonReceiverObj::GetDecision
const std::vector< bool > & GetDecision() const
Definition: TileMuonReceiverObj.h:109
lumiFormat.i
int i
Definition: lumiFormat.py:85
TileMuonReceiverObj::GetThresholds
const std::vector< float > & GetThresholds() const
Definition: TileMuonReceiverObj.h:110
hist_file_dump.f
f
Definition: hist_file_dump.py:135
python.TriggerConfigAccess.maxsize
maxsize
Definition: TriggerConfigAccess.py:51
TileMuonReceiverObj_p1
Definition: TileMuonReceiverObj_p1.h:20
TileMuonReceiverObjCnv_p1.h
TileMuonReceiverObj::identify
int identify(void) const
Definition: TileMuonReceiverObj.h:107
Rtt_histogram.n1
n1
Definition: Rtt_histogram.py:21
TileMuonReceiverObj
Definition: TileMuonReceiverObj.h:28
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
TileMuonReceiverObjCnv_p1::persToTrans
virtual void persToTrans(const TileMuonReceiverObj_p1 *persObj, TileMuonReceiverObj *transObj, MsgStream &log) const override
Method creating the transient representation TileMuonReceiverObj from its persistent representation T...
Definition: TileMuonReceiverObjCnv_p1.cxx:95
TileMuonReceiverObj.h
TileMuonReceiverObj::GetEne
const std::vector< float > & GetEne() const
Definition: TileMuonReceiverObj.h:111
TileMuonReceiverObj_p1::m_id
unsigned int m_id
Definition: TileMuonReceiverObj_p1.h:32