ATLAS Offline Software
JepRoiReadByteStreamV1Cnv.icc
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 #include <typeinfo>
9 
10 #include "ByteStreamCnvSvcBase/ByteStreamAddress.h"
11 #include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h"
12 
13 #include "ByteStreamData/RawEvent.h"
14 #include "ByteStreamData/ROBData.h"
15 
16 #include "GaudiKernel/DataObject.h"
17 #include "GaudiKernel/IOpaqueAddress.h"
18 #include "GaudiKernel/ISvcLocator.h"
19 #include "GaudiKernel/StatusCode.h"
20 
21 #include "AthenaKernel/ClassID_traits.h"
22 #include "AthenaKernel/StorableConversions.h"
23 #include "AthenaKernel/errorcheck.h"
24 
25 #include "JepRoiByteStreamV1Tool.h"
26 
27 namespace LVL1BS {
28 
29 template <typename Container>
30 JepRoiReadByteStreamV1Cnv<Container>::JepRoiReadByteStreamV1Cnv(
31  ISvcLocator* svcloc )
32  : AthConstConverter( storageType(), classID(), svcloc, "JepRoiReadByteStreamV1Cnv" ),
33  m_tool("LVL1BS::JepRoiByteStreamV1Tool/JepRoiByteStreamV1Tool"),
34  m_robDataProvider("ROBDataProviderSvc", name())
35 {
36 }
37 
38 template <typename Container>
39 JepRoiReadByteStreamV1Cnv<Container>::~JepRoiReadByteStreamV1Cnv()
40 {
41 }
42 
43 // CLID
44 
45 template <typename Container>
46 const CLID& JepRoiReadByteStreamV1Cnv<Container>::classID()
47 {
48  return ClassID_traits<Container>::ID();
49 }
50 
51 template <typename Container>
52 long JepRoiReadByteStreamV1Cnv<Container>::storageType()
53 {
54  return ByteStreamAddress::storageType();
55 }
56 
57 // Init method gets all necessary services etc.
58 
59 
60 template <typename Container>
61 StatusCode JepRoiReadByteStreamV1Cnv<Container>::initialize()
62 {
63  ATH_CHECK( Converter::initialize() );
64  ATH_CHECK( m_tool.retrieve() );
65  ATH_CHECK( m_robDataProvider.retrieve() );
66 
67  return StatusCode::SUCCESS;
68 }
69 
70 // createObj should create the RDO from bytestream.
71 
72 template <typename Container>
73 StatusCode JepRoiReadByteStreamV1Cnv<Container>::createObjConst ( IOpaqueAddress* pAddr,
74  DataObject*& pObj ) const
75 {
76  ByteStreamAddress *pBS_Addr;
77  pBS_Addr = dynamic_cast<ByteStreamAddress *>( pAddr );
78  if ( !pBS_Addr ) {
79  ATH_MSG_ERROR( " Cannot cast to ByteStreamAddress " );
80  return StatusCode::FAILURE;
81  }
82 
83  const std::string nm = *( pBS_Addr->par() );
84 
85  ATH_MSG_DEBUG( " Creating Objects " << nm );
86 
87  // get SourceIDs
88  const std::vector<uint32_t>& vID(m_tool->sourceIDs(nm));
89 
90  // get ROB fragments
91  IROBDataProviderSvc::VROBFRAG robFrags;
92  m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags );
93 
94  // size check
95  auto collection = std::make_unique<Container>();
96  ATH_MSG_DEBUG( " Number of ROB fragments is " << robFrags.size() );
97 
98  if (robFrags.size() == 0) {
99  pObj = SG::asStorable(std::move(collection)) ;
100  return StatusCode::SUCCESS;
101  }
102 
103  ATH_CHECK( m_tool->convert(robFrags, collection.get()) );
104 
105  pObj = SG::asStorable(std::move(collection));
106 
107  return StatusCode::SUCCESS;
108 }
109 
110 } // end namespace