The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
TagCollectionStream.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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// Framework include files
12#include "TagCollectionStream.h"
19#include <GaudiKernel/SmartIF.h>
20
21// Define the algorithm factory for the standard output data writer
23
24static const char SEPARATOR = IDataProviderSvc::SEPARATOR;
25
26// Standard Constructor
28 : OutputStream( nam, pSvc ), m_addr{ new GenericAddress() } {}
29
30// Connect address column, if not already connected
33 if ( !nt ) {
34 error() << "Failed to connect to the tag collection " << m_tagName << endmsg;
36 }
39 StatusCode sc = nt->addItem( m_addrColName, m_item );
40 if ( sc.isSuccess() ) {
41 m_addrColumn = m_item.operator->();
42 return sc;
43 }
44 error() << "Failed to add the address column:" << m_addrColName << " to the tag collection " << m_tagName << endmsg;
45 return sc;
46}
47
48// initialize data writer
51 std::string log_node, log_file, logical_name;
53 if ( m_collectionSvc ) {
54 std::string tmp;
55 for ( auto attrib : Parser( m_output ) ) {
56 switch ( ::toupper( attrib.tag[0] ) ) {
57 case 'C':
58 m_tagName = std::move( attrib.value );
59 break;
60 case 'A':
61 m_addrLeaf = std::move( attrib.value );
62 break;
63 default:
64 tmp += attrib.tag + "='" + attrib.value + "' ";
65 break;
66 }
67 }
68 m_output = std::move( tmp );
69 {
70 auto& tag = m_tagName.value();
71 std::string::size_type idx = ( tag[0] == SEPARATOR ) ? tag.find( SEPARATOR, 1 ) : 0;
72 log_node = tag.substr( idx, tag.find( SEPARATOR, idx + 1 ) );
73 }
74 log_file = log_node + " " + m_output + " SHARED='YES'";
75 }
76 m_addrColumn = nullptr; // reset pointer to item column
77 auto sc = OutputStream::initialize(); // Now initialize the base class
78 if ( sc.isSuccess() ) {
79 auto src_mgr = m_collectionSvc.as<IDataSourceMgr>();
80 if ( src_mgr ) {
81 auto data_mgr = m_collectionSvc.as<IDataManagerSvc>();
82 if ( data_mgr ) {
83 logical_name = data_mgr->rootName();
84 logical_name += SEPARATOR;
85 logical_name += log_node;
87 m_addrLeaf.value().substr( 0, m_addrLeaf.value().find( SEPARATOR, m_addrLeaf[0] == '/' ? 1 : 0 ) );
89 if ( src_mgr->isConnected( logical_name ) ) return sc;
90 sc = src_mgr->connect( log_file );
91 if ( sc.isSuccess() ) return sc;
92 }
93 }
94 }
95 error() << "Failed to initialize TagCollection Stream." << endmsg;
97}
98
99// terminate data writer
102 m_collectionSvc.reset();
103 m_addrColumn = nullptr;
104 return status;
105}
106
107// Write tuple data
109 StatusCode sc = m_collectionSvc->writeRecord( m_tagName );
110 if ( !sc.isSuccess() ) {
111 error() << "Failed to write tag collection " << m_tagName << ". "
112 << "[Tuple write error]" << endmsg;
113 }
114 return sc;
115}
116
117// Write data objects
120 if ( !sc.isSuccess() ) {
121 error() << "Failed to write tag collection " << m_tagName << ". "
122 << "[Object write error]" << endmsg;
123 }
124 return sc;
125}
126
127// Write full event record
132
133// Work entry point
136 if ( status.isSuccess() ) {
138 if ( status.isSuccess() && !m_addrColName.empty() ) {
140 if ( !top ) {
141 error() << "Failed to write tag collection " << m_tagName << ". " << m_topLeafName << " not found." << endmsg;
142 return StatusCode::FAILURE;
143 }
144 IOpaqueAddress* pA = top->registry()->address();
145 if ( !pA ) {
146 error() << "Failed to write tag collection " << m_tagName << ". " << m_topLeafName << "'s address not found."
147 << endmsg;
148 return StatusCode::FAILURE;
149 }
150 std::string* par = const_cast<std::string*>( m_addr->par() );
151 unsigned long* ipar = (unsigned long*)m_addr->ipar();
152 m_addr->setClID( pA->clID() );
153 m_addr->setSvcType( pA->svcType() );
154 par[0] = pA->par()[0];
155 par[1] = pA->par()[1];
156 ipar[0] = pA->ipar()[0];
157 ipar[1] = pA->ipar()[1];
158 *(IOpaqueAddress**)( m_addrColumn->buffer() ) = m_addr.get();
159 if ( m_isTopLeaf ) return writeRecord();
160 // Handle redirection mode. Normal tag collection mode
161 // is the same like leaving this out....
163 if ( !leaf ) {
164 error() << "Failed to write tag collection " << m_tagName << ". " << m_addrLeaf << " not found." << endmsg;
165 return StatusCode::FAILURE;
166 }
167 IOpaqueAddress* redir = leaf->registry()->address();
168 if ( !redir ) {
169 error() << "Failed to write tag collection " << m_tagName << ". " << m_addrLeaf << "'s address not found."
170 << endmsg;
171 return StatusCode::FAILURE;
172 }
173 par[0] = redir->par()[0];
174 ipar[0] = ~0x0;
175 ipar[1] = redir->ipar()[1];
176 return writeRecord();
177 }
178 }
179 return status;
180}
void toupper(std::string &s)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
SmartDataPtr< NTuple::Tuple > NTuplePtr
Definition NTuple.h:1020
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
SmartIF< IService > service(std::string_view name, const bool createIf=true, const bool quiet=false) const
Return a pointer to the service identified by name (or "type/name").
Parse attribute strings allowing iteration over the various attributes.
Generic Transient Address.
IDataSourceMgr interface definition.
Opaque address interface definition.
virtual long svcType() const =0
Retrieve service type.
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
virtual const CLID & clID() const =0
Retrieve class information from link.
virtual const std::string * par() const =0
Retrieve String parameters.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
A small to stream Data I/O.
StatusCode finalize() override
Terminate OutputStream.
virtual StatusCode writeObjects()
Select the different objects and write them to file.
StatusCode initialize() override
Initialize OutputStream.
Gaudi::Property< std::string > m_output
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
A small class used to access easily (and efficiently) data items residing in data stores.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isSuccess() const
Definition StatusCode.h:302
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
Specialized output stream class for event tag collections, where the basic Event entry point should b...
StatusCode finalize() override
Terminate TagCollectionStream.
StatusCode writeTuple()
Write tuple data.
StatusCode writeObjects() override
OutputStream override: Select the different objects and write them to file.
StatusCode writeData()
Write data objects.
Gaudi::Property< std::string > m_addrColName
StatusCode writeRecord()
Write full event record.
Gaudi::Property< std::string > m_addrLeaf
virtual StatusCode connectAddress()
Connect address column, if not already connected.
std::unique_ptr< GenericAddress > m_addr
Address buffer.
SmartIF< INTupleSvc > m_collectionSvc
Keep reference to the tuple service.
Gaudi::Property< std::string > m_tagName
INTupleItem * m_addrColumn
NTuple column to hold the opaque address of the address leaf.
TagCollectionStream(const std::string &name, ISvcLocator *pSvcLocator)
Standard algorithm Constructor.
std::string m_topLeafName
Name of the top leaf (performance cache).
NTuple::Item< IOpaqueAddress * > m_item
Address item buffer.
Gaudi::Property< bool > m_objectsFirst
Gaudi::Property< std::string > m_collSvcName
StatusCode initialize() override
Initialize TagCollectionStream.
bool m_isTopLeaf
Short cut flag to indicate if the address leaf is the top leaf (performace cache).