ATLAS Offline Software
CpmRoiByteStreamV2Cnv.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 
6 #include <vector>
7 #include <stdint.h>
8 
12 
14 #include "ByteStreamData/ROBData.h"
15 
17 
18 #include "GaudiKernel/DataObject.h"
19 #include "GaudiKernel/IOpaqueAddress.h"
20 #include "GaudiKernel/IRegistry.h"
21 #include "GaudiKernel/ISvcLocator.h"
22 #include "GaudiKernel/StatusCode.h"
23 
27 
29 
30 #include "CpmRoiByteStreamV2Cnv.h"
31 #include "CpmRoiByteStreamV2Tool.h"
32 
33 namespace LVL1BS {
34 
36  : AthConstConverter( storageType(), classID(), svcloc, "CpmRoiByteStreamV2Cnv" ),
37  m_tool("LVL1BS::CpmRoiByteStreamV2Tool/CpmRoiByteStreamV2Tool"),
38  m_robDataProvider("ROBDataProviderSvc", name())
39 {
40 }
41 
43 {
44 }
45 
46 // CLID
47 
49 {
51 }
52 
54 {
56 }
57 
58 // Init method gets all necessary services etc.
59 
60 
62 {
64  ATH_CHECK( m_tool.retrieve() );
65 
66  // Get ROBDataProvider
67  StatusCode sc = m_robDataProvider.retrieve();
68  if ( sc.isFailure() ) {
69  ATH_MSG_WARNING( "Failed to retrieve service " << m_robDataProvider );
70  // return is disabled for Write BS which does not require ROBDataProviderSvc
71  // return sc ;
72  }
73 
74  return StatusCode::SUCCESS;
75 }
76 
77 // createObj should create the RDO from bytestream.
78 
80  DataObject*& pObj ) const
81 {
82  ByteStreamAddress *pBS_Addr;
83  pBS_Addr = dynamic_cast<ByteStreamAddress *>( pAddr );
84  if ( !pBS_Addr ) {
85  ATH_MSG_ERROR( " Can not cast to ByteStreamAddress " );
86  return StatusCode::FAILURE;
87  }
88 
89  const std::string nm = *( pBS_Addr->par() );
90 
91  ATH_MSG_DEBUG( " Creating Objects " << nm );
92 
93  // get SourceIDs
94  const std::vector<uint32_t>& vID(m_tool->sourceIDs(nm));
95 
96  // get ROB fragments
98  m_robDataProvider->getROBData( vID, robFrags );
99 
100  // size check
101  auto roiCollection = std::make_unique<DataVector<LVL1::CPMTobRoI> >();
102  ATH_MSG_DEBUG( " Number of ROB fragments is " << robFrags.size() );
103 
104  if (robFrags.size() == 0) {
105  pObj = SG::asStorable(std::move(roiCollection)) ;
106  return StatusCode::SUCCESS;
107  }
108 
109  ATH_CHECK( m_tool->convert(robFrags, roiCollection.get()) );
110 
111  pObj = SG::asStorable(std::move(roiCollection));
112 
113  return StatusCode::SUCCESS;
114 }
115 
116 // createRep should create the bytestream from RDOs.
117 
119  IOpaqueAddress*& pAddr ) const
120 {
121  DataVector<LVL1::CPMTobRoI>* roiCollection = 0;
122  if( !SG::fromStorable( pObj, roiCollection ) ) {
123  ATH_MSG_ERROR( " Cannot cast to DataVector<CPMTobRoI>" );
124  return StatusCode::FAILURE;
125  }
126 
127  const std::string nm = pObj->registry()->name();
128 
129  pAddr = new ByteStreamAddress( classID(), nm, "" );
130 
131  // Convert to ByteStream
132  return m_tool->convert( roiCollection );
133 }
134 
135 } // end namespace
LVL1BS::CpmRoiByteStreamV2Cnv::CpmRoiByteStreamV2Cnv
CpmRoiByteStreamV2Cnv(ISvcLocator *svcloc)
Definition: CpmRoiByteStreamV2Cnv.cxx:35
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
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
ROBData.h
Defines the ROB data entity. The ROB data is an abstract entity that is used to discase the raw event...
initialize
void initialize()
Definition: run_EoverP.cxx:894
LVL1BS::CpmRoiByteStreamV2Cnv::createRepConst
virtual StatusCode createRepConst(DataObject *pObj, IOpaqueAddress *&pAddr) const override
Create ByteStream from CPM RoIs.
Definition: CpmRoiByteStreamV2Cnv.cxx:118
SG::asStorable
DataObject * asStorable(T *pObject)
Definition: StorableConversions.h:158
LVL1BS::CpmRoiByteStreamV2Cnv::createObjConst
virtual StatusCode createObjConst(IOpaqueAddress *pAddr, DataObject *&pObj) const override
Create CPM RoIs from ByteStream.
Definition: CpmRoiByteStreamV2Cnv.cxx:79
IByteStreamEventAccess.h
AthConstConverter
Gaudi converter base class with const interfaces.
Definition: AthConstConverter.h:33
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CpmRoiByteStreamV2Cnv.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
RawEvent.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ByteStreamAddress
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
Definition: ByteStreamAddress.h:28
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LVL1BS::CpmRoiByteStreamV2Cnv::classID
static const CLID & classID()
Definition: CpmRoiByteStreamV2Cnv.cxx:48
IROBDataProviderSvc::VROBFRAG
std::vector< const ROBF * > VROBFRAG
Definition: IROBDataProviderSvc.h:29
CPMTobRoI.h
ByteStreamAddress.h
DataVector< LVL1::CPMTobRoI >
LVL1BS::CpmRoiByteStreamV2Cnv::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service for reading bytestream.
Definition: CpmRoiByteStreamV2Cnv.h:56
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
ByteStreamAddress::storageType
static constexpr long storageType()
Definition: ByteStreamAddress.h:51
LVL1BS::CpmRoiByteStreamV2Cnv::initialize
virtual StatusCode initialize() override
Definition: CpmRoiByteStreamV2Cnv.cxx:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CpmRoiByteStreamV2Tool.h
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
CalibCoolCompareRT.nm
nm
Definition: CalibCoolCompareRT.py:110
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LVL1BS
Definition: ZdcByteStreamReadV1V2Tool.h:47
LVL1BS::CpmRoiByteStreamV2Cnv::m_tool
ToolHandle< LVL1BS::CpmRoiByteStreamV2Tool > m_tool
Tool that does the actual work.
Definition: CpmRoiByteStreamV2Cnv.h:53
LVL1BS::CpmRoiByteStreamV2Cnv::~CpmRoiByteStreamV2Cnv
virtual ~CpmRoiByteStreamV2Cnv()
Definition: CpmRoiByteStreamV2Cnv.cxx:42
LVL1BS::CpmRoiByteStreamV2Cnv::storageType
static long storageType()
Definition: CpmRoiByteStreamV2Cnv.cxx:53
IROBDataProviderSvc.h