| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

TagCollectionStream.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "TagCollectionStream.h"
3 #include "GaudiKernel/AttribStringParser.h"
4 #include "GaudiKernel/GenericAddress.h"
5 #include "GaudiKernel/IDataManagerSvc.h"
6 #include "GaudiKernel/IDataSourceMgr.h"
7 #include "GaudiKernel/IRegistry.h"
8 #include "GaudiKernel/SmartDataPtr.h"
9 #include "GaudiKernel/SmartIF.h"
10
11 // Define the algorithm factory for the standard output data writer
12 DECLARE_COMPONENT( TagCollectionStream )
13
14 static const char SEPARATOR = IDataProviderSvc::SEPARATOR;
15
16 // Standard Constructor
17 TagCollectionStream::TagCollectionStream( const std::string& nam, ISvcLocator* pSvc )
18 : OutputStream( nam, pSvc ), m_addr{new GenericAddress()}
19 {
20 }
21
22 // Connect address column, if not already connected
23 StatusCode TagCollectionStream::connectAddress()
24 {
25 NTuplePtr nt( m_collectionSvc, m_tagName );
26 if ( !nt ) {
27 error() << "Failed to connect to the tag collection " << m_tagName << endmsg;
28 return StatusCode::FAILURE;
29 }
30 m_addrColumn = nt->find( m_addrColName );
31 if ( m_addrColumn ) return StatusCode::SUCCESS;
32 StatusCode sc = nt->addItem( m_addrColName, m_item );
33 if ( sc.isSuccess() ) {
34 m_addrColumn = m_item.operator->();
35 return sc;
36 }
37 error() << "Failed to add the address column:" << m_addrColName << " to the tag collection " << m_tagName << endmsg;
38 return sc;
39 }
40
41 // initialize data writer
42 StatusCode TagCollectionStream::initialize()
43 {
44 using Parser = Gaudi::Utils::AttribStringParser;
45 std::string log_node, log_file, logical_name;
46 m_collectionSvc = service( m_collSvcName, true );
47 if ( m_collectionSvc ) {
48 std::string tmp;
49 for ( auto attrib : Parser( m_output ) ) {
50 switch (::toupper( attrib.tag[0] ) ) {
51 case 'C':
52 m_tagName = std::move( attrib.value );
53 break;
54 case 'A':
55 m_addrLeaf = std::move( attrib.value );
56 break;
57 default:
58 tmp += attrib.tag + "='" + attrib.value + "' ";
59 break;
60 }
61 }
62 m_output = std::move( tmp );
63 {
64 auto& tag = m_tagName.value();
65 std::string::size_type idx = ( tag[0] == SEPARATOR ) ? tag.find( SEPARATOR, 1 ) : 0;
66 log_node = tag.substr( idx, tag.find( SEPARATOR, idx + 1 ) );
67 }
68 log_file = log_node + " " + m_output + " SHARED='YES'";
69 }
70 m_addrColumn = nullptr; // reset pointer to item column
71 auto sc = OutputStream::initialize(); // Now initialize the base class
72 if ( sc.isSuccess() ) {
73 auto src_mgr = m_collectionSvc.as<IDataSourceMgr>();
74 if ( src_mgr ) {
75 auto data_mgr = m_collectionSvc.as<IDataManagerSvc>();
76 if ( data_mgr ) {
77 logical_name = data_mgr->rootName();
78 logical_name += SEPARATOR;
79 logical_name += log_node;
80 m_topLeafName =
81 m_addrLeaf.value().substr( 0, m_addrLeaf.value().find( SEPARATOR, m_addrLeaf[0] == '/' ? 1 : 0 ) );
82 m_isTopLeaf = m_topLeafName == m_addrLeaf;
83 if ( src_mgr->isConnected( logical_name ) ) return sc;
84 sc = src_mgr->connect( log_file );
85 if ( sc.isSuccess() ) return sc;
86 }
87 }
88 }
89 error() << "Failed to initialize TagCollection Stream." << endmsg;
90 return StatusCode::FAILURE;
91 }
92
93 // terminate data writer
94 StatusCode TagCollectionStream::finalize()
95 {
96 StatusCode status = OutputStream::finalize();
97 m_collectionSvc.reset();
98 m_addrColumn = nullptr;
99 return status;
100 }
101
102 // Write tuple data
103 StatusCode TagCollectionStream::writeTuple()
104 {
105 StatusCode sc = m_collectionSvc->writeRecord( m_tagName );
106 if ( !sc.isSuccess() ) {
107 error() << "Failed to write tag collection " << m_tagName << ". "
108 << "[Tuple write error]" << endmsg;
109 }
110 return sc;
111 }
112
113 // Write data objects
114 StatusCode TagCollectionStream::writeData()
115 {
116 StatusCode sc = OutputStream::writeObjects();
117 if ( !sc.isSuccess() ) {
118 error() << "Failed to write tag collection " << m_tagName << ". "
119 << "[Object write error]" << endmsg;
120 }
121 return sc;
122 }
123
124 // Write full event record
125 StatusCode TagCollectionStream::writeRecord()
126 {
127 if ( writeTuple().isSuccess() ) {
128 return m_objectsFirst ? StatusCode::SUCCESS : writeData();
129 }
130 return StatusCode::FAILURE;
131 }
132
133 // Work entry point
134 StatusCode TagCollectionStream::writeObjects()
135 {
136 StatusCode status = !m_addrColumn ? connectAddress() : StatusCode::SUCCESS;
137 if ( status.isSuccess() ) {
138 status = m_objectsFirst ? writeData() : StatusCode::SUCCESS;
139 if ( status.isSuccess() && !m_addrColName.empty() ) {
140 SmartDataPtr<DataObject> top( eventSvc(), m_topLeafName );
141 if ( !top ) {
142 error() << "Failed to write tag collection " << m_tagName << ". " << m_topLeafName << " not found." << endmsg;
143 return StatusCode::FAILURE;
144 }
145 IOpaqueAddress* pA = top->registry()->address();
146 if ( !pA ) {
147 error() << "Failed to write tag collection " << m_tagName << ". " << m_topLeafName << "'s address not found."
148 << endmsg;
149 return StatusCode::FAILURE;
150 }
151 std::string* par = (std::string*)m_addr->par();
152 unsigned long* ipar = (unsigned long*)m_addr->ipar();
153 m_addr->setClID( pA->clID() );
154 m_addr->setSvcType( pA->svcType() );
155 par[0] = pA->par()[0];
156 par[1] = pA->par()[1];
157 ipar[0] = pA->ipar()[0];
158 ipar[1] = pA->ipar()[1];
159 *(IOpaqueAddress**)( m_addrColumn->buffer() ) = m_addr.get();
160 if ( m_isTopLeaf ) return writeRecord();
161 // Handle redirection mode. Normal tag collection mode
162 // is the same like leaving this out....
163 SmartDataPtr<DataObject> leaf( eventSvc(), m_addrLeaf );
164 if ( !leaf ) {
165 error() << "Failed to write tag collection " << m_tagName << ". " << m_addrLeaf << " not found." << endmsg;
166 return StatusCode::FAILURE;
167 }
168 IOpaqueAddress* redir = leaf->registry()->address();
169 if ( !redir ) {
170 error() << "Failed to write tag collection " << m_tagName << ". " << m_addrLeaf << "'s address not found."
171 << endmsg;
172 return StatusCode::FAILURE;
173 }
174 par[0] = redir->par()[0];
175 ipar[0] = ~0x0;
176 ipar[1] = redir->ipar()[1];
177 return writeRecord();
178 }
179 }
180 return status;
181 }
Gaudi::Utils::AttribStringParser
Parse attribute strings allowing iteration over the various attributes.
Definition: AttribStringParser.h:32
StatusCode::SUCCESS
Definition: StatusCode.h:31
SmartDataObjectPtr::find
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
Definition: SmartDataObjectPtr.h:97
TagCollectionStream::connectAddress
virtual StatusCode connectAddress()
Connect address column, if not already connected.
Definition: TagCollectionStream.cpp:23
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
OutputStream::finalize
StatusCode finalize() override
Terminate OutputStream.
Definition: OutputStream.cpp:128
TagCollectionStream::initialize
StatusCode initialize() override
Initialize TagCollectionStream.
Definition: TagCollectionStream.cpp:42
IOpaqueAddress::clID
virtual const CLID & clID() const =0
Retrieve class information from link.
TagCollectionStream::m_addr
std::unique_ptr< GenericAddress > m_addr
Address buffer.
Definition: TagCollectionStream.h:82
SEPARATOR
constexpr char SEPARATOR
Definition: RegistryEntry.cpp:40
StatusCode::FAILURE
Definition: StatusCode.h:31
Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Definition: Algorithm.cpp:798
GenericAddress::setSvcType
void setSvcType(long typ)
Access : set the storage type of the class id.
Definition: GenericAddress.h:82
TagCollectionStream::m_addrLeaf
Gaudi::Property< std::string > m_addrLeaf
Definition: TagCollectionStream.h:64
TagCollectionStream
Specialized output stream class for event tag collections, where the basic Event entry point should b...
Definition: TagCollectionStream.h:61
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
TagCollectionStream::m_objectsFirst
Gaudi::Property< bool > m_objectsFirst
Definition: TagCollectionStream.h:69
OutputStream::m_output
Gaudi::Property< std::string > m_output
Definition: OutputStream.h:51
TagCollectionStream::writeData
StatusCode writeData()
Write data objects.
Definition: TagCollectionStream.cpp:114
TagCollectionStream::m_addrColName
Gaudi::Property< std::string > m_addrColName
Definition: TagCollectionStream.h:66
std
STL namespace.
TagCollectionStream::m_addrColumn
INTupleItem * m_addrColumn
NTuple column to hold the opaque address of the address leaf.
Definition: TagCollectionStream.h:74
GenericAddress
Generic Transient Address.
Definition: GenericAddress.h:20
TagCollectionStream::m_collectionSvc
SmartIF< INTupleSvc > m_collectionSvc
Keep reference to the tuple service.
Definition: TagCollectionStream.h:80
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
TagCollectionStream::writeTuple
StatusCode writeTuple()
Write tuple data.
Definition: TagCollectionStream.cpp:103
IDataSourceMgr.h
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
TagCollectionStream::m_tagName
Gaudi::Property< std::string > m_tagName
Definition: TagCollectionStream.h:71
OutputStream
A small to stream Data I/O.
Definition: OutputStream.h:29
std::string
STL class.
OutputStream::writeObjects
virtual StatusCode writeObjects()
Select the different objects and write them to file.
Definition: OutputStream.cpp:162
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:111
TagCollectionStream::writeRecord
StatusCode writeRecord()
Write full event record.
Definition: TagCollectionStream.cpp:125
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:115
OutputStream::initialize
StatusCode initialize() override
Initialize OutputStream.
Definition: OutputStream.cpp:40
IDataManagerSvc.h
GenericAddress::setClID
void setClID(const CLID &clid)
Access : Set class ID of the link.
Definition: GenericAddress.h:78
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:435
SmartDataPtr.h
TagCollectionStream::m_collSvcName
Gaudi::Property< std::string > m_collSvcName
Definition: TagCollectionStream.h:68
IOpaqueAddress::ipar
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
TagCollectionStream::finalize
StatusCode finalize() override
Terminate TagCollectionStream.
Definition: TagCollectionStream.cpp:94
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
INTupleSvc::writeRecord
virtual StatusCode writeRecord(NTuple::Tuple *tuple)=0
Write single record to N tuple.
GenericAddress::ipar
const unsigned long * ipar() const override
Retrieve integer parameters.
Definition: GenericAddress.h:86
GenericAddress::par
const std::string * par() const override
Retrieve string parameters.
Definition: GenericAddress.h:84
SmartIF.h
IRegistry.h
IOpaqueAddress::svcType
virtual long svcType() const =0
Retrieve service type.
std::move
T move(T...args)
INTupleItem::buffer
virtual const void * buffer() const =0
Access data buffer (CONST)
std::unique_ptr::get
T get(T...args)
HiveAlgSequencer.top
top
Definition: HiveAlgSequencer.py:29
TagCollectionStream.h
IDataManagerSvc
Definition: IDataManagerSvc.h:45
AttribStringParser.h
SmartDataPtr
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:47
IDataSourceMgr
IDataSourceMgr interface definition.
Definition: IDataSourceMgr.h:14
std::string::substr
T substr(T...args)
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
Algorithm::service
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Algorithm.h:231
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
TagCollectionStream::m_item
NTuple::Item< IOpaqueAddress * > m_item
Address item buffer.
Definition: TagCollectionStream.h:84
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
GenericAddress.h
toupper
void toupper(std::string &s)
Definition: StatusCodeSvc.cpp:10
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
TagCollectionStream::m_isTopLeaf
bool m_isTopLeaf
Short cut flag to indicate if the address leaf is the top leaf (performace cache) ...
Definition: TagCollectionStream.h:78
TagCollectionStream::m_topLeafName
std::string m_topLeafName
Name of the top leaf (performance cache)
Definition: TagCollectionStream.h:76
TagCollectionStream::writeObjects
StatusCode writeObjects() override
OutputStream override: Select the different objects and write them to file.
Definition: TagCollectionStream.cpp:134