ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArCnv
LArTPCnv
src
LArDigitContainerCnv_p2.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
LArTPCnv/LArDigitContainerCnv_p2.h
"
6
#include "
LArRawEvent/LArDigitContainer.h
"
7
#include "Identifier/Identifier.h"
8
#include "
LArIdentifier/LArOnlineID_Base.h
"
9
#include "GaudiKernel/GaudiException.h"
10
#include "
CxxUtils/AthUnlikelyMacros.h
"
11
12
#include "
AthAllocators/DataPool.h
"
13
14
#include <algorithm>
15
#include <cstdlib>
16
17
namespace
{
18
19
void
writeTwoBits(std::vector<unsigned char>&
vec
,
const
unsigned
idx,
const
unsigned
char
val) {
20
const
auto
qr=std::div(idx,4);
21
const
unsigned
char
maskval=(
val
&0x3) << 2*qr.rem;
22
vec
[qr.quot]|=maskval;
23
return
;
24
}
25
26
unsigned
char
readTwoBits(
const
std::vector<unsigned char>&
vec
,
const
unsigned
idx) {
27
const
auto
qr=std::div(idx,4);
28
const
unsigned
char
&
v
=
vec
[qr.quot];
29
return
(v>>2*qr.rem) & 0x3;
30
}
31
}
32
33
LArDigitContainerCnv_p2::LArDigitContainerCnv_p2
(
const
LArOnlineID_Base
* idHelper) :
34
m_idHelper
(idHelper) {}
35
36
void
37
LArDigitContainerCnv_p2::persToTrans
(
const
LArDigitContainer_p2
* pers,
38
LArDigitContainer
* trans, MsgStream &
/*log*/
)
const
39
{
40
41
DataPool<LArDigit>
dataItems;
42
if
(pers->
m_nSamples
==0 || pers->
m_samples
.size()==0) {
43
//No data
44
return
;
45
}
46
47
const
unsigned
nMaxChannels=4*(pers->
m_gain
.size());
48
trans->
clear
(
SG::VIEW_ELEMENTS
);
49
size_t
numElements = pers->
m_samples
.size()/pers->
m_nSamples
;
50
//
51
dataItems.
reserve
(numElements);
52
trans->
reserve
(numElements);
53
54
std::vector<short>::const_iterator samplesIt=pers->
m_samples
.begin();
55
for
(
unsigned
idx=0;idx<nMaxChannels;idx++) {
56
const
unsigned
char
gain=readTwoBits(pers->
m_gain
,idx);
57
if
(gain!=0) {
58
const
HWIdentifier
hwid=
m_idHelper
->channel_Id(
IdentifierHash
(idx));
59
std::vector<short>::const_iterator samplesIt_e=samplesIt+pers->
m_nSamples
;
60
std::vector<short> samples(samplesIt,samplesIt_e);
61
LArDigit
* lardigi = dataItems.
nextElementPtr
();
62
(*lardigi) =
63
LArDigit
(hwid, (
CaloGain::CaloGain
)(gain - 1), std::move(samples));
64
trans->
push_back
(lardigi);
65
samplesIt=samplesIt_e;
66
}
//end if gain!=0, eg channel present
67
}
//end loop over all hashes
68
}
69
70
71
void
72
LArDigitContainerCnv_p2::transToPers
(
const
LArDigitContainer
* trans,
73
LArDigitContainer_p2
* pers, MsgStream &log)
const
{
74
75
const
unsigned
int
nChannels=trans->
size
();
76
if
(nChannels==0) {
77
pers->
m_nSamples
=0;
//Avoid undefined value in output file
78
return
;
79
}
80
81
//Store the number of ADC samples from first digit
82
pers->
m_nSamples
=(*(trans->
begin
()))->samples().size();
83
const
unsigned
hashMax=
m_idHelper
->channelHashMax();
84
85
//Resize persistant storage
86
pers->
m_gain
.assign(hashMax/4,0);
87
pers->
m_samples
.assign(pers->
m_nSamples
*nChannels,0);
88
89
//Copy pointer to digits into a hash-indexed vector, nullptr for non-existing digits
90
std::vector<const LArDigit*> digitsvsHash(hashMax,
nullptr
);
91
for
(
const
LArDigit
* transDigit : *trans) {
92
const
IdentifierHash
h
=
m_idHelper
->channel_Hash(transDigit->hardwareID());
93
if
(
ATH_UNLIKELY
(transDigit->samples().size()!=pers->
m_nSamples
)) {
94
log << MSG::ERROR <<
"Encountered LArDigit Container with varying numbers of ADC samples"
<<
endmsg
;
95
throw
GaudiException(
"Encountered LArDigit Container with varying numbers of ADC samples"
,
96
"LArDigitContainerCnv_p2"
,StatusCode::FAILURE);
97
}
98
digitsvsHash[
h
]=transDigit;
99
}
100
101
unsigned
idx=0;
102
std::vector<short>::iterator writeIt=pers->
m_samples
.begin();
103
std::vector<const LArDigit*>::const_iterator it=digitsvsHash.begin();
104
std::vector<const LArDigit*>::const_iterator it_e=digitsvsHash.end();
105
for
(;it!=it_e;++it,++idx) {
106
const
LArDigit
* dig=*it;
107
if
(dig!=
nullptr
) {
108
//A gain value of 0 means no data for this hash-value
109
//Store gain+1
110
writeTwoBits(pers->
m_gain
,idx,1+dig->
gain
());
111
//Copy ADC samples
112
writeIt=std::copy(dig->
samples
().begin(),dig->
samples
().end(),writeIt);
113
}
114
}
115
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:61
AthUnlikelyMacros.h
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition
AthUnlikelyMacros.h:17
vec
std::vector< size_t > vec
Definition
CombinationsGeneratorTest.cxx:9
DataPool.h
LArDigitContainerCnv_p2.h
LArDigitContainer.h
LArOnlineID_Base.h
h
Header file for AthHistogramAlgorithm.
DataPool
a typed memory pool that saves time spent allocation small object.
Definition
DataPool.h:63
DataPool::reserve
void reserve(unsigned int size)
Set the desired capacity.
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::clear
void clear()
Erase all the elements in the collection.
HWIdentifier
Definition
HWIdentifier.h:13
IdentifierHash
This is a "hash" representation of an Identifier.
Definition
IdentifierHash.h:25
LArDigitContainerCnv_p2::persToTrans
virtual void persToTrans(const LArDigitContainer_p2 *pers, LArDigitContainer *trans, MsgStream &log) const override
Definition
LArDigitContainerCnv_p2.cxx:37
LArDigitContainerCnv_p2::LArDigitContainerCnv_p2
LArDigitContainerCnv_p2(const LArOnlineID_Base *idHelper)
Definition
LArDigitContainerCnv_p2.cxx:33
LArDigitContainerCnv_p2::transToPers
virtual void transToPers(const LArDigitContainer *trans, LArDigitContainer_p2 *pers, MsgStream &log) const override
Definition
LArDigitContainerCnv_p2.cxx:72
LArDigitContainerCnv_p2::m_idHelper
const LArOnlineID_Base * m_idHelper
Definition
LArDigitContainerCnv_p2.h:29
LArDigitContainer_p2
Definition
LArDigitContainer_p2.h:10
LArDigitContainer_p2::m_gain
std::vector< unsigned char > m_gain
Definition
LArDigitContainer_p2.h:13
LArDigitContainer_p2::m_samples
std::vector< short > m_samples
Definition
LArDigitContainer_p2.h:14
LArDigitContainer_p2::m_nSamples
unsigned char m_nSamples
Definition
LArDigitContainer_p2.h:12
LArDigitContainer
Container class for LArDigit.
Definition
LArDigitContainer.h:24
LArDigit
Liquid Argon digit base class.
Definition
LArDigit.h:25
LArDigit::gain
CaloGain::CaloGain gain() const
Definition
LArDigit.h:72
LArDigit::samples
const std::vector< short > & samples() const
Definition
LArDigit.h:78
LArOnlineID_Base
Helper for the Liquid Argon Calorimeter cell identifiers.
Definition
LArOnlineID_Base.h:97
CaloGain::CaloGain
CaloGain
Definition
CaloGain.h:11
Pythia8_RapidityOrderMPI.val
val
Definition
Pythia8_RapidityOrderMPI.py:14
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition
OwnershipPolicy.h:18
python.PyAthena.v
v
Definition
PyAthena.py:153
Generated on
for ATLAS Offline Software by
1.17.0