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"
16 
18 #include "EvtCollectionStream.h"
19 
20 // Define the algorithm factory for the standard output data writer
22 
23 // Standard Constructor
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
34  // Use the Job options service to set the Algorithm's parameters
35  setProperties();
36  // Get access to the DataManagerSvc
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
52  m_pTupleSvc = nullptr; // release
53  clearItems();
54  return StatusCode::SUCCESS;
55 }
56 
57 // Work entry point
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;
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 }
StatusCode initialize() override
Initialize EvtCollectionStream.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
SmartIF< INTupleSvc > m_pTupleSvc
Reference to Tuple service for event collection (may or may not be NTuple service) ...
StatusCode setProperties()
Set the algorithm's properties.
Definition: Algorithm.cpp:934
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:929
T rfind(T...args)
STL namespace.
Description of the DataStoreItem class.
Definition: DataStoreItem.h:17
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
STL class.
std::vector< std::string > m_itemNames
Vector of item names.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode writeRecord(NTuple::Tuple *tuple)=0
Write single record to N tuple.
std::vector< std::unique_ptr< DataStoreItem > > m_itemList
Vector of items to be saved to this stream.
T clear(T...args)
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
std::string m_storeName
Name of the service managing the data store.
void clearItems()
Clear item list.
void addItem(const std::string &descriptor)
Add item to output streamer list.
StatusCode finalize() override
Terminate EvtCollectionStream.
T back(T...args)
tuple item
print s1,s2
Definition: ana.py:146
T substr(T...args)
StatusCode execute() override
Working entry point.
A small to stream Data I/O.
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
list i
Definition: ana.py:128
T stoi(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
T emplace_back(T...args)