The Gaudi Framework  v33r1 (b1225454)
EvtCollectionStream.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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  // Use the Job options service to set the Algorithm's parameters
36  if ( auto sc = setProperties(); !sc ) return sc;
37 
38  // Get access to the DataManagerSvc
39  m_pTupleSvc = serviceLocator()->service( m_storeName );
40  if ( !m_pTupleSvc ) {
41  fatal() << "Unable to locate IDataManagerSvc interface" << endmsg;
42  return StatusCode::FAILURE;
43  }
44  // Clear the item list
45  clearItems();
46  // Take the new item list from the properties.
47  for ( const auto& i : m_itemNames ) addItem( i );
48  info() << "Data source: " << m_storeName.value() << endmsg;
49  return StatusCode::SUCCESS;
50 }
51 
52 // terminate data writer
54  m_pTupleSvc = nullptr; // release
55  clearItems();
56  return StatusCode::SUCCESS;
57 }
58 
59 // Work entry point
62  if ( status.isSuccess() ) {
63  for ( const auto& i : m_itemList ) {
64  StatusCode iret = m_pTupleSvc->writeRecord( i->path() );
65  if ( !iret.isSuccess() ) status = iret;
66  }
67  }
68  return status;
69 }
70 
71 // Remove all items from the output streamer list;
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  } else {
84  level = std::stoi( slevel );
85  }
86  }
87  m_itemList.emplace_back( new DataStoreItem( obj_path, level ) );
88  const auto& item = m_itemList.back();
89  info() << "Adding OutputStream item " << item->path() << " with " << item->depth() << " level(s)." << endmsg;
90 }
SmartIF< INTupleSvc > m_pTupleSvc
Reference to Tuple service for event collection (may or may not be NTuple service)
T rfind(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Description of the DataStoreItem class.
Definition: DataStoreItem.h:27
STL class.
#define DECLARE_COMPONENT(type)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
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
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)
bool isSuccess() const
Definition: StatusCode.h:365
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)
constexpr static const auto FAILURE
Definition: StatusCode.h:101
T substr(T... args)
StatusCode execute() override
Working entry point.
A small to stream Data I/O.
T stoi(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
T emplace_back(T... args)