| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

EvtCollectionStream.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // EvtCollectionStream.cpp
3 // --------------------------------------------------------------------
4 //
5 // Package : GaudiSvc/PersistencySvc
6 //
7 // Author : Markus Frank
8 //
9 // ====================================================================
10 #define GAUDISVC_PERSISTENCYSVC_EVTCOLLECTIONSTREAM_CPP
11
12 // Framework include files
13 #include "GaudiKernel/IDataProviderSvc.h"
14 #include "GaudiKernel/INTupleSvc.h"
15 #include "GaudiKernel/MsgStream.h"
16
17 #include "EvtCollectionStream.h"
18 #include "GaudiKernel/DataStoreItem.h"
19
20 // Define the algorithm factory for the standard output data writer
21 DECLARE_COMPONENT( EvtCollectionStream )
22
23 // initialize data writer
24 StatusCode EvtCollectionStream::initialize()
25 {
26 // Use the Job options service to set the Algorithm's parameters
27 setProperties();
28 // Get access to the DataManagerSvc
29 m_pTupleSvc = serviceLocator()->service( m_storeName );
30 if ( !m_pTupleSvc ) {
31 fatal() << "Unable to locate IDataManagerSvc interface" << endmsg;
32 return StatusCode::FAILURE;
33 }
34 // Clear the item list
35 clearItems();
36 // Take the new item list from the properties.
37 for ( const auto& i : m_itemNames ) addItem( i );
38 info() << "Data source: " << m_storeName.value() << endmsg;
39 return StatusCode::SUCCESS;
40 }
41
42 // terminate data writer
43 StatusCode EvtCollectionStream::finalize()
44 {
45 m_pTupleSvc = nullptr; // release
46 clearItems();
47 return StatusCode::SUCCESS;
48 }
49
50 // Work entry point
51 StatusCode EvtCollectionStream::execute()
52 {
53 StatusCode status = ( m_pTupleSvc ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
54 if ( status.isSuccess() ) {
55 for ( const auto& i : m_itemList ) {
56 StatusCode iret = m_pTupleSvc->writeRecord( i->path() );
57 if ( !iret.isSuccess() ) status = iret;
58 }
59 }
60 return status;
61 }
62
63 // Remove all items from the output streamer list;
64 void EvtCollectionStream::clearItems() { m_itemList.clear(); }
65
66 // Add item to output streamer list
67 void EvtCollectionStream::addItem( const std::string& descriptor )
68 {
69 auto sep = descriptor.rfind( "#" );
70 int level = 0;
71 std::string obj_path = descriptor.substr( 0, sep );
72 if ( sep != std::string::npos ) {
73 std::string slevel = descriptor.substr( sep + 1 );
74 if ( slevel == "*" ) {
75 level = 9999999;
76 } else {
77 level = std::stoi( slevel );
78 }
79 }
80 m_itemList.emplace_back( new DataStoreItem( obj_path, level ) );
81 const auto& item = m_itemList.back();
82 info() << "Adding OutputStream item " << item->path() << " with " << item->depth() << " level(s)." << endmsg;
83 }
StatusCode::SUCCESS
Definition: StatusCode.h:31
StatusCode::FAILURE
Definition: StatusCode.h:31
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:117
EvtCollectionStream::m_pTupleSvc
SmartIF< INTupleSvc > m_pTupleSvc
Reference to Tuple service for event collection (may or may not be NTuple service) ...
Definition: EvtCollectionStream.h:33
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
std::string::rfind
T rfind(T...args)
DataStoreItem
Description of the DataStoreItem class.
Definition: DataStoreItem.h:17
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
std::string
STL class.
DataStoreItem.h
IDataProviderSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
INTupleSvc::writeRecord
virtual StatusCode writeRecord(NTuple::Tuple *tuple)=0
Write single record to N tuple.
EvtCollectionStream::m_itemList
std::vector< std::unique_ptr< DataStoreItem > > m_itemList
Vector of items to be saved to this stream.
Definition: EvtCollectionStream.h:35
EvtCollectionStream.h
std::vector::clear
T clear(T...args)
EvtCollectionStream::clearItems
void clearItems()
Clear item list.
Definition: EvtCollectionStream.cpp:64
EvtCollectionStream::addItem
void addItem(const std::string &descriptor)
Add item to output streamer list.
Definition: EvtCollectionStream.cpp:67
EvtCollectionStream::finalize
StatusCode finalize() override
Terminate EvtCollectionStream.
Definition: EvtCollectionStream.cpp:43
std::vector::back
T back(T...args)
std::string::substr
T substr(T...args)
EvtCollectionStream::execute
StatusCode execute() override
Working entry point.
Definition: EvtCollectionStream.cpp:51
gaudirun.level
level
Definition: gaudirun.py:271
EvtCollectionStream
A small to stream Data I/O.
Definition: EvtCollectionStream.h:25
std::stoi
T stoi(T...args)
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
INTupleSvc.h
std::vector::emplace_back
T emplace_back(T...args)