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
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  MsgStream log(msgSvc(), name());
35  // Use the Job options service to set the Algorithm's parameters
36  setProperties();
37  // Get access to the DataManagerSvc
39  if( !m_pTupleSvc ) {
40  log << MSG::FATAL << "Unable to locate IDataManagerSvc interface" << endmsg;
41  return StatusCode::FAILURE;
42  }
43  // Clear the item list
44  clearItems();
45  // Take the new item list from the properties.
46  for(const auto& i : m_itemNames) addItem( i );
47  log << MSG::INFO << "Data source: " << m_storeName << endmsg;
48  return StatusCode::SUCCESS;
49 }
50 
51 // terminate data writer
53  m_pTupleSvc = nullptr; // release
54  clearItems();
55  return StatusCode::SUCCESS;
56 }
57 
58 // Work entry point
61  if ( status.isSuccess() ) {
62  for ( const auto& i : m_itemList) {
63  StatusCode iret = m_pTupleSvc->writeRecord(i->path());
64  if ( !iret.isSuccess() ) status = iret;
65  }
66  }
67  return status;
68 }
69 
70 // Remove all items from the output streamer list;
72  m_itemList.clear();
73 }
74 
75 // Add item to output streamer list
76 void EvtCollectionStream::addItem(const std::string& descriptor) {
77  MsgStream log(msgSvc(), name());
78  auto sep = descriptor.rfind("#");
79  int level = 0;
80  std::string obj_path = descriptor.substr(0,sep);
81  if ( sep != std::string::npos ) {
82  std::string slevel = descriptor.substr(sep+1) ;
83  if ( slevel == "*" ) {
84  level = 9999999;
85  }
86  else {
87  level = std::stoi(slevel);
88  }
89  }
90  m_itemList.emplace_back( new DataStoreItem(obj_path, level) );
91  const auto& item = m_itemList.back();
92  log << MSG::INFO << "Adding OutputStream item " << item->path()
93  << " with " << item->depth()
94  << " level(s)." << endmsg;
95 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
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 & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
Definition: Algorithm.cpp:1045
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:1050
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
STL namespace.
Description of the DataStoreItem class.
Definition: DataStoreItem.h:17
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:919
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.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::vector< std::unique_ptr< DataStoreItem > > m_itemList
Vector of items to be saved to this stream.
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:77
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.
tuple item
print s1,s2
Definition: ana.py:146
StatusCode execute() override
Working entry point.
A small to stream Data I/O.
list i
Definition: ana.py:128
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Algorithm.cpp:1001