ATLAS Offline Software
Loading...
Searching...
No Matches
LArABBADecoder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8static const InterfaceID IID_ILArABBADecoder("LArABBADecoder", 1, 0);
9
10
11using namespace OFFLINE_FRAGMENTS_NAMESPACE;
12
13LArABBADecoder::LArABBADecoder(const std::string& type, const std::string& name,
14 const IInterface* parent )
15 : AthAlgTool(type,name,parent)
16{
17 declareInterface< LArABBADecoder >( this );
18
19}
20
21const InterfaceID& LArABBADecoder::interfaceID( )
22{ return IID_ILArABBADecoder; }
23
24
25
27
28
30 return StatusCode::SUCCESS;
31}
32
34 return StatusCode::SUCCESS;
35}
36
38{
39
40 bool ret=false;
41 // Check fragment validity:
42 try {
43 ret=re->check();
44 }
45 catch (eformat::Issue& ex) {
46 ATH_MSG_WARNING( "Exception while checking eformat fragment validity: " << ex.what() );
47 ret=false;
48 }
49 if (!ret) {
50 ATH_MSG_ERROR( "Got invalid RawEvent fragment" );
51 return StatusCode::FAILURE;
52 }
53
54 //Build TOC
55 std::map<eformat::SubDetectorGroup, std::vector<const uint32_t*> > robIndex;
56 eformat::helper::build_toc(*re, robIndex );
57 std::map<eformat::SubDetectorGroup, std::vector<const uint32_t*> >::const_iterator robIt = robIndex.find(eformat::LAR);
58 if (robIt!=robIndex.end()) {
59 const std::vector<const uint32_t*>& robs = robIt->second;
60 for (const uint32_t* pRob :robs) {
61 try {
62 ROBFragment robFrag(pRob);
63 fillCollection(&robFrag,coll);
64 }
65 catch (eformat::Issue& ex) {
66 ATH_MSG_WARNING ( " exception thrown by ROBFragment, badly corrupted event. Abort decoding " );
67 coll->clear();
68 break;
69 }
70 }//end loop over robs
71 }//end if got LAr-RODs
72 return StatusCode::SUCCESS;
73}
74
75
77{
79 LArDigit * scDigit=0 ;
80
81 //FIXME: Check validity
82 uint32_t nData = robFrag->rod_ndata();
83 const uint32_t* p=robFrag->rod_data();
84 if (nData < 3) {
85 ATH_MSG_WARNING ( "Error reading bytestream event: "
86 << "Empty ROD block (less than 3 words) for source ID " << robFrag->rod_source_id() );
87 return;
88 }
89 else
90 robFrag->rod_source_id();
91 unsigned int n = robFrag->payload_size_word();
92
93 std::vector<std::string> string;
94 int x=0x0;
95 int nsamples = p[0];
96 for(unsigned int s=1;s<n-13;s+=6) {
97 std::string ss;
98 for (unsigned int k=0;k<6;++k){
99 x = p[s+k];
100 std::ostringstream oss;
101 oss << std::hex << x;
102 if (oss.str().size() == 7){
103 ss.append("0");
104 }
105 ss += oss.str();
106 }
107 string.push_back(std::move(ss));
108 }
109
110
111
112constexpr int nFibers = 20;
113constexpr int nchannels = 8;
114constexpr int Nabbachannels = nFibers * nchannels;
115
116constexpr int fiberSeq[16] = {0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1};
117constexpr int adcSeq[16] = {1,0,1,0,3,2,3,2,5,4,5,4,7,6,7,6};
118
119std::vector< std::vector< std::vector<int> > > abbasamples;
120abbasamples.resize(nFibers);
121
122std::vector<std::vector<short>> abba_channel_samples;
123abba_channel_samples.resize(Nabbachannels);
124
125for (int fib=0;fib < nFibers; ++fib){
126 abbasamples[fib].resize(nchannels);
127 for (int ch = 0; ch < nchannels; ++ch){
128 abbasamples[fib][ch].resize(nsamples);
129 int Nchannel = fib*8 + ch;
130 abba_channel_samples[Nchannel].resize(nsamples);
131 }
132 }
133
134 for (int fib=0;fib < nFibers; fib+=2){
135 for (int sam=0; sam < nsamples; sam++){
136 int zx = sam + (fib/2)*nsamples;
137 const std::string &wx = string[zx];
138 int k = 0;
139 for (int m = 0; m < 16; ++m){ //16 size of fiberSeq array
140 int fiber_number = fiberSeq[m];
141 int adc_number = adcSeq[m];
142 int idx = k*3;
143 std::stringstream ss;
144 char mysample[3];
145 for (int j = idx; j < idx+3; ++j){
146 int i = j%3;
147 mysample[i] = wx[j];
148 }
149 ss << mysample;
150 short mysample_int;
151 ss >> std::hex >> mysample_int;
152 int fb = fiber_number+fib;
153 int ch = adc_number;
154 int abbachannel = fb*8+ch;
155 k++;
156 abbasamples[fb][ch][sam] = mysample_int;
157 abba_channel_samples[abbachannel][sam] = mysample_int;
158 }
159 }
160 }
161
162std::map<int, HWIdentifier> abba_mapping;
163
164
165int iphi = 0;
166switch (robFrag->rod_source_id())
167{
168case 0x410511:
169 iphi=19;
170 break;
172case 0x410512:
173 iphi=18;
174 break;
175case 0x410521:
176 iphi=20;
177 break;
178case 0x410522:
179 iphi=21;
180 break;
181
182default:
183msg(MSG::ERROR) << "ROD_source_id not found" << endmsg;
184}
185
186
187ABBAMapping::fill(&abba_mapping, iphi);
188
189
190for (std::size_t index_abba_channel_samples = 0; index_abba_channel_samples < abba_channel_samples.size(); ++index_abba_channel_samples) {
191 auto abba_mapping_search = abba_mapping.find(index_abba_channel_samples);
192 if (abba_mapping_search == abba_mapping.end()) {
193 msg(MSG::WARNING) << "No mapping for index_abba_channel_samples: "<<std::dec<<index_abba_channel_samples << endmsg;
194 continue;
195 }
196
197 HWIdentifier channelID = (*abba_mapping_search).second;
198 std::vector<short> adcValues = abba_channel_samples[index_abba_channel_samples];
199 scDigit=new LArDigit(channelID,dummyGain,std::move(adcValues));
200
201 coll->push_back(scDigit);
202 }
203
204abbasamples.clear();
205
206 return;
207
208
209}
const boost::regex re(r_e)
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
static const InterfaceID IID_ILArABBADecoder("LArABBADecoder", 1, 0)
static Double_t ss
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition RawEvent.h:37
#define x
static void fill(std::map< int, HWIdentifier > *toFill, int iphi)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
MsgStream & msg() const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
void clear()
Erase all the elements in the collection.
static const InterfaceID & interfaceID()
virtual StatusCode initialize() override
LArABBADecoder(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode finalize() override
virtual ~LArABBADecoder()
Destructor.
StatusCode convert(const RawEvent *re, LArDigitContainer *coll) const
void fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment *pROB, LArDigitContainer *coll) const
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
STL class.
@ LARHIGHGAIN
Definition CaloGain.h:18
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27