ATLAS Offline Software
JepReadByteStreamV1V2Cnv.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 
9 #include "ByteStreamCnvSvcBase/ByteStreamAddress.h"
10 #include "ByteStreamCnvSvcBase/IByteStreamEventAccess.h"
11 #include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h"
12 
13 #include "ByteStreamData/RawEvent.h"
14 #include "ByteStreamData/ROBData.h"
15 
16 #include "AthContainers/DataVector.h"
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 
24 #include "AthenaKernel/ClassID_traits.h"
25 #include "AthenaKernel/StorableConversions.h"
26 #include "AthenaKernel/errorcheck.h"
27 
28 #include "JepByteStreamV1Tool.h"
29 #include "JepByteStreamV2Tool.h"
30 
31 namespace LVL1BS {
32 
33 template <typename Container>
34 JepReadByteStreamV1V2Cnv<Container>::JepReadByteStreamV1V2Cnv( ISvcLocator* svcloc )
35  : AthConstConverter( storageType(), classID(), svcloc, "JepReadByteStreamV1V2Cnv" ),
36  m_tool1("LVL1BS::JepByteStreamV1Tool/JepByteStreamV1Tool"),
37  m_tool2("LVL1BS::JepByteStreamV2Tool/JepByteStreamV2Tool"),
38  m_robDataProvider("ROBDataProviderSvc", name())
39 {
40 }
41 
42 template <typename Container>
43 JepReadByteStreamV1V2Cnv<Container>::~JepReadByteStreamV1V2Cnv()
44 {
45 }
46 
47 // CLID
48 
49 template <typename Container>
50 const CLID& JepReadByteStreamV1V2Cnv<Container>::classID()
51 {
52  return ClassID_traits<Container>::ID();
53 }
54 
55 template <typename Container>
56 long JepReadByteStreamV1V2Cnv<Container>::storageType()
57 {
58  return ByteStreamAddress::storageType();
59 }
60 
61 // Init method gets all necessary services etc.
62 
63 
64 template <typename Container>
65 StatusCode JepReadByteStreamV1V2Cnv<Container>::initialize()
66 {
67  ATH_CHECK( Converter::initialize() );
68  ATH_CHECK( m_tool1.retrieve() );
69  ATH_CHECK( m_tool2.retrieve() );
70  ATH_CHECK( m_robDataProvider.retrieve() );
71 
72  return StatusCode::SUCCESS;
73 }
74 
75 // createObj should create the RDO from bytestream.
76 
77 template <typename Container>
78 StatusCode JepReadByteStreamV1V2Cnv<Container>::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>& vID1(m_tool1->sourceIDs());
94  const std::vector<uint32_t>& vID2(m_tool2->sourceIDs());
95 
96  // get ROB fragments
97  IROBDataProviderSvc::VROBFRAG robFrags1;
98  m_robDataProvider->getROBData( vID1, robFrags1 );
99  IROBDataProviderSvc::VROBFRAG robFrags2;
100  m_robDataProvider->getROBData( vID2, robFrags2 );
101 
102  // size check
103  auto collection = std::make_unique<Container>();
104  ATH_MSG_DEBUG( " Number of ROB fragments is " << robFrags1.size()
105  << ", " << robFrags2.size() );
106 
107  if (robFrags1.size() == 0 && robFrags2.size() == 0) {
108  pObj = SG::asStorable(std::move(collection)) ;
109  return StatusCode::SUCCESS;
110  }
111 
112  // Pre-LS1 data
113  if (robFrags1.size() > 0) {
114  ATH_CHECK( m_tool1->convert(nm, robFrags1, collection.get()) );
115  }
116  // Post-LS1 data
117  if (robFrags2.size() > 0) {
118  ATH_CHECK( m_tool2->convert(nm, robFrags2, collection.get()) );
119  }
120 
121  pObj = SG::asStorable(std::move(collection));
122 
123  return StatusCode::SUCCESS;
124 }
125 
126 } // end namespace