| The Gaudi Framework v27r1

- 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 declareProperty("AddressLeaf", m_addrLeaf = "/Event" );
21 declareProperty("AddressColumn", m_addrColName = "Address");
22 declareProperty("TagCollectionSvc", m_collSvcName = "NTupleSvc");
23 declareProperty("ObjectsFirst", m_objectsFirst = true);
24 declareProperty("Collection", m_tagName );
25 }
26
27
28 // Connect address column, if not already connected
29 StatusCode TagCollectionStream::connectAddress() {
30 NTuplePtr nt(m_collectionSvc, m_tagName);
31 if ( !nt ) {
32 error() << "Failed to connect to the tag collection "
33 << m_tagName << endmsg;
34 return StatusCode::FAILURE;
35 }
36 m_addrColumn = nt->find(m_addrColName);
37 if ( m_addrColumn ) return StatusCode::SUCCESS;
38 StatusCode sc = nt->addItem (m_addrColName,m_item);
39 if ( sc.isSuccess() ) {
40 m_addrColumn = m_item.operator->();
41 return sc;
42 }
43 error() << "Failed to add the address column:"
44 << m_addrColName << " to the tag collection " << m_tagName
45 << endmsg;
46 return sc;
47 }
48
49 // initialize data writer
50 StatusCode TagCollectionStream::initialize() {
51 using Parser = Gaudi::Utils::AttribStringParser;
52 std::string log_node, log_file, logical_name;
53 m_collectionSvc = service(m_collSvcName, true);
54 if ( m_collectionSvc ) {
55 std::string tmp;
56 for(auto attrib: Parser(m_output)) {
57 switch( ::toupper(attrib.tag[0]) ) {
58 case 'C':
59 m_tagName = std::move(attrib.value);
60 break;
61 case 'A':
62 m_addrLeaf = std::move(attrib.value);
63 break;
64 default:
65 tmp += attrib.tag + "='" + attrib.value + "' ";
66 break;
67 }
68 }
69 m_output = std::move(tmp);
70 std::string::size_type idx = m_tagName[0]==SEPARATOR ? m_tagName.find(SEPARATOR,1) : 0;
71 log_node = m_tagName.substr(idx,m_tagName.find(SEPARATOR,idx+1));
72 log_file = log_node + " " + m_output + " SHARED='YES'";
73 }
74 m_addrColumn = nullptr; // reset pointer to item column
75 auto sc = OutputStream::initialize(); // Now initialize the base class
76 if ( sc.isSuccess() ) {
77 auto src_mgr = m_collectionSvc.as<IDataSourceMgr>();
78 if ( src_mgr ) {
79 auto data_mgr = m_collectionSvc.as<IDataManagerSvc>();
80 if ( data_mgr ) {
81 logical_name = data_mgr->rootName();
82 logical_name += SEPARATOR;
83 logical_name += log_node;
84 m_topLeafName = m_addrLeaf.substr(0,m_addrLeaf.find(SEPARATOR,m_addrLeaf[0]=='/' ? 1 : 0));
85 m_isTopLeaf = m_topLeafName == m_addrLeaf;
86 if ( src_mgr->isConnected(logical_name) ) return sc;
87 sc = src_mgr->connect(log_file);
88 if ( sc.isSuccess() ) return sc;
89 }
90 }
91 }
92 error() << "Failed to initialize TagCollection Stream." << endmsg;
93 return StatusCode::FAILURE;
94 }
95
96 // terminate data writer
97 StatusCode TagCollectionStream::finalize() {
98 StatusCode status = OutputStream::finalize();
99 m_collectionSvc.reset();
100 m_addrColumn = nullptr;
101 return status;
102 }
103
104 // Write tuple data
105 StatusCode TagCollectionStream::writeTuple() {
106 StatusCode sc = m_collectionSvc->writeRecord(m_tagName);
107 if ( !sc.isSuccess() ) {
108 error() << "Failed to write tag collection " << m_tagName << ". "
109 << "[Tuple write error]" << endmsg;
110 }
111 return sc;
112 }
113
114 // Write data objects
115 StatusCode TagCollectionStream::writeData() {
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 if ( writeTuple().isSuccess() ) {
127 return m_objectsFirst ? StatusCode::SUCCESS : writeData();
128 }
129 return StatusCode::FAILURE;
130 }
131
132 // Work entry point
133 StatusCode TagCollectionStream::writeObjects() {
134 StatusCode status = !m_addrColumn ? connectAddress() : StatusCode::SUCCESS;
135 if ( status.isSuccess() ) {
136 status = m_objectsFirst ? writeData() : StatusCode::SUCCESS;
137 if ( status.isSuccess() && !m_addrColName.empty() ) {
138 SmartDataPtr<DataObject> top(eventSvc(), m_topLeafName);
139 if ( !top ) {
140 error() << "Failed to write tag collection " << m_tagName << ". "
141 << 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 << ". "
147 << m_topLeafName << "'s address not found." << endmsg;
148 return StatusCode::FAILURE;
149 }
150 std::string* par = (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....
162 SmartDataPtr<DataObject> leaf(eventSvc(), m_addrLeaf);
163 if ( !leaf ) {
164 error() << "Failed to write tag collection " << m_tagName << ". "
165 << 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 << ". "
171 << m_addrLeaf << "'s address not found." << 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 }
TagCollectionStream::m_addrColName
std::string m_addrColName
Property: Name of the address column of the tag collection.
Definition: TagCollectionStream.h:68
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.
TagCollectionStream::m_tagName
std::string m_tagName
Property: Name of the tag collection in the transient store.
Definition: TagCollectionStream.h:70
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:29
std::string::empty
T empty(T...args)
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:159
TagCollectionStream::initialize
StatusCode initialize() override
Initialize TagCollectionStream.
Definition: TagCollectionStream.cpp:50
TagCollectionStream::m_addr
std::unique_ptr< GenericAddress > m_addr
Address buffer.
Definition: TagCollectionStream.h:84
SEPARATOR
constexpr char SEPARATOR
Definition: RegistryEntry.cpp:41
GenericAddress::par
const std::string * par() const override
Retrieve string parameters.
Definition: GenericAddress.h:104
GenericAddress::setSvcType
void setSvcType(long typ)
Access : set the storage type of the class id.
Definition: GenericAddress.h:100
TagCollectionStream
Specialized output stream class for event tag collections, where the basic Event entry point should b...
Definition: TagCollectionStream.h:62
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
TagCollectionStream::writeData
StatusCode writeData()
Write data objects.
Definition: TagCollectionStream.cpp:115
std
STL namespace.
TagCollectionStream::m_addrColumn
INTupleItem * m_addrColumn
NTuple column to hold the opaque address of the address leaf.
Definition: TagCollectionStream.h:76
GenericAddress
Generic Transient Address.
Definition: GenericAddress.h:20
TagCollectionStream::m_collectionSvc
SmartIF< INTupleSvc > m_collectionSvc
Keep reference to the tuple service.
Definition: TagCollectionStream.h:82
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
merge_files.sc
int sc
Definition: merge_files.py:167
IOpaqueAddress::svcType
virtual long svcType() const =0
Retrieve service type.
TagCollectionStream::writeTuple
StatusCode writeTuple()
Write tuple data.
Definition: TagCollectionStream.cpp:105
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_objectsFirst
bool m_objectsFirst
Property: Flag to indicate that the objects should be written first.
Definition: TagCollectionStream.h:74
OutputStream
A small to stream Data I/O.
Definition: OutputStream.h:29
std::string
STL class.
TagCollectionStream::m_addrLeaf
std::string m_addrLeaf
Property: Name of the address leaf in the transient event store.
Definition: TagCollectionStream.h:66
OutputStream::writeObjects
virtual StatusCode writeObjects()
Select the different objects and write them to file.
Definition: OutputStream.cpp:199
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
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:110
OutputStream::initialize
StatusCode initialize() override
Initialize OutputStream.
Definition: OutputStream.cpp:70
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:386
IDataManagerSvc.h
GenericAddress::setClID
void setClID(const CLID &clid)
Access : Set class ID of the link.
Definition: GenericAddress.h:92
SmartDataPtr.h
IOpaqueAddress::clID
virtual const CLID & clID() const =0
Retrieve class information from link.
StatusCode::FAILURE
Definition: StatusCode.h:29
TagCollectionStream::finalize
StatusCode finalize() override
Terminate TagCollectionStream.
Definition: TagCollectionStream.cpp:97
StatusCode::SUCCESS
Definition: StatusCode.h:30
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.
SmartIF.h
IRegistry.h
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
std::move
T move(T...args)
TagCollectionStream::m_collSvcName
std::string m_collSvcName
Property: Name of the collection service.
Definition: TagCollectionStream.h:72
std::unique_ptr::get
T get(T...args)
std::string::find
T find(T...args)
HiveAlgSequencer.top
tuple top
Definition: HiveAlgSequencer.py:29
Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
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)
GenericAddress::ipar
const unsigned long * ipar() const override
Retrieve integer parameters.
Definition: GenericAddress.h:108
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't already exist.
Definition: Algorithm.h:232
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
OutputStream::m_output
std::string m_output
Name of the output file specification.
Definition: OutputStream.h:49
TagCollectionStream::m_item
NTuple::Item< IOpaqueAddress * > m_item
Address item buffer.
Definition: TagCollectionStream.h:86
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: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:80
TagCollectionStream::m_topLeafName
std::string m_topLeafName
Name of the top leaf (performance cache)
Definition: TagCollectionStream.h:78
TagCollectionStream::writeObjects
StatusCode writeObjects() override
OutputStream override: Select the different objects and write them to file.
Definition: TagCollectionStream.cpp:133
INTupleItem::buffer
virtual const void * buffer() const =0
Access data buffer (CONST)