ATLAS Offline Software
Loading...
Searching...
No Matches
JetCollectionCnv_p3.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5*/
6
7// JetCollectionCnv_p3.cxx
8// Implementation file for class JetCollectionCnv_p3
9// Author: S.Binet<binet@cern.ch>
11
12// DataModel includes
14
15// JetEvent includes
16#include "JetEvent/Jet.h"
18
19
20// JetEventTPCnv includes
25
26// DataModelAthenaPool includes
28
29#include <sstream>
30
31// preallocate converters
32static const JetCnv_p3 jetCnv;
34
35
36void
38 JetCollection* trans,
39 MsgStream& msg ) const
40{
41 msg << MSG::DEBUG << "Loading JetCollection from persistent state..."
42 << endmsg;
43
44 // make sure to first read the JetKeyDescriptor
46 JetKeyStoreCnv.persToTrans( &pers->m_keyStore, &trans->m_keyStore, msg );
47 // link the JetKeyDescriptorInstance to the store:
48 if( trans->m_keyStore.isValid() ){
49 trans->keyDesc()->m_Stores = nullptr;
50 trans->keyDesc()->m_ConstStores = trans->m_keyStore.cptr();
51 // make sure the global instance is pointing to this jetkey store
54 }
55 else if (trans->m_keyStore.isDefault()) {
56 DataLink<JetKeyDescriptor> dl ("JetKeyMap");
57 if (dl.isValid()) {
58 trans->keyDesc()->m_Stores = nullptr;
59 trans->keyDesc()->m_ConstStores = dl.cptr();
60 // make sure the global instance is pointing to this jetkey store
63 }
64 else {
65 trans->keyDesc()->m_Stores =
67 trans->keyDesc()->m_ConstStores =
69 }
70 }
71 else {
74 }
75 msg << MSG::DEBUG << "attached JetKeyDescriptor to its instance" << endmsg;
76
77 // elements are managed by DataPool
79
80 DataPool<Jet> pool( 20 );
81 const std::size_t nJets = pers->size();
82 if ( pool.capacity() - pool.allocated() < nJets ) {
83 pool.reserve( pool.allocated() + nJets );
84 }
85
86 trans->setOrdered (static_cast<JetCollection::OrderedVar>(pers->m_ordered));
87 // the transient version does not have this data member any more,
88 // each jet knows its ROI
89 // trans->m_ROIauthor = //pers->m_roiAuthor;
90
91 msg << MSG::DEBUG << "persistant JetCollection has size " << nJets <<endmsg;
92
93 trans->reserve( nJets );
94 for ( JetCollection_p3::const_iterator
95 itr = pers->begin(),
96 itrEnd = pers->end();
97 itr != itrEnd;
98 ++itr ) {
99 Jet * jet = pool.nextElementPtr();
100 jetCnv.persToTrans( &(*itr), jet, msg );
101 trans->push_back( jet );
102
103 }
104
105 // now each jet knows its ROI
106 unsigned int RoIWord;
107 std::stringstream strm(pers->m_roiAuthor);
108 strm >> RoIWord;
109 if( strm.good() )
110 {
111 msg << MSG::DEBUG << "Note: This jet collection uses RoIWords!" << endmsg;
112 for( JetCollection::iterator itr = trans->begin(); itr != trans->end(); ++itr )
113 (*itr)->set_RoIword( RoIWord );
114 }
115
116 msg << MSG::DEBUG << "Loading JetCollection from persistent state [OK]"
117 << endmsg;
118}
119
120void
122 JetCollection_p3* pers,
123 MsgStream& msg ) const
124{
125// msg << MSG::DEBUG << "Creating persistent state of JetCollection..."
126// << endmsg;
127
128 pers->m_ordered = static_cast<short>(trans->ordered());
129 //pers->m_roiAuthor = trans->m_ROIauthor;
130
131 std::size_t size = trans->size();
132 pers->resize(size);
133
134 // convert vector entries one by one
135 JetCollection::const_iterator transItr = trans->begin();
136 JetCollection_p3::iterator persItr = pers->begin();
137 while(size) {
138 jetCnv.transToPers( *transItr, &(*persItr), msg );
139 ++persItr; ++transItr; --size;
140 }
141
142 // RS now deal with the JetKeyDescriptor
144 JetKeyStoreCnv.transToPers( &trans->m_keyStore, &pers->m_keyStore, msg );
145}
#define endmsg
This file contains the class definition for the DataLinkCnv_p1 class and DataLinkVectorCnv_p1 class.
static const JetCnv_p1 jetCnv
static const JetKeyDescriptorCnv_p1 jetkeyCnv
bool isDefault() const
Test to see if we're in the default state.
virtual void persToTrans(const PersDLink_t *pers, DLink_t *trans, MsgStream &log) const override
virtual void transToPers(const DLink_t *trans, PersDLink_t *pers, MsgStream &log) const override
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual void transToPers(const JetCollection *trans, JetCollection_p3 *pers, MsgStream &msg) const override
Method creating the persistent representation JetCollection_p1 from its transient representation JetC...
virtual void persToTrans(const JetCollection_p3 *pers, JetCollection *trans, MsgStream &msg) const override
Method creating the transient representation of JetCollection from its persistent representation JetC...
DataLink_p1 m_keyStore
std::string m_roiAuthor
JetCollection::OrderedVar ordered() const
DataLink< JetKeyDescriptor > m_keyStore
link to the JetKeyDescriptor is mandatory for persistency. Access done through the JetKeyDescriptorIn...
void setOrdered(JetCollection::OrderedVar ordered)
DataVector< Jet >::iterator iterator
void push_back(Jet *j)
JetKeyDescriptorInstance * keyDesc() const
const JetKeyDescriptor * m_ConstStores
JetKeyDescriptor * m_Stores
static JetKeyDescriptorInstance * instance()
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
pool namespace
Definition libname.h:15
MsgStream & msg
Definition testRead.cxx:32