The Gaudi Framework  master (37c0b60a)
EvtCollectionStream.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ====================================================================
12 // EvtCollectionStream.cpp
13 // --------------------------------------------------------------------
14 //
15 // Package : GaudiSvc/PersistencySvc
16 //
17 // Author : Markus Frank
18 //
19 // ====================================================================
20 #define GAUDISVC_PERSISTENCYSVC_EVTCOLLECTIONSTREAM_CPP
21 
22 // Framework include files
24 #include <GaudiKernel/INTupleSvc.h>
25 #include <GaudiKernel/MsgStream.h>
26 
27 #include "EvtCollectionStream.h"
29 
30 // Define the algorithm factory for the standard output data writer
32 
33 // initialize data writer
35  // Get access to the DataManagerSvc
36  m_pTupleSvc = serviceLocator()->service( m_storeName );
37  if ( !m_pTupleSvc ) {
38  fatal() << "Unable to locate IDataManagerSvc interface" << endmsg;
39  return StatusCode::FAILURE;
40  }
41  // Clear the item list
42  clearItems();
43  // Take the new item list from the properties.
44  for ( const auto& i : m_itemNames ) addItem( i );
45  info() << "Data source: " << m_storeName.value() << endmsg;
46  return StatusCode::SUCCESS;
47 }
48 
49 // terminate data writer
51  m_pTupleSvc = nullptr; // release
52  clearItems();
53  return StatusCode::SUCCESS;
54 }
55 
56 // Work entry point
59  if ( status.isSuccess() ) {
60  for ( const auto& i : m_itemList ) {
61  StatusCode iret = m_pTupleSvc->writeRecord( i->path() );
62  if ( !iret.isSuccess() ) status = iret;
63  }
64  }
65  return status;
66 }
67 
68 // Remove all items from the output streamer list;
70 
71 // Add item to output streamer list
72 void EvtCollectionStream::addItem( const std::string& descriptor ) {
73  auto sep = descriptor.rfind( "#" );
74  int level = 0;
75  std::string obj_path = descriptor.substr( 0, sep );
76  if ( sep != std::string::npos ) {
77  std::string slevel = descriptor.substr( sep + 1 );
78  if ( slevel == "*" ) {
79  level = 9999999;
80  } else {
81  level = std::stoi( slevel );
82  }
83  }
84  m_itemList.emplace_back( new DataStoreItem( obj_path, level ) );
85  const auto& item = m_itemList.back();
86  info() << "Adding OutputStream item " << item->path() << " with " << item->depth() << " level(s)." << endmsg;
87 }
std::string
STL class.
DataStoreItem.h
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
EvtCollectionStream::execute
StatusCode execute() override
Working entry point.
Definition: EvtCollectionStream.cpp:57
std::vector::back
T back(T... args)
EvtCollectionStream::m_itemList
std::vector< std::unique_ptr< DataStoreItem > > m_itemList
Vector of items to be saved to this stream.
Definition: EvtCollectionStream.h:44
IDataProviderSvc.h
std::vector::clear
T clear(T... args)
EvtCollectionStream.h
EvtCollectionStream::clearItems
void clearItems()
Clear item list.
Definition: EvtCollectionStream.cpp:69
EvtCollectionStream
A small to stream Data I/O.
Definition: EvtCollectionStream.h:35
std::stoi
T stoi(T... args)
StatusCode
Definition: StatusCode.h:65
DataStoreItem
Definition: DataStoreItem.h:27
EvtCollectionStream::finalize
StatusCode finalize() override
Terminate EvtCollectionStream.
Definition: EvtCollectionStream.cpp:50
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
gaudirun.level
level
Definition: gaudirun.py:364
std::string::substr
T substr(T... args)
std::vector::emplace_back
T emplace_back(T... args)
EvtCollectionStream::m_pTupleSvc
SmartIF< INTupleSvc > m_pTupleSvc
Reference to Tuple service for event collection (may or may not be NTuple service)
Definition: EvtCollectionStream.h:42
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Algorithm::service
StatusCode service(std::string_view name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Algorithm.h:206
DataStoreItem::path
const std::string & path() const
Accessor: Retrieve load path.
Definition: DataStoreItem.h:66
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
EvtCollectionStream::addItem
void addItem(const std::string &descriptor)
Add item to output streamer list.
Definition: EvtCollectionStream.cpp:72
std::string::rfind
T rfind(T... args)
INTupleSvc.h
MsgStream.h