The Gaudi Framework  v33r0 (d5ea422b)
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  setProperties();
37  // Get access to the DataManagerSvc
38  m_pTupleSvc = serviceLocator()->service( m_storeName );
39  if ( !m_pTupleSvc ) {
40  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  info() << "Data source: " << m_storeName.value() << 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 
73 // Add item to output streamer list
74 void EvtCollectionStream::addItem( const std::string& descriptor ) {
75  auto sep = descriptor.rfind( "#" );
76  int level = 0;
77  std::string obj_path = descriptor.substr( 0, sep );
78  if ( sep != std::string::npos ) {
79  std::string slevel = descriptor.substr( sep + 1 );
80  if ( slevel == "*" ) {
81  level = 9999999;
82  } else {
83  level = std::stoi( slevel );
84  }
85  }
86  m_itemList.emplace_back( new DataStoreItem( obj_path, level ) );
87  const auto& item = m_itemList.back();
88  info() << "Adding OutputStream item " << item->path() << " with " << item->depth() << " level(s)." << endmsg;
89 }
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:96
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
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:361
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:97
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)