ATLAS Offline Software
Loading...
Searching...
No Matches
CpmRoiByteStreamV1Cnv.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
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
28
31
32namespace LVL1BS {
33
35 : AthConstConverter( storageType(), classID(), svcloc, "CpmRoiByteStreamV1Cnv" ),
36 m_tool("LVL1BS::CpmRoiByteStreamV1Tool/CpmRoiByteStreamV1Tool"),
37 m_robDataProvider("ROBDataProviderSvc", name())
38{
39}
40
44
45// CLID
46
51
56
57// Init method gets all necessary services etc.
58
59
61{
62 ATH_CHECK( Converter::initialize() );
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
78StatusCode CpmRoiByteStreamV1Cnv::createObjConst( IOpaqueAddress* pAddr,
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 if (robFrags.size() == 0) {
103 pObj = SG::asStorable(std::move(roiCollection)) ;
104 return StatusCode::SUCCESS;
105 }
106
107 ATH_CHECK( m_tool->convert(robFrags, roiCollection.get()) );
108
109 pObj = SG::asStorable(std::move(roiCollection));
110
111 return StatusCode::SUCCESS;
112}
113
114// createRep should create the bytestream from RDOs.
115
116StatusCode CpmRoiByteStreamV1Cnv::createRepConst( DataObject* pObj,
117 IOpaqueAddress*& pAddr ) const
118{
119 DataVector<LVL1::CPMRoI>* roiCollection = 0;
120 if( !SG::fromStorable( pObj, roiCollection ) ) {
121 REPORT_ERROR (StatusCode::FAILURE) << " Cannot cast to DataVector<CPMRoI>";
122 return StatusCode::FAILURE;
123 }
124
125 const std::string nm = pObj->registry()->name();
126
127 pAddr = new ByteStreamAddress( classID(), nm, "" );
128
129 // Convert to ByteStream
130 return m_tool->convert( roiCollection );
131}
132
133} // end namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< Identifier > ID
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
Helpers for checking error return status codes and reporting errors.
#define REPORT_ERROR(SC)
Report an error.
An STL vector of pointers that by default owns its pointed-to elements.
uint32_t CLID
The Class ID type.
static Double_t sc
Defines the ROB data entity. The ROB data is an abstract entity that is used to decouple the raw even...
convert to and from a SG storable
AthConstConverter(long storage_type, const CLID &class_type, ISvcLocator *svc, const std::string &name)
const std::string & name() const
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
static constexpr long storageType()
Derived DataVector<T>.
Definition DataVector.h:795
std::vector< const ROBF * > VROBFRAG
virtual StatusCode createObjConst(IOpaqueAddress *pAddr, DataObject *&pObj) const override
Create CPM RoIs from ByteStream.
ToolHandle< LVL1BS::CpmRoiByteStreamV1Tool > m_tool
Tool that does the actual work.
virtual StatusCode initialize() override
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Service for reading bytestream.
virtual StatusCode createRepConst(DataObject *pObj, IOpaqueAddress *&pAddr) const override
Create ByteStream from CPM RoIs.
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
Default, invalid implementation of ClassID_traits.