ATLAS Offline Software
Loading...
Searching...
No Matches
JetCollectionCnv_p1.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5*/
6
7// JetCollectionCnv_p1.cxx
8// Implementation file for class JetCollectionCnv_p1
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
24
25#include <sstream>
26
27// preallocate converters
28static const JetCnv_p1 jetCnv;
29
30
31void
33 JetCollection* trans,
34 MsgStream& msg ) const
35{
36// msg << MSG::DEBUG << "Loading JetCollection from persistent state..."
37// << endmsg;
38
39 // elements are managed by DataPool
41
42 DataPool<Jet> pool( 20 );
43 const std::size_t nJets = pers->size();
44 if ( pool.capacity() - pool.allocated() < nJets ) {
45 pool.reserve( pool.allocated() + nJets );
46 }
47
48 trans->setOrdered (static_cast<JetCollection::OrderedVar>(pers->m_ordered));
49 // the transient version does not have this data member any more,
50 // each jet knows its ROI
51 // trans->m_ROIauthor = //pers->m_roiAuthor;
52
53 trans->reserve( nJets );
54 for ( JetCollection_p1::const_iterator
55 itr = pers->begin(),
56 itrEnd = pers->end();
57 itr != itrEnd;
58 ++itr ) {
59 Jet * jet = pool.nextElementPtr();
60 jetCnv.persToTrans( &(*itr), jet, msg );
61 trans->push_back( jet );
62 }
63
64 // now each jet knows its ROI
65 unsigned int RoIWord;
66 std::stringstream strm(pers->m_roiAuthor);
67 strm >> RoIWord;
68 if( strm.good() )
69 {
70 msg << MSG::DEBUG << "Note: This jet collection uses RoIWords!" << endmsg;
71 for( JetCollection::iterator itr = trans->begin(); itr != trans->end(); ++itr )
72 (*itr)->set_RoIword( RoIWord );
73 }
74// msg << MSG::DEBUG << "Loading JetCollection from persistent state [OK]"
75// << endmsg;
76 }
77
78void
80 JetCollection_p1* pers,
81 MsgStream& msg ) const
82{
83// msg << MSG::DEBUG << "Creating persistent state of JetCollection..."
84// << endmsg;
85
86 pers->m_ordered = static_cast<short>(trans->ordered());
87 //pers->m_roiAuthor = trans->m_ROIauthor;
88
89 std::size_t size = trans->size();
90 pers->resize(size);
91
92 // convert vector entries one by one
93 JetCollection::const_iterator transItr = trans->begin();
94 JetCollection_p1::iterator persItr = pers->begin();
95 while(size) {
96 jetCnv.transToPers( *transItr, &(*persItr), msg );
97 ++persItr; ++transItr; --size;
98 }
99
100// msg << MSG::DEBUG << "Creating persistent state of JetCollection [OK]"
101// << endmsg;
102 }
103
#define endmsg
static const JetCnv_p1 jetCnv
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_p1 *pers, MsgStream &msg) const override
Method creating the persistent representation JetCollection_p1 from its transient representation JetC...
virtual void persToTrans(const JetCollection_p1 *pers, JetCollection *trans, MsgStream &msg) const override
Method creating the transient representation of JetCollection from its persistent representation JetC...
std::string m_roiAuthor
JetCollection::OrderedVar ordered() const
void setOrdered(JetCollection::OrderedVar ordered)
DataVector< Jet >::iterator iterator
void push_back(Jet *j)
@ 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