| The Gaudi Framework v32r1 (f65d50dc)

NTupleImplementation.cpp
Go to the documentation of this file.
1 //====================================================================
2 // NTuple class implementation
3 //--------------------------------------------------------------------
4 //
5 // Package : Gaudi/NTupleSvc ( The LHCb Offline System)
6 // Author : M.Frank
7 //
8 // +---------+----------------------------------------------+--------+
9 // | Date | Comment | Who |
10 // +---------+----------------------------------------------+--------+
11 // | 21/10/99| Initial version. | MF |
12 // +---------+----------------------------------------------+--------+
13 //====================================================================
14 #define GAUDI_NTUPLEIMP_CPP 1
15
16 // Framework include files
17 #include "GaudiKernel/NTupleImplementation.h"
18 #include "GaudiKernel/IDataSelector.h"
19 #include "GaudiKernel/INTupleSvc.h"
20 #include "GaudiKernel/ISelectStatement.h"
21
22 /*
23 */
24 namespace NTuple {
26 TupleImp::TupleImp( std::string title ) : m_title( std::move( title ) ) {}
27
29 TupleImp::~TupleImp() {
30 for ( auto& i : m_items ) i->release();
31 }
32
34 StatusCode TupleImp::attachSelector( ISelectStatement* sel ) {
35 m_pSelector = sel;
36 return StatusCode::SUCCESS;
37 }
38
40 ISelectStatement* TupleImp::selector() { return m_pSelector.get(); }
41
43 void TupleImp::reset() {
44 for ( auto& i : m_items ) i->reset();
45 }
46
48 INTupleItem* TupleImp::i_find( const std::string& name ) const {
49 auto i = std::find_if( std::begin( m_items ), std::end( m_items ),
50 [&]( ItemContainer::const_reference j ) { return j->name() == name; } );
51 return i != std::end( m_items ) ? const_cast<INTupleItem*>( *i ) : nullptr;
52 }
53
55 StatusCode TupleImp::add( INTupleItem* item ) {
56 if ( item ) {
57 INTupleItem* i = i_find( item->name() );
58 if ( !i ) {
59 m_items.push_back( item );
60 return StatusCode::SUCCESS;
61 }
62 }
63 return StatusCode::FAILURE;
64 }
65
67 StatusCode TupleImp::remove( const std::string& name ) {
68 INTupleItem* i = i_find( name );
69 return i ? remove( i ) : StatusCode::FAILURE;
70 }
71
73 StatusCode TupleImp::remove( INTupleItem* item ) {
74 auto i = std::find( std::begin( m_items ), std::end( m_items ), item );
75 if ( i == std::end( m_items ) ) return StatusCode::FAILURE;
76 m_items.erase( i );
77 item->release();
78 return StatusCode::SUCCESS;
79 }
81 char* TupleImp::setBuffer( std::unique_ptr<char[]>&& buff ) {
82 m_buffer = std::move( buff );
83 return m_buffer.get();
84 }
86 char* TupleImp::setBuffer( char* buff ) {
87 m_buffer.reset( buff );
88 return m_buffer.get();
89 }
91 StatusCode TupleImp::write() { return m_ntupleSvc->writeRecord( this ); }
93 StatusCode TupleImp::writeRecord() { return m_ntupleSvc->writeRecord( this ); }
95 StatusCode TupleImp::read() { return m_ntupleSvc->readRecord( this ); }
97 StatusCode TupleImp::readRecord() { return m_ntupleSvc->readRecord( this ); }
99 StatusCode TupleImp::save() { return m_ntupleSvc->save( this ); }
100 } // end namespace NTuple
IDataSelector.h
NTuple::TupleImp::reset
void reset() override
Reset all entries to their default values.
Definition: NTupleImplementation.cpp:43
NTuple::TupleImp::i_find
INTupleItem * i_find(const std::string &name) const override
Internally used by abstract classes.
Definition: NTupleImplementation.cpp:48
NTupleImplementation.h
NTuple::TupleImp::TupleImp
TupleImp(const TupleImp &)=delete
Standard Copy Constructor.
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
ISelectStatement
A select statement can either contain.
Definition: ISelectStatement.h:32
NTuple::TupleImp::m_buffer
std::unique_ptr< char[]> m_buffer
Buffer.
Definition: NTupleImplementation.h:27
NTuple::TupleImp::add
StatusCode add(INTupleItem *item) override
Add an item row to the N tuple.
Definition: NTupleImplementation.cpp:55
NTuple::TupleImp::attachSelector
StatusCode attachSelector(ISelectStatement *sel) override
Attach selector.
Definition: NTupleImplementation.cpp:34
NTuple::TupleImp::selector
ISelectStatement * selector() override
Access selector.
Definition: NTupleImplementation.cpp:40
IOTest.sel
sel
Definition: IOTest.py:93
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
ISelectStatement.h
std
STL namespace.
std::end
T end(T... args)
NTuple::TupleImp::write
StatusCode write() override
Write record of the NTuple (Shortcut of writeRecord)
Definition: NTupleImplementation.cpp:91
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
NTuple
NTuple name space.
Definition: INTupleSvc.h:9
NTuple::TupleImp::save
StatusCode save() override
Save the NTuple.
Definition: NTupleImplementation.cpp:99
std::string
STL class.
NTuple::TupleImp::m_ntupleSvc
INTupleSvc * m_ntupleSvc
Reference to N-tuple service used.
Definition: NTupleImplementation.h:29
std::vector::push_back
T push_back(T... args)
NTuple::TupleImp::read
StatusCode read() override
Read record of the NTuple (Shortcut of readRecord)
Definition: NTupleImplementation.cpp:95
INTupleItem
NTuple interface class definition.
Definition: INTuple.h:27
NTuple::TupleImp::~TupleImp
~TupleImp() override
Standard Destructor.
Definition: NTupleImplementation.cpp:29
NTuple::TupleImp::remove
StatusCode remove(INTupleItem *item) override
Remove an item row (identified by pointer) from the N tuple.
Definition: NTupleImplementation.cpp:73
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
INTupleSvc::writeRecord
virtual StatusCode writeRecord(NTuple::Tuple *tuple)=0
Write single record to N tuple.
std::vector::erase
T erase(T... args)
INTupleSvc::save
virtual StatusCode save(const std::string &fullPath)=0
Save N tuple to disk.
std::unique_ptr::reset
T reset(T... args)
std::move
T move(T... args)
NTuple::TupleImp::readRecord
StatusCode readRecord() override
Read record of the NTuple.
Definition: NTupleImplementation.cpp:97
DataObject::name
const std::string & name() const
Retreive DataObject name. It is the name when registered in the store.
Definition: DataObject.cpp:62
std::unique_ptr::get
T get(T... args)
std::find_if
T find_if(T... args)
std::unique_ptr
STL class.
NTuple::TupleImp::m_pSelector
SmartIF< ISelectStatement > m_pSelector
Possibly hanging selector.
Definition: NTupleImplementation.h:25
std::begin
T begin(T... args)
NTuple::TupleImp::m_items
ItemContainer m_items
Container with N tuple _Columns.
Definition: NTupleImplementation.h:19
INTupleSvc::readRecord
virtual StatusCode readRecord(NTuple::Tuple *tuple)=0
Read single record from N tuple.
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
NTuple::TupleImp::setBuffer
virtual char * setBuffer(std::unique_ptr< char[]> &&buff)
Set N tuple data buffer.
Definition: NTupleImplementation.cpp:81
NTuple::Tuple::item
StatusCode item(const std::string &name, Item< TYPE > &result)
Locate a scalar Item of data to the N tuple type safe.
Definition: NTuple.h:459
NTuple::TupleImp::writeRecord
StatusCode writeRecord() override
Write record of the NTuple.
Definition: NTupleImplementation.cpp:93
INTupleSvc.h