| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 "GaudiKernel/SmartIF.h"
3 #include "GaudiKernel/IRegistry.h"
4 #include "GaudiKernel/AttribStringParser.h"
5 #include "GaudiKernel/SmartDataPtr.h"
6 #include "GaudiKernel/IDataSourceMgr.h"
7 #include "GaudiKernel/IDataManagerSvc.h"
8 #include "GaudiKernel/GenericAddress.h"
9 #include "TagCollectionStream.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 NTuplePtr nt(m_collectionSvc, m_tagName);
25 if ( !nt ) {
26 error() << "Failed to connect to the tag collection "
27 << 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:"
38 << m_addrColName << " to the tag collection " << m_tagName
39 << endmsg;
40 return sc;
41 }
42
43 // initialize data writer
44 StatusCode TagCollectionStream::initialize() {
45 using Parser = Gaudi::Utils::AttribStringParser;
46 std::string log_node, log_file, logical_name;
47 m_collectionSvc = service(m_collSvcName, true);
48 if ( m_collectionSvc ) {
49 std::string tmp;
50 for(auto attrib: Parser(m_output)) {
51 switch( ::toupper(attrib.tag[0]) ) {
52 case 'C':
53 m_tagName = std::move(attrib.value);
54 break;
55 case 'A':
56 m_addrLeaf = std::move(attrib.value);
57 break;
58 default:
59 tmp += attrib.tag + "='" + attrib.value + "' ";
60 break;
61 }
62 }
63 m_output = std::move(tmp);
64 {
65 auto& tag = m_tagName.value();
66 std::string::size_type idx = (tag[0] == SEPARATOR) ? tag.find(SEPARATOR,1) : 0;
67 log_node = tag.substr( idx, tag.find( SEPARATOR, idx + 1 ) );
68 }
69 log_file = log_node + " " + m_output + " SHARED='YES'";
70 }
71 m_addrColumn = nullptr; // reset pointer to item column
72 auto sc = OutputStream::initialize(); // Now initialize the base class
73 if ( sc.isSuccess() ) {
74 auto src_mgr = m_collectionSvc.as<IDataSourceMgr>();
75 if ( src_mgr ) {
76 auto data_mgr = m_collectionSvc.as<IDataManagerSvc>();
77 if ( data_mgr ) {
78 logical_name = data_mgr->rootName();
79 logical_name += SEPARATOR;
80 logical_name += log_node;
81 m_topLeafName = 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 StatusCode status = OutputStream::finalize();
96 m_collectionSvc.reset();
97 m_addrColumn = nullptr;
98 return status;
99 }
100
101 // Write tuple data
102 StatusCode TagCollectionStream::writeTuple() {
103 StatusCode sc = m_collectionSvc->writeRecord(m_tagName);
104 if ( !sc.isSuccess() ) {
105 error() << "Failed to write tag collection " << m_tagName << ". "
106 << "[Tuple write error]" << endmsg;
107 }
108 return sc;
109 }
110
111 // Write data objects
112 StatusCode TagCollectionStream::writeData() {
113 StatusCode sc = OutputStream::writeObjects();
114 if ( !sc.isSuccess() ) {
115 error() << "Failed to write tag collection " << m_tagName << ". "
116 << "[Object write error]" << endmsg;
117 }
118 return sc;
119 }
120
121 // Write full event record
122 StatusCode TagCollectionStream::writeRecord() {
123 if ( writeTuple().isSuccess() ) {
124 return m_objectsFirst ? StatusCode::SUCCESS : writeData();
125 }
126 return StatusCode::FAILURE;
127 }
128
129 // Work entry point
130 StatusCode TagCollectionStream::writeObjects() {
131 StatusCode status = !m_addrColumn ? connectAddress() : StatusCode::SUCCESS;
132 if ( status.isSuccess() ) {
133 status = m_objectsFirst ? writeData() : StatusCode::SUCCESS;
134 if ( status.isSuccess() && !m_addrColName.empty() ) {
135 SmartDataPtr<DataObject> top(eventSvc(), m_topLeafName);
136 if ( !top ) {
137 error() << "Failed to write tag collection " << m_tagName << ". "
138 << m_topLeafName << " not found." << endmsg;
139 return StatusCode::FAILURE;
140 }
141 IOpaqueAddress* pA = top->registry()->address();
142 if ( !pA ) {
143 error() << "Failed to write tag collection " << m_tagName << ". "
144 << m_topLeafName << "'s address not found." << endmsg;
145 return StatusCode::FAILURE;
146 }
147 std::string* par = (std::string*)m_addr->par();
148 unsigned long* ipar = (unsigned long*)m_addr->ipar();
149 m_addr->setClID(pA->clID());
150 m_addr->setSvcType(pA->svcType());
151 par[0] = pA->par()[0];
152 par[1] = pA->par()[1];
153 ipar[0] = pA->ipar()[0];
154 ipar[1] = pA->ipar()[1];
155 *(IOpaqueAddress**)(m_addrColumn->buffer()) = m_addr.get();
156 if ( m_isTopLeaf ) return writeRecord();
157 // Handle redirection mode. Normal tag collection mode
158 // is the same like leaving this out....
159 SmartDataPtr<DataObject> leaf(eventSvc(), m_addrLeaf);
160 if ( !leaf ) {
161 error() << "Failed to write tag collection " << m_tagName << ". "
162 << m_addrLeaf << " not found." << endmsg;
163 return StatusCode::FAILURE;
164 }
165 IOpaqueAddress* redir = leaf->registry()->address();
166 if ( !redir ) {
167 error() << "Failed to write tag collection " << m_tagName << ". "
168 << m_addrLeaf << "'s address not found." << endmsg;
169 return StatusCode::FAILURE;
170 }
171 par[0] = redir->par()[0];
172 ipar[0] = ~0x0;
173 ipar[1] = redir->ipar()[1];
174 return writeRecord();
175 }
176 }
177 return status;
178 }
Gaudi::Utils::AttribStringParser
Parse attribute strings allowing iteration over the various attributes.
Definition: AttribStringParser.h:30
StatusCode::SUCCESS
Definition: StatusCode.h:30
SmartDataObjectPtr::find
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
Definition: SmartDataObjectPtr.h:113
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:44
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:41
StatusCode::FAILURE
Definition: StatusCode.h:29
Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Definition: Algorithm.cpp:776
GenericAddress::setSvcType
void setSvcType(long typ)
Access : set the storage type of the class id.
Definition: GenericAddress.h:100
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:74
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:112
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:102
IDataSourceMgr.h
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
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:117
TagCollectionStream::writeRecord
StatusCode writeRecord()
Write full event record.
Definition: TagCollectionStream.cpp:122
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:110
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:92
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:386
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:26
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:108
GenericAddress::par
const std::string * par() const override
Retrieve string parameters.
Definition: GenericAddress.h:104
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:46
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:88
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:227
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:244
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:130