ATLAS Offline Software
CpmRoiByteStreamCnv.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 
11 
13 #include "ByteStreamData/ROBData.h"
14 
16 
17 #include "GaudiKernel/DataObject.h"
18 #include "GaudiKernel/IOpaqueAddress.h"
19 #include "GaudiKernel/IRegistry.h"
20 #include "GaudiKernel/ISvcLocator.h"
21 #include "GaudiKernel/StatusCode.h"
22 
26 
27 #include "TrigT1CaloEvent/CPMRoI.h"
28 
29 #include "CpmRoiByteStreamCnv.h"
30 #include "CpmRoiByteStreamTool.h"
31 
32 namespace LVL1BS {
33 
35  : AthConstConverter( storageType(), classID(), svcloc, "CpmRoiByteStreamCnv" ),
36  m_tool("LVL1BS::CpmRoiByteStreamTool/CpmRoiByteStreamTool"),
37  m_robDataProvider("ROBDataProviderSvc", name())
38 {
39 }
40 
42 {
43 }
44 
45 // CLID
46 
48 {
50 }
51 
53 {
55 }
56 
57 // Init method gets all necessary services etc.
58 
59 
61 {
63  ATH_CHECK( m_tool.retrieve() );
64 
65  // Get ROBDataProvider
66  StatusCode sc = m_robDataProvider.retrieve();
67  if ( sc.isFailure() ) {
68  ATH_MSG_WARNING( "Failed to retrieve service " << m_robDataProvider );
69  // return is disabled for Write BS which does not require ROBDataProviderSvc
70  // return sc ;
71  }
72 
73  return StatusCode::SUCCESS;
74 }
75 
76 // createObj should create the RDO from bytestream.
77 
79  DataObject*& pObj ) const
80 {
81  ByteStreamAddress *pBS_Addr;
82  pBS_Addr = dynamic_cast<ByteStreamAddress *>( pAddr );
83  if ( !pBS_Addr ) {
84  ATH_MSG_ERROR( " Can not cast to ByteStreamAddress " );
85  return StatusCode::FAILURE;
86  }
87 
88  const std::string nm = *( pBS_Addr->par() );
89 
90  ATH_MSG_DEBUG( " Creating Objects " << nm );
91 
92  // get SourceIDs
93  const std::vector<uint32_t>& vID(m_tool->sourceIDs(nm));
94 
95  // get ROB fragments
97  m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags );
98 
99  // size check
100  auto roiCollection = std::make_unique<DataVector<LVL1::CPMRoI> >();
101  ATH_MSG_DEBUG( " Number of ROB fragments is " << robFrags.size() );
102 
103  if (robFrags.size() == 0) {
104  pObj = SG::asStorable(std::move(roiCollection)) ;
105  return StatusCode::SUCCESS;
106  }
107 
108  ATH_CHECK( m_tool->convert(robFrags, roiCollection.get()) );
109 
110  pObj = SG::asStorable(std::move(roiCollection));
111 
112  return StatusCode::SUCCESS;
113 }
114 
115 // createRep should create the bytestream from RDOs.
116 
118  IOpaqueAddress*& pAddr ) const
119 {
120  DataVector<LVL1::CPMRoI>* roiCollection = 0;
121  if( !SG::fromStorable( pObj, roiCollection ) ) {
122  ATH_MSG_ERROR( " Cannot cast to DataVector<CPMRoI>" );
123  return StatusCode::FAILURE;
124  }
125 
126  const std::string nm = pObj->registry()->name();
127 
128  pAddr = new ByteStreamAddress( classID(), nm, "" );
129 
130  // Convert to ByteStream
131  return m_tool->convert( roiCollection );
132 }
133 
134 } // end namespace
LVL1BS::CpmRoiByteStreamCnv::initialize
virtual StatusCode initialize() override
Definition: CpmRoiByteStreamCnv.cxx:60
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:167
StorableConversions.h
convert to and from a SG storable
LVL1BS::CpmRoiByteStreamCnv::storageType
static long storageType()
Definition: CpmRoiByteStreamCnv.cxx:52
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
CpmRoiByteStreamCnv.h
LVL1BS::CpmRoiByteStreamCnv::createRepConst
virtual StatusCode createRepConst(DataObject *pObj, IOpaqueAddress *&pAddr) const override
Create ByteStream from CPM RoIs.
Definition: CpmRoiByteStreamCnv.cxx:117
AthConstConverter
Gaudi converter base class with const interfaces.
Definition: AthConstConverter.h:33
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LVL1BS::CpmRoiByteStreamCnv::m_tool
ToolHandle< LVL1BS::CpmRoiByteStreamTool > m_tool
Tool that does the actual work.
Definition: CpmRoiByteStreamCnv.h:58
SG::asStorable
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
Definition: DataObjectSharedPtr.h:65
CpmRoiByteStreamTool.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
IROBDataProviderSvc::VROBFRAG
std::vector< const ROBF * > VROBFRAG
Definition: IROBDataProviderSvc.h:27
LVL1BS::CpmRoiByteStreamCnv::createObjConst
virtual StatusCode createObjConst(IOpaqueAddress *pAddr, DataObject *&pObj) const override
Create CPM RoIs from ByteStream.
Definition: CpmRoiByteStreamCnv.cxx:78
ByteStreamAddress.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
CPMRoI.h
ByteStreamAddress::storageType
static constexpr long storageType()
Definition: ByteStreamAddress.h:51
LVL1BS::CpmRoiByteStreamCnv::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service for reading bytestream.
Definition: CpmRoiByteStreamCnv.h:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
LVL1BS::CpmRoiByteStreamCnv::~CpmRoiByteStreamCnv
virtual ~CpmRoiByteStreamCnv()
Definition: CpmRoiByteStreamCnv.cxx:41
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
LVL1BS::CpmRoiByteStreamCnv::CpmRoiByteStreamCnv
CpmRoiByteStreamCnv(ISvcLocator *svcloc)
Definition: CpmRoiByteStreamCnv.cxx:34
CalibCoolCompareRT.nm
nm
Definition: CalibCoolCompareRT.py:110
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LVL1BS
Definition: ZdcModifySlices.h:10
LVL1BS::CpmRoiByteStreamCnv::classID
static const CLID & classID()
Definition: CpmRoiByteStreamCnv.cxx:47
IROBDataProviderSvc.h