ATLAS Offline Software
TileRawChannelContByteStreamCnv.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Gaudi includes
6 #include "GaudiKernel/MsgStream.h"
7 #include "GaudiKernel/StatusCode.h"
8 #include "GaudiKernel/DataObject.h"
9 #include "GaudiKernel/IRegistry.h"
10 #include "GaudiKernel/IToolSvc.h"
11 #include "GaudiKernel/ServiceHandle.h"
12 
13 // Athena includes
16 
21 #include "ByteStreamData/RawEvent.h"
22 
24 #include "AthenaKernel/CLASS_DEF.h"
25 
26 // Tile includes
32 
33 
34 #include <string>
35 #include <stdint.h>
36 
38  : AthConstConverter(storageType(), classID(), svcloc, "TileRawChannelContByteStreamCnv")
39  , m_tool("TileRawChannelContByteStreamTool")
40  , m_byteStreamEventAccess("ByteStreamCnvSvc", name())
41  , m_byteStreamCnvSvc(0)
42  , m_robSvc("ROBDataProviderSvc", name())
43  , m_decoder("TileROD_Decoder")
44  , m_hid2re(0)
45 {
46 }
47 
49 
51 
53 
54  ATH_MSG_DEBUG(" initialize ");
55 
57 
58  // Get ByteStreamCnvSvc
59  ATH_CHECK( m_byteStreamEventAccess.retrieve() );
61 
62  // retrieve Tool
63  ATH_CHECK( m_decoder.retrieve() );
64  m_hid2re = m_decoder->getHid2re();
65 
66  ATH_CHECK( m_tool.retrieve() );
67 
68  ATH_CHECK( m_robSvc.retrieve() );
69 
70  return StatusCode::SUCCESS;
71 }
72 
73 StatusCode TileRawChannelContByteStreamCnv::createObjConst(IOpaqueAddress* pAddr, DataObject*& pObj) const
74 {
75  ATH_MSG_DEBUG(" Executing createObj method ");
76 
77  ByteStreamAddress *pRE_Addr;
78  pRE_Addr = dynamic_cast<ByteStreamAddress*>(pAddr);
79 
80  if(!pRE_Addr) {
81  ATH_MSG_ERROR(" Can not cast to ByteStreamAddress ");
82  return StatusCode::FAILURE;
83  }
84 
85  const std::string containerName(*(pRE_Addr->par()));
86  bool isTMDB(containerName == std::string("MuRcvRawChCnt"));
87 
88  uint32_t newrob = 0x0;
89 
90 
91  std::vector<uint32_t> robid(1);
92  robid[0] = 0;
93  std::vector<const ROBDataProviderSvc::ROBF*> robf;
94 
95  TileMutableRawChannelContainer* cont = m_queue.get (true);
96  ATH_CHECK( cont->status() );
97 
98  if (isTMDB) {
99  cont->set_type (TileFragHash::MF);
100  } else {
101  cont->set_type (TileFragHash::OptFilterDsp);
102  }
103 
104  std::unordered_map<uint32_t,int> bsflags;
105  uint32_t flag;
106 
107  // iterate over all collections in a container and fill them
108  for (IdentifierHash hash : cont->GetAllCurrentHashes()) {
109  TileRawChannelCollection* rawChannelCollection = cont->indexFindPtr (hash);
110  rawChannelCollection->clear();
111  TileRawChannelCollection::ID collID = rawChannelCollection->identify();
112 
113  // find ROB
114  if (isTMDB) {
115  newrob = m_hid2re->getRobFromTileMuRcvFragID(collID);
116  } else {
117  newrob = m_hid2re->getRobFromFragID(collID);
118  }
119 
120  if (newrob != robid[0]) {
121  robid[0] = newrob;
122  robf.clear();
123  m_robSvc->getROBData(robid, robf);
124  }
125 
126  // unpack ROB data
127  if (robf.size() > 0 ) {
128  if (isTMDB) {// reid for TMDB 0x5x010x
129  m_decoder->fillCollection_TileMuRcv_RawChannel(robf[0], *rawChannelCollection);
130  } else {
131  m_decoder->fillCollection(robf[0], *rawChannelCollection, cont);
132  }
133  flag = cont->get_bsflags();
134  auto result = bsflags.insert(std::pair<uint32_t, int>(flag, 1));
135  if (result.second == false) result.first->second++;
136  } else {
137  ATH_MSG_DEBUG( "ROB for " << ((isTMDB)?"TMDB ":"") << "drawer 0x" << MSG::hex << collID << MSG::dec << " not found in BS" );
139  rawChannelCollection->setFragGlobalCRC(status);
140  ATH_MSG_DEBUG( "Status for " << ((isTMDB)?"TMDB ":"") << "drawer 0x" << MSG::hex << collID << " is 0x" << status << MSG::dec);
141  }
142  }
143 
144  if (bsflags.size() > 1) {
145  int n=0;
146  for (const auto & elem : bsflags) {
147  if (elem.second > n) {
148  n = elem.second;
149  flag = elem.first;
150  }
151  }
152 
153  if (flag != cont->get_bsflags()) {
154 
155  uint32_t unit = ((flag & 0xC0000000) >> 30);
156  if ((flag & 0x30000000) < 0x30000000) unit += TileRawChannelUnit::OnlineOffset; // Online units in real data
157 
158  ATH_MSG_DEBUG( "Changing units for " << ((isTMDB)?"TMDB ":"") << "RawChannelContainer from "
159  << cont->get_unit() << " to " << unit << MSG::hex
160  << " and BS flags from 0x" << cont->get_bsflags() << " to 0x" << flag << MSG::dec);
161 
162  cont->set_unit((TileRawChannelUnit::UNIT)unit);
163  cont->set_bsflags(flag);
164  }
165  }
166 
167  ATH_MSG_DEBUG( "Creating raw channel container: " << containerName );
168 
169  TileRawChannelContainer* basecont = cont;
170  pObj = SG::asStorable( basecont );
171 
172 
173  return StatusCode::SUCCESS;
174 }
175 
176 StatusCode TileRawChannelContByteStreamCnv::createRepConst(DataObject* pObj, IOpaqueAddress*& pAddr) const
177 {
178  // convert TileRawChannels in the container into ByteStream
179 
180  ATH_MSG_DEBUG(" Executing createRep method ");
181 
182  // uint32_t runnum = re->header()->specific_part()->run_no();
183 
184  std::string key("Tile");
185 
186  // get Full Event Assembler
189 
190  // create TileRawChannelContainer
191  TileRawChannelContainer* rccont(0) ;
192  SG::fromStorable(pObj, rccont );
193  if(!rccont){
194  ATH_MSG_ERROR(" Can not cast to TileRawChannelContainer ");
195  return StatusCode::FAILURE;
196  }
197 
198  std::string name = pObj->registry()->name();
199 
200  if ( pAddr != nullptr ) pAddr->release();
201  ByteStreamAddress* addr = new ByteStreamAddress(classID(), name, "");
202  pAddr = addr;
203  pAddr->addRef();
204 
205  ATH_CHECK( m_tool->convert(rccont, fea) );
206 
207  return StatusCode::SUCCESS;
208 }
209 
211 {
212  return Converter::finalize();
213 }
214 
TileRawChannelContainer
Definition: TileRawChannelContainer.h:13
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
get_generator_info.result
result
Definition: get_generator_info.py:21
FullEventAssembler
Template class for assembling a full atlas raw event from subfragments.
Definition: FullEventAssembler.h:40
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::fromStorable
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
Definition: StorableConversions.h:180
StorableConversions.h
convert to and from a SG storable
TileMutableDataContainer::status
StatusCode status() const
Return the error status from the constructors.
initialize
void initialize()
Definition: run_EoverP.cxx:894
TileHid2RESrcID::getRobFromFragID
uint32_t getRobFromFragID(int frag_id) const
make a ROB SrcID for a fragment ID
Definition: TileHid2RESrcID.cxx:457
TileRawChannelContByteStreamCnv::finalize
virtual StatusCode finalize() override
Definition: TileRawChannelContByteStreamCnv.cxx:210
TileRawChannelCollection::setFragGlobalCRC
void setFragGlobalCRC(uint32_t globalcrc)
Various set methods.
Definition: TileRawChannelCollection.h:81
TileRawChannelContByteStreamCnv::m_hid2re
const TileHid2RESrcID * m_hid2re
Pointer to TileHid2RESrcID.
Definition: TileRawChannelContByteStreamCnv.h:73
TileRawChannelContByteStreamCnv::m_decoder
ToolHandle< TileROD_Decoder > m_decoder
Pointer to TileROD_Decoder.
Definition: TileRawChannelContByteStreamCnv.h:70
TileHid2RESrcID::getRobFromTileMuRcvFragID
uint32_t getRobFromTileMuRcvFragID(int frag_id) const
Definition: TileHid2RESrcID.cxx:579
TileRawChannelContByteStreamCnv::m_tool
ToolHandle< TileRawChannelContByteStreamTool > m_tool
Definition: TileRawChannelContByteStreamCnv.h:61
SG::asStorable
DataObject * asStorable(T *pObject)
Definition: StorableConversions.h:158
ROBDataProviderSvc.h
AthConstConverter
Gaudi converter base class with const interfaces.
Definition: AthConstConverter.h:33
TileRawChannelContByteStreamCnv::m_byteStreamEventAccess
ServiceHandle< IByteStreamEventAccess > m_byteStreamEventAccess
Definition: TileRawChannelContByteStreamCnv.h:63
TileFragHash::OptFilterDsp
@ OptFilterDsp
Definition: TileFragHash.h:34
TileRawChannelContByteStreamCnv::createRepConst
virtual StatusCode createRepConst(DataObject *pObj, IOpaqueAddress *&pAddr) const override
Convert the transient object to the requested representation.
Definition: TileRawChannelContByteStreamCnv.cxx:176
TileRawChannelContByteStreamCnv.h
TileRawChannelContainer.h
TileRawChannelContByteStreamCnv::createObjConst
virtual StatusCode createObjConst(IOpaqueAddress *pAddr, DataObject *&pObj) const override
Create the transient representation of an object.
Definition: TileRawChannelContByteStreamCnv.cxx:73
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
TileRawChannelCollection::ID
MyBase::ID ID
Definition: TileRawChannelCollection.h:17
ByteStreamCnvSvc
Gaudi Conversion Service class for ByteStream Persistency.
Definition: ByteStreamCnvSvc.h:34
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TileROD_Decoder.h
beamspotman.n
n
Definition: beamspotman.py:731
RawEvent.h
TileRawChannelContByteStreamCnv::TileRawChannelContByteStreamCnv
TileRawChannelContByteStreamCnv(ISvcLocator *svcloc)
Definition: TileRawChannelContByteStreamCnv.cxx:37
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TileMutableDataContainer
Helper for holding non-const raw data prior to recording in SG.
Definition: TileMutableDataContainer.h:52
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TileRawChannelUnit::OnlineOffset
@ OnlineOffset
Definition: TileRawChannelUnit.h:25
master.flag
bool flag
Definition: master.py:29
ByteStreamAddress
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
Definition: ByteStreamAddress.h:28
TileROD_Decoder::CRC_ERR
@ CRC_ERR
Definition: TileROD_Decoder.h:226
TileRawChannelContByteStreamCnv::storageType
static long storageType()
Definition: TileRawChannelContByteStreamCnv.cxx:50
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ByteStreamAddress.h
ByteStreamCnvSvc.h
TileRawChannelUnit::UNIT
UNIT
Definition: TileRawChannelUnit.h:16
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
TileROD_Decoder::NO_ROB
@ NO_ROB
Definition: TileROD_Decoder.h:226
TileRawDataCollection::identify
ID identify() const
Definition: TileRawDataCollection.h:71
TileHid2RESrcID.h
ByteStreamAddress::storageType
static constexpr long storageType()
Definition: ByteStreamAddress.h:51
TileMutableDataContainer::indexFindPtr
Collection * indexFindPtr(IdentifierHash hash)
Look up a (non-const) collection via hash.
TileRawChannelContByteStreamCnv::m_robSvc
ServiceHandle< IROBDataProviderSvc > m_robSvc
Pointer to IROBDataProviderSvc.
Definition: TileRawChannelContByteStreamCnv.h:67
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TileFragHash::MF
@ MF
Definition: TileFragHash.h:35
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileRawChannelCollection
Definition: TileRawChannelCollection.h:12
StoreClearedIncident.h
Incident sent after a store is cleared.
TileRawChannelContByteStreamCnv::m_byteStreamCnvSvc
ByteStreamCnvSvc * m_byteStreamCnvSvc
Definition: TileRawChannelContByteStreamCnv.h:64
TileRawChannelCollection::clear
void clear()
Clear everything for next event.
Definition: TileRawChannelCollection.cxx:52
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:20
ByteStreamCnvSvcBase.h
TileRawChannelContByteStreamTool.h
merge.status
status
Definition: merge.py:17
ByteStreamCnvSvc::getFullEventAssembler
StatusCode getFullEventAssembler(T *&t, const std::string &nm)
Access to FullEventAssembler.
Definition: ByteStreamCnvSvc.h:121
IdentifierHash
Definition: IdentifierHash.h:38
TileRawChannelContByteStreamCnv::initialize
virtual StatusCode initialize() override
Definition: TileRawChannelContByteStreamCnv.cxx:52
CLASS_DEF.h
macros to associate a CLID to a type
TileRawChannelContByteStreamCnv::classID
static const CLID & classID()
Definition: TileRawChannelContByteStreamCnv.cxx:48
AthConstConverter::name
std::string name() const
Definition: AthConstConverter.h:67
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37