ATLAS Offline Software
Loading...
Searching...
No Matches
LArRawDataContByteStreamTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
8
10
16
24#include "GaudiKernel/MsgStream.h"
25#include "GaudiKernel/ThreadLocalContext.h"
26
28
29// STL stuff
30#include <map>
31
32
33static const InterfaceID IID_ILArRawDataContByteStreamTool
34 ("LArRawDataContByteStreamTool", 1, 0);
35
36
39
40// default contructor
41
43( const std::string& type, const std::string& name,const IInterface* parent )
44 : AthAlgTool(type,name,parent)
45{ declareInterface< LArRawDataContByteStreamTool >( this );
46 declareProperty("DSPRunMode",m_DSPRunMode=4);
47 declareProperty("RodBlockVersion",m_RodBlockVersion=0);
48 declareProperty("FebNoiseCut",m_nfebsigma=2);
49 declareProperty("InitializeForWriting",m_initializeForWriting=false);
50 declareProperty("SubDetectorId",m_subDetId=0);
51 declareProperty("IncludeDigits",m_includeDigits=false);
52 declareProperty("DigitsContainer",m_DigitContName="LArDigitContainer_MC_Thinned");
53}
54
57
58
59StatusCode
61{
62 ATH_CHECK( AthAlgTool::initialize() );
63 ATH_MSG_DEBUG ( "Initializing LArRawDataContByteStream" );
64
65 ATH_CHECK( m_decoder.retrieve() );
66
68 if (m_DSPRunMode == 0) {
69 // Obsolete mode
70 ATH_MSG_ERROR ( "LArRodBlockStructure type 0 is obsolete and can't be used any more." );
71 return StatusCode::FAILURE;
72 }
73
74 ATH_CHECK( detStore()->retrieve (m_onlineHelper, "LArOnlineID") );
75
76 ATH_MSG_INFO ( "Initialization done for reading and writing" );
77 }
78 else {
79 ATH_MSG_INFO ( "Initialization done for reading only" );
80 }
81
86
87 return StatusCode::SUCCESS;
88}
89
90
91StatusCode
93{
94 ATH_CHECK( AthAlgTool::finalize() );
95 return StatusCode::SUCCESS;
96}
97
98
99StatusCode
101 FEA_t& fea) const
102{
104 ATH_MSG_ERROR ( "Tool not setup for writing! Use property "
105 << name()<<".InitializeForWriting" );
106 return StatusCode::FAILURE;
107 }
108 ATH_MSG_DEBUG ( "Writing LArDigitContainer to ByteStream" );
109 if (!digitCont) {
110 ATH_MSG_ERROR ( "Null pointer passed to WriteLArDigit routine!" );
111 return StatusCode::FAILURE;
112 }
113
114 std::unique_ptr<LArRodBlockStructure> blstruct = makeRodBlockStructure();
115
116 if (!blstruct->canSetRawData() && !blstruct->canSetRawDataFixed()) {
117 ATH_MSG_DEBUG ( "This instance of LArRodBlockStructure can't hold LArDigits!" );
118 return StatusCode::FAILURE;
119 }
122 ATH_MSG_DEBUG ( "Setting Detector Event Type to " << m_DSPRunMode
123 << " and Minor Version Number to " << m_RodBlockVersion );
124 FEA_t::RODDATA* theROD;
126 LArDigitContainer::const_iterator it_e=digitCont->end();
127 if (it_b==it_e) {
128 ATH_MSG_WARNING ( "Attempt to persistify an empty LArDigitContainer to ByteStream" );
129 return StatusCode::SUCCESS;
130 }
131
132 const EventContext& ctx = Gaudi::Hive::currentContext();
136 const Hid2RESrcID& hid2re = getHid2RESrcID (**febRodMapping);
137
138 std::map<uint32_t, LArRodEncoder> mapEncoder;
139
140 auto getEncoder = [&] (uint32_t reid) -> LArRodEncoder&
141 { return mapEncoder.try_emplace (reid,
143 **caloMgr,
144 **onOffMapping,
145 blstruct.get()).first->second; };
146
147 unsigned n=0;
148 if (blstruct->canSetRawDataFixed() && checkGainConsistency(digitCont))
149 {//Set fixed gain raw data
150 int fixgain=(*it_b)->gain();
151 ATH_MSG_DEBUG(" number of Digits in LArDigitContainer for gain " << fixgain << ": "
152 << digitCont->size() );
153 // Sorting Channels by ROD
154 for(; it_b!=it_e; ++it_b){
155 const LArDigit* digit = *it_b;
156 HWIdentifier chid = digit->hardwareID() ;
157 uint32_t reid = hid2re.getRodID( **febRodMapping, chid );
158 getEncoder(reid).add (digit, fixgain);
159 n++;
160 }
161 ATH_MSG_VERBOSE(" number of channels in the LArDigitContainer for gain "
162 << fixgain << ": "<<n );
163 } // end if
164 else
165 if (blstruct->canSetRawData()) { //Set free gain raw data
166 ATH_MSG_DEBUG(" number of channels in LArDigit container: "<< digitCont->size() );
167
168 // Sorting Channels by ROD
169 for(; it_b!=it_e; ++it_b){
170 const LArDigit* digit = *it_b;
171 HWIdentifier chid = digit->hardwareID() ;
172 uint32_t reid = hid2re.getRodID( **febRodMapping, chid );
173 getEncoder(reid).add (digit);
174 n++;
175 }
176 ATH_MSG_VERBOSE(" number of channels added to framgent: "<<n );
177 }// end else-if(can set Raw data)
178
180
181 // Now loop over map and fill all ROD Data Blocks
182 std::map<uint32_t,LArRodEncoder>::iterator it =mapEncoder.begin();
183 std::map<uint32_t,LArRodEncoder>::iterator it_end=mapEncoder.end();
184 // LArRodEncoder has collected all the channels, now can fill the
185 // ROD block data.
186 for(; it!=it_end;++it) {
187 theROD = fea.getRodData( (*it).first );
188 ((*it).second).fillROD(*theROD,msg(), **noise, m_nfebsigma ) ;
189 }
190 ATH_MSG_DEBUG ( "Filled " << mapEncoder.size() << " Rod Blocks" );
191 return StatusCode::SUCCESS;
192}
193
194
195
196StatusCode
198 FEA_t& fea) const
199{
201 ATH_MSG_ERROR ( "Tool not setup for writing! Use property "
202 << name()<<".InitializeForWriting" );
203 return StatusCode::FAILURE;
204 }
205 ATH_MSG_DEBUG ( "Writing LArCalibDigitContainer to ByteStream" );
206 if (!digitCont) {
207 ATH_MSG_DEBUG ( "Null pointer passed to WriteLArCalibDigit routine!" );
208 return StatusCode::FAILURE;
209 }
210
211 std::unique_ptr<LArRodBlockStructure> blstruct = makeRodBlockStructure();
212
213 if (!blstruct->canSetCalibration()|| !blstruct->canSetRawDataFixed()) {
214 ATH_MSG_DEBUG ( "This instance of LArRodBlockStructure can't hold LArCalibDigits!" );
215 return StatusCode::FAILURE;
216 }
219 ATH_MSG_DEBUG ( "Setting Detector Event Type to " << m_DSPRunMode
220 << "and Minor Version Number to " << m_RodBlockVersion );
221 FEA_t::RODDATA* theROD;
224 if (it_b==it_e) {
225 ATH_MSG_WARNING ( "Attempt to persistify a empty LArDigitContainer to ByteStream" );
226 return StatusCode::SUCCESS;
227 }
228 if (!checkGainConsistency(digitCont)) {
229 ATH_MSG_ERROR ( "Inconsistent gain in LArCalibDigitContainer" );
230 return StatusCode::FAILURE;
231 }
232
233 const EventContext& ctx = Gaudi::Hive::currentContext();
237 const Hid2RESrcID& hid2re = getHid2RESrcID (**febRodMapping);
238
239 std::map<uint32_t, LArRodEncoder> mapEncoder;
240
241 auto getEncoder = [&] (uint32_t reid) -> LArRodEncoder&
242 { return mapEncoder.try_emplace (reid,
244 **caloMgr,
245 **onOffMapping,
246 blstruct.get()).first->second; };
247
248 unsigned n=0;
249 int fixgain=(*it_b)->gain();
250
251 // Sorting Channels by ROD
252 for(; it_b!=it_e; ++it_b){
253 const LArCalibDigit* digit = *it_b;
254 HWIdentifier chid = digit->hardwareID() ;
255 uint32_t reid = hid2re.getRodID( **febRodMapping, chid );
256 getEncoder(reid).add (digit, fixgain);
257 n++;
258 }
259
260 ATH_MSG_VERBOSE(" number of channels in the LArCalibDigitContainer for gain "
261 << fixgain << ": "<<n );
262
264
265 // Now loop over map and fill all ROD Data Blocks
266 std::map<uint32_t,LArRodEncoder>::iterator it =mapEncoder.begin();
267 std::map<uint32_t,LArRodEncoder>::iterator it_end=mapEncoder.end();
268 // LArRodEncoder has collected all the channels, now can fill the
269 // ROD block data.
270 for(; it!=it_end;++it) {
271 theROD = fea.getRodData( (*it).first );
272 ((*it).second).fillROD( *theROD,msg(), **noise, m_nfebsigma ) ;
273 }
274 ATH_MSG_DEBUG ( "Filled " << mapEncoder.size() << " Rod Blocks" );
275 return StatusCode::SUCCESS;
276}
277
278
279StatusCode
281 FEA_t& fea) const
282{
284 ATH_MSG_ERROR ( "Tool not setup for writing! Use property "
285 << name()<<".InitializeForWriting" );
286 return StatusCode::FAILURE;
287 }
288 if (!channelCont) {
289 ATH_MSG_DEBUG ( "Null pointer passed to WriteLArCalibDigit routine!" );
290 return StatusCode::FAILURE;
291 }
292
293 std::unique_ptr<LArRodBlockStructure> blstruct = makeRodBlockStructure();
294
295 if (!blstruct->canSetEnergy()) {
296 ATH_MSG_DEBUG ( "This instance of LArRodBlockStructure can't hold LArRawChannels!" );
297 return StatusCode::FAILURE;
298 }
299 FEA_t::RODDATA* theROD;
302 ATH_MSG_DEBUG ( "Setting Detector Event Type to " << m_DSPRunMode
303 << "and Minor Version Number to " << m_RodBlockVersion );
304 LArRawChannelContainer::const_iterator it = channelCont->begin();
305 LArRawChannelContainer::const_iterator it_e= channelCont->end();
306 if ( it==it_e) {
307 ATH_MSG_WARNING ( "Attempt to persistify a empty LArDigitContainer to ByteStream" );
308 return StatusCode::SUCCESS;
309 }
310
311 const EventContext& ctx = Gaudi::Hive::currentContext();
315 const Hid2RESrcID& hid2re = getHid2RESrcID (**febRodMapping);
316
317 std::map<uint32_t, LArRodEncoder> mapEncoder;
318
319 auto getEncoder = [&] (uint32_t reid) -> LArRodEncoder&
320 { return mapEncoder.try_emplace (reid,
322 **caloMgr,
323 **onOffMapping,
324 blstruct.get()).first->second; };
325
326 ATH_MSG_DEBUG(" number of LArRawChannel container "<< channelCont->size() );
327 for(; it!=it_e; ++it){
328 const LArRawChannel& rawChan = *it;
329 HWIdentifier chid = rawChan.channelID() ;
330 uint32_t reid = hid2re.getRodID( **febRodMapping, chid );
331
332 getEncoder(reid).add (&rawChan);
333 }
334 // I may want to also include the digits
335 if ( m_includeDigits ) {
336 const LArDigitContainer* digitCont = nullptr;
337 if ( evtStore()->retrieve(digitCont,m_DigitContName).isFailure() ){
338 ATH_MSG_ERROR ( "Digits required but not really found" );
339 } else {
340 if ( blstruct->canIncludeRawData() ){
342 LArDigitContainer::const_iterator it_e=digitCont->end();
343 if (it_b==it_e) {
344 ATH_MSG_WARNING ( "Attempt to persistify a empty LArDigitContainer to ByteStream" );
345 }
346 for(; it_b!=it_e; ++it_b){
347 const LArDigit* digit = *it_b;
348 HWIdentifier chid = digit->hardwareID() ;
349 uint32_t reid = hid2re.getRodID( **febRodMapping, chid );
350 // Lets use anygain for the moment
351 getEncoder(reid).add (digit);
352 }
353 } // End of check whether format allows to include RawData
354 } // Finish checking for Digit container in SG
355 } // End of check for digits inclusion
356
358
359 // Now loop over map and fill all ROD Data Blocks
360 std::map<uint32_t,LArRodEncoder>::iterator it_m =mapEncoder.begin();
361 std::map<uint32_t,LArRodEncoder>::iterator it_m_e=mapEncoder.end();
362 // LArRodEncoder has collected all the channels, now can fill the
363 // ROD block data.
364 for(; it_m!=it_m_e;++it_m) {
365 theROD = fea.getRodData( (*it_m).first );
366 ((*it_m).second).fillROD( *theROD,msg(), **noise, m_nfebsigma ) ;
367 // delete ((*it_m).second);
368 // ((*it_m).second)=NULL;
369 }
370 ATH_MSG_DEBUG ( "Filled " << mapEncoder.size() << " Rod Blocks" );
371 return StatusCode::SUCCESS;
372}
373
374
375StatusCode
377 RobIndex_t& robIndex) const
378{
379 // This `optimization' leads to disaster if there ever happen to be
380 // two adjacent events with identical L1 IDs --- in that case,
381 // we'd be using the dangling ROB pointers from the last event.
382 // We should generally come through here only once per event anyway.
383 ATH_MSG_DEBUG( "Converting event (from ByteStream)" );
384
385 if (!re) {
386 ATH_MSG_ERROR ( "RawEvent passed to 'convert'-function is a null pointer!" );
387 return StatusCode::FAILURE;
388 }
389
390 if (!m_decoder->check_valid (re, msg())) return StatusCode::FAILURE;
391
392 ATH_MSG_VERBOSE ( "Full Event:" );
393 ATH_MSG_VERBOSE ( MSG::hex << "Full source ID: " << re->source_id() << MSG::dec );
394 ATH_MSG_VERBOSE ("Fragment size in words: " << re->fragment_size_word() );
395
396 // Need to clear up or it will accumulate
397 robIndex.clear();
398 eformat::helper::build_toc(*re, robIndex );
399 if ( robIndex.empty() ) { // This is a problem
400 return StatusCode::FAILURE;
401 }
402 return StatusCode::SUCCESS;
403}
404
405
407std::unique_ptr<LArRodBlockStructure>
409{
410 switch(m_DSPRunMode) {
411 case 0: // Obsolete; shouldn't get here.
412 std::abort();
413
414 case 2: //Transparent mode, DSP just copies FEB-data
415 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockTransparent (#2)" );
416 return std::make_unique<LArRodBlockTransparentV0<LArRodBlockHeaderTransparentV0> >(this->msgSvc().get());
417 break;
418
419 case 7: //Calibration mode
420 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockCalibration (#7)" );
421 return std::make_unique<LArRodBlockCalibrationV0<LArRodBlockHeaderCalibrationV0> >(this->msgSvc().get());
422 break;
423
424 case 4: //Physics assembly mode
425 if ( m_RodBlockVersion == 10 ){
426 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockPhysics (#5)" );
427 return std::make_unique<LArRodBlockPhysicsV5>(this->msgSvc().get());
428 }
429 else if ( m_RodBlockVersion == 12 ){
430 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockPhysics (#6)" );
431 return std::make_unique<LArRodBlockPhysicsV6>(this->msgSvc().get());
432 }
433 else {
434 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockPhysics (#4)" );
435 return std::make_unique<LArRodBlockPhysicsV0>(this->msgSvc().get());
436 }
437 break;
438
439 case 5: //Physics assembly mode
440 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockPhysics (#5)" );
441 return std::make_unique<LArRodBlockPhysicsV3>(this->msgSvc().get());
442
443 default:
444 ATH_MSG_WARNING ( "DSP runmode " << m_DSPRunMode << " is unknown. Using physics assembly mode (#4) by default" );
445 return std::make_unique<LArRodBlockPhysicsV0>(this->msgSvc().get());
446 }
447}
448
449
450const Hid2RESrcID&
452{
453 if (!m_hid2re) {
454 auto hid2re = std::make_unique<Hid2RESrcID>();
455 if (hid2re->initialize (rodMapping).isFailure()) {
456 std::abort();
457 }
458 m_hid2re.set (std::move (hid2re));
459 }
460 return *m_hid2re.get();
461}
462
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static const InterfaceID IID_ILArRawDataContByteStreamTool("LArRawDataContByteStreamTool", 1, 0)
Helper tool for conversion of raw data classes to/from LArByteStream.
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition RawEvent.h:37
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
void setRodMinorVersion(uint16_t m)
change the ROD minor version
void setDetEvtType(uint32_t m)
change Detector Event Type
RODDATA * getRodData(uint32_t id)
get a block of ROD data
uint32_t getRodID(const LArFebRodMapping &rodMapping, const HWIdentifier &hid) const
make a ROD SrcID for a HWIdentifier
Container class for LArCalibDigit.
Base class for LArDigits taken during calibration runs.
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
Container for LArRawChannel (IDC using LArRawChannelCollection)
Liquid Argon ROD output object base class.
HWIdentifier channelID() const
StatusCode prepareRobIndex(const RawEvent *event, RobIndex_t &robIndex) const
Prepare ROB index before conversion.
CxxUtils::CachedUniquePtr< Hid2RESrcID > m_hid2re
Contains the mapping from channel to ROD (writing only)
std::map< eformat::SubDetectorGroup, std::vector< const uint32_t * > > RobIndex_t
unsigned m_DSPRunMode
Indicates which version of DSP code should be used for writing.
PublicToolHandle< LArRodDecoder > m_decoder
bool checkGainConsistency(const COLLECTION *coll) const
Check that all elements in a container have the same gain.
SG::ReadCondHandleKey< CaloNoise > m_caloNoiseKey
StatusCode WriteLArRawChannels(const LArRawChannelContainer *CannelCont, FEA_t &fea) const
Fill channels from LArRawChannelContainer to a FullEvent.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_onOffIdMappingKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
virtual StatusCode initialize() override
static const InterfaceID & interfaceID()
AlgTool InterfaceID.
SG::ReadCondHandleKey< LArFebRodMapping > m_febRodMappingKey
StatusCode WriteLArDigits(const LArDigitContainer *digit_cont, FEA_t &fea) const
Fill channels from LArDigitContainer to a FullEvent.
LArRawDataContByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor Standard AlgTool constructor.
StatusCode WriteLArCalibDigits(const LArCalibDigitContainer *digit_cont, FEA_t &fea) const
Fill channels from LArCalibDigitContainer to a FullEvent.
std::unique_ptr< LArRodBlockStructure > makeRodBlockStructure() const
Construct a RodBlockStructure instance of the proper concrete type.
unsigned short m_RodBlockVersion
Minor ROD block version This is equivalent to the lower 16 bits of the version word in the ROD block ...
FullEventAssembler< RodRobIdMap > FEA_t
const Hid2RESrcID & getHid2RESrcID(const LArFebRodMapping &rodMapping) const
virtual StatusCode finalize() override
bool m_initializeForWriting
JobOption to intitialize services needed only for writing.
This class provides conversion from LArRawChannel and LArDigit to ROD format.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130