| The Gaudi Framework v32r1 (f65d50dc)

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