| The Gaudi Framework v27r1

- 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/MsgStream.h"
14 #include "GaudiKernel/INTupleSvc.h"
15 #include "GaudiKernel/IDataProviderSvc.h"
16
17 #include "GaudiKernel/DataStoreItem.h"
18 #include "EvtCollectionStream.h"
19
20 // Define the algorithm factory for the standard output data writer
21 DECLARE_COMPONENT(EvtCollectionStream)
22
23 // Standard Constructor
24 EvtCollectionStream::EvtCollectionStream(const std::string& name, ISvcLocator* pSvcLocator)
25 : Algorithm(name, pSvcLocator)
26 {
27 m_storeName = "TagCollectionSvc";
28 declareProperty("ItemList", m_itemNames);
29 declareProperty("EvtDataSvc", m_storeName);
30 }
31
32 // initialize data writer
33 StatusCode EvtCollectionStream::initialize() {
34 // Use the Job options service to set the Algorithm's parameters
35 setProperties();
36 // Get access to the DataManagerSvc
37 m_pTupleSvc = serviceLocator()->service(m_storeName);
38 if( !m_pTupleSvc ) {
39 fatal() << "Unable to locate IDataManagerSvc interface" << endmsg;
40 return StatusCode::FAILURE;
41 }
42 // Clear the item list
43 clearItems();
44 // Take the new item list from the properties.
45 for(const auto& i : m_itemNames) addItem( i );
46 info() << "Data source: " << m_storeName << endmsg;
47 return StatusCode::SUCCESS;
48 }
49
50 // terminate data writer
51 StatusCode EvtCollectionStream::finalize() {
52 m_pTupleSvc = nullptr; // release
53 clearItems();
54 return StatusCode::SUCCESS;
55 }
56
57 // Work entry point
58 StatusCode EvtCollectionStream::execute() {
59 StatusCode status = (m_pTupleSvc) ? StatusCode::SUCCESS : StatusCode::FAILURE;
60 if ( status.isSuccess() ) {
61 for ( const auto& i : m_itemList) {
62 StatusCode iret = m_pTupleSvc->writeRecord(i->path());
63 if ( !iret.isSuccess() ) status = iret;
64 }
65 }
66 return status;
67 }
68
69 // Remove all items from the output streamer list;
70 void EvtCollectionStream::clearItems() {
71 m_itemList.clear();
72 }
73
74 // Add item to output streamer list
75 void EvtCollectionStream::addItem(const std::string& descriptor) {
76 auto sep = descriptor.rfind("#");
77 int level = 0;
78 std::string obj_path = descriptor.substr(0,sep);
79 if ( sep != std::string::npos ) {
80 std::string slevel = descriptor.substr(sep+1) ;
81 if ( slevel == "*" ) {
82 level = 9999999;
83 }
84 else {
85 level = std::stoi(slevel);
86 }
87 }
88 m_itemList.emplace_back( new DataStoreItem(obj_path, level) );
89 const auto& item = m_itemList.back();
90 info() << "Adding OutputStream item " << item->path()
91 << " with " << item->depth()
92 << " level(s)." << endmsg;
93 }
EvtCollectionStream::initialize
StatusCode initialize() override
Initialize EvtCollectionStream.
Definition: EvtCollectionStream.cpp:33
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
EvtCollectionStream::m_pTupleSvc
SmartIF< INTupleSvc > m_pTupleSvc
Reference to Tuple service for event collection (may or may not be NTuple service) ...
Definition: EvtCollectionStream.h:29
Algorithm::setProperties
StatusCode setProperties()
Set the algorithm's properties.
Definition: Algorithm.cpp:934
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
Algorithm::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:929
std::string::rfind
T rfind(T...args)
std
STL namespace.
DataStoreItem
Description of the DataStoreItem class.
Definition: DataStoreItem.h:17
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string
STL class.
EvtCollectionStream::m_itemNames
std::vector< std::string > m_itemNames
Vector of item names.
Definition: EvtCollectionStream.h:33
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
DataStoreItem.h
IDataProviderSvc.h
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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)
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
EvtCollectionStream::m_storeName
std::string m_storeName
Name of the service managing the data store.
Definition: EvtCollectionStream.h:31
EvtCollectionStream::clearItems
void clearItems()
Clear item list.
Definition: EvtCollectionStream.cpp:70
EvtCollectionStream::addItem
void addItem(const std::string &descriptor)
Add item to output streamer list.
Definition: EvtCollectionStream.cpp:75
EvtCollectionStream::finalize
StatusCode finalize() override
Terminate EvtCollectionStream.
Definition: EvtCollectionStream.cpp:51
std::vector::back
T back(T...args)
ana.item
tuple item
print s1,s2
Definition: ana.py:146
std::string::substr
T substr(T...args)
EvtCollectionStream::execute
StatusCode execute() override
Working entry point.
Definition: EvtCollectionStream.cpp:58
gaudirun.level
level
Definition: gaudirun.py:261
EvtCollectionStream
A small to stream Data I/O.
Definition: EvtCollectionStream.h:26
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:112
ana.i
list i
Definition: ana.py:128
std::stoi
T stoi(T...args)
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
INTupleSvc.h
std::vector::emplace_back
T emplace_back(T...args)