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
21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/ThreadLocalContext.h"
23
25
26// STL stuff
27#include <map>
28
29
30static const InterfaceID IID_ILArRawDataContByteStreamTool
31 ("LArRawDataContByteStreamTool", 1, 0);
32
33
36
37// default contructor
38
40( const std::string& type, const std::string& name,const IInterface* parent )
41 : AthAlgTool(type,name,parent)
42{ declareInterface< LArRawDataContByteStreamTool >( this );
43 declareProperty("DSPRunMode",m_DSPRunMode=4);
44 declareProperty("RodBlockVersion",m_RodBlockVersion=0);
45 declareProperty("FebNoiseCut",m_nfebsigma=2);
46 declareProperty("InitializeForWriting",m_initializeForWriting=false);
47 declareProperty("SubDetectorId",m_subDetId=0);
48 declareProperty("IncludeDigits",m_includeDigits=false);
49 declareProperty("DigitsContainer",m_DigitContName="LArDigitContainer_MC_Thinned");
50}
51
54
55
56StatusCode
58{
59 ATH_CHECK( AthAlgTool::initialize() );
60 ATH_MSG_DEBUG ( "Initializing LArRawDataContByteStream" );
61
62 ATH_CHECK( m_decoder.retrieve() );
63
65 if (m_DSPRunMode == 0) {
66 // Obsolete mode
67 ATH_MSG_ERROR ( "LArRodBlockStructure type 0 is obsolete and can't be used any more." );
68 return StatusCode::FAILURE;
69 }
70
71 ATH_CHECK( detStore()->retrieve (m_onlineHelper, "LArOnlineID") );
72
73 ATH_MSG_INFO ( "Initialization done for reading and writing" );
74 }
75 else {
76 ATH_MSG_INFO ( "Initialization done for reading only" );
77 }
78
83
84 return StatusCode::SUCCESS;
85}
86
87
88StatusCode
90{
91 ATH_CHECK( AthAlgTool::finalize() );
92 return StatusCode::SUCCESS;
93}
94
95StatusCode
97 FEA_t& fea) const
98{
100 ATH_MSG_ERROR ( "Tool not setup for writing! Use property "
101 << name()<<".InitializeForWriting" );
102 return StatusCode::FAILURE;
103 }
104 if (!channelCont) {
105 ATH_MSG_DEBUG ( "Null pointer passed to WriteLArCalibDigit routine!" );
106 return StatusCode::FAILURE;
107 }
108
109 std::unique_ptr<LArRodBlockStructure> blstruct = makeRodBlockStructure();
110
111 if (!blstruct->canSetEnergy()) {
112 ATH_MSG_DEBUG ( "This instance of LArRodBlockStructure can't hold LArRawChannels!" );
113 return StatusCode::FAILURE;
114 }
115 FEA_t::RODDATA* theROD;
118 ATH_MSG_DEBUG ( "Setting Detector Event Type to " << m_DSPRunMode
119 << "and Minor Version Number to " << m_RodBlockVersion );
120 LArRawChannelContainer::const_iterator it = channelCont->begin();
121 LArRawChannelContainer::const_iterator it_e= channelCont->end();
122 if ( it==it_e) {
123 ATH_MSG_WARNING ( "Attempt to persistify a empty LArDigitContainer to ByteStream" );
124 return StatusCode::SUCCESS;
125 }
126
127 const EventContext& ctx = Gaudi::Hive::currentContext();
131 const Hid2RESrcID& hid2re = getHid2RESrcID (**febRodMapping);
132
133 std::map<uint32_t, LArRodEncoder> mapEncoder;
134
135 auto getEncoder = [&] (uint32_t reid) -> LArRodEncoder&
136 { return mapEncoder.try_emplace (reid,
138 **caloMgr,
139 **onOffMapping,
140 blstruct.get()).first->second; };
141
142 ATH_MSG_DEBUG(" number of LArRawChannel container "<< channelCont->size() );
143 for(; it!=it_e; ++it){
144 const LArRawChannel& rawChan = *it;
145 HWIdentifier chid = rawChan.channelID() ;
146 uint32_t reid = hid2re.getRodID( **febRodMapping, chid );
147
148 getEncoder(reid).add (&rawChan);
149 }
150 // I may want to also include the digits
151 if ( m_includeDigits ) {
152 const LArDigitContainer* digitCont = nullptr;
153 if ( evtStore()->retrieve(digitCont,m_DigitContName).isFailure() ){
154 ATH_MSG_ERROR ( "Digits required but not really found" );
155 } else {
156 if ( blstruct->canIncludeRawData() ){
158 LArDigitContainer::const_iterator it_e=digitCont->end();
159 if (it_b==it_e) {
160 ATH_MSG_WARNING ( "Attempt to persistify a empty LArDigitContainer to ByteStream" );
161 }
162 for(; it_b!=it_e; ++it_b){
163 const LArDigit* digit = *it_b;
164 HWIdentifier chid = digit->hardwareID() ;
165 uint32_t reid = hid2re.getRodID( **febRodMapping, chid );
166 // Lets use anygain for the moment
167 getEncoder(reid).add (digit);
168 }
169 } // End of check whether format allows to include RawData
170 } // Finish checking for Digit container in SG
171 } // End of check for digits inclusion
172
174
175 // Now loop over map and fill all ROD Data Blocks
176 std::map<uint32_t,LArRodEncoder>::iterator it_m =mapEncoder.begin();
177 std::map<uint32_t,LArRodEncoder>::iterator it_m_e=mapEncoder.end();
178 // LArRodEncoder has collected all the channels, now can fill the
179 // ROD block data.
180 for(; it_m!=it_m_e;++it_m) {
181 theROD = fea.getRodData( (*it_m).first );
182 ((*it_m).second).fillROD( *theROD,msg(), **noise, m_nfebsigma ) ;
183 // delete ((*it_m).second);
184 // ((*it_m).second)=NULL;
185 }
186 ATH_MSG_DEBUG ( "Filled " << mapEncoder.size() << " Rod Blocks" );
187 return StatusCode::SUCCESS;
188}
189
190StatusCode
192 RobIndex_t& robIndex) const
193{
194 // This `optimization' leads to disaster if there ever happen to be
195 // two adjacent events with identical L1 IDs --- in that case,
196 // we'd be using the dangling ROB pointers from the last event.
197 // We should generally come through here only once per event anyway.
198 ATH_MSG_DEBUG( "Converting event (from ByteStream)" );
199
200 if (!re) {
201 ATH_MSG_ERROR ( "RawEvent passed to 'convert'-function is a null pointer!" );
202 return StatusCode::FAILURE;
203 }
204
205 if (!m_decoder->check_valid (re, msg())) return StatusCode::FAILURE;
206
207 ATH_MSG_VERBOSE ( "Full Event:" );
208 ATH_MSG_VERBOSE ( MSG::hex << "Full source ID: " << re->source_id() << MSG::dec );
209 ATH_MSG_VERBOSE ("Fragment size in words: " << re->fragment_size_word() );
210
211 // Need to clear up or it will accumulate
212 robIndex.clear();
213 eformat::helper::build_toc(*re, robIndex );
214 if ( robIndex.empty() ) { // This is a problem
215 return StatusCode::FAILURE;
216 }
217 return StatusCode::SUCCESS;
218}
219
220
222std::unique_ptr<LArRodBlockStructure>
224{
225 switch(m_DSPRunMode) {
226 case 0: // Obsolete; shouldn't get here.
227 std::abort();
228
229 case 2: //Transparent mode, DSP just copies FEB-data
230 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockTransparent (#2)" );
231 return std::make_unique<LArRodBlockTransparentV0<LArRodBlockHeaderTransparentV0> >(this->msgSvc().get());
232 break;
233
234 case 4: //Physics assembly mode
235 if ( m_RodBlockVersion == 10 ){
236 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockPhysics (#5)" );
237 return std::make_unique<LArRodBlockPhysicsV5>(this->msgSvc().get());
238 }
239 else if ( m_RodBlockVersion == 12 ){
240 ATH_MSG_DEBUG ( "Set Rod Block Type to LArRodBlockPhysics (#6)" );
241 return std::make_unique<LArRodBlockPhysicsV6>(this->msgSvc().get());
242 }
243 else {
244 ATH_MSG_ERROR ( "Unsupported Rod block version " << m_RodBlockVersion << " for physics assembly mode (#4)" );
245 std::abort();
246 }
247 break;
248
249 default:
250 ATH_MSG_ERROR ( "DSP runmode " << m_DSPRunMode << " is unknown." );
251 std::abort();
252 }
253}
254
255
256const Hid2RESrcID&
258{
259 if (!m_hid2re) {
260 auto hid2re = std::make_unique<Hid2RESrcID>();
261 if (hid2re->initialize (rodMapping).isFailure()) {
262 std::abort();
263 }
264 m_hid2re.set (std::move (hid2re));
265 }
266 return *m_hid2re.get();
267}
268
const std::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(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:861
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.
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 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
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
LArRawDataContByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor Standard AlgTool constructor.
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:132