TagCollectionStream.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/SmartIF.h"
3 #include "GaudiKernel/MsgStream.h"
4 #include "GaudiKernel/IRegistry.h"
5 #include "GaudiKernel/AttribStringParser.h"
6 #include "GaudiKernel/SmartDataPtr.h"
7 #include "GaudiKernel/IDataSourceMgr.h"
8 #include "GaudiKernel/IDataManagerSvc.h"
9 #include "GaudiKernel/GenericAddress.h"
10 #include "TagCollectionStream.h"
11 
12 // Define the algorithm factory for the standard output data writer
14 
15 static const char SEPARATOR = IDataProviderSvc::SEPARATOR;
16 
17 // Standard Constructor
19  : OutputStream(nam, pSvc), m_addr{ new GenericAddress() }
20 {
21  declareProperty("AddressLeaf", m_addrLeaf = "/Event" );
22  declareProperty("AddressColumn", m_addrColName = "Address");
23  declareProperty("TagCollectionSvc", m_collSvcName = "NTupleSvc");
24  declareProperty("ObjectsFirst", m_objectsFirst = true);
25  declareProperty("Collection", m_tagName );
26 }
27 
28 
29 // Connect address column, if not already connected
31  MsgStream log(msgSvc(), name());
33  if ( nt ) {
35  if ( 0 == m_addrColumn ) {
36  StatusCode sc = nt->addItem (m_addrColName,m_item);
37  if ( sc.isSuccess() ) {
38  m_addrColumn = m_item.operator->();
39  return sc;
40  }
41  log << MSG::ERROR << "Failed to add the address column:"
42  << m_addrColName << " to the tag collection " << m_tagName
43  << endmsg;
44  return sc;
45  }
46  return StatusCode::SUCCESS;
47  }
48  log << MSG::ERROR << "Failed to connect to the tag collection "
49  << m_tagName << endmsg;
50  return StatusCode::FAILURE;
51 }
52 
53 // initialize data writer
55  using Parser = Gaudi::Utils::AttribStringParser;
56  std::string log_node, log_file, logical_name;
58  if ( sc.isSuccess() ) {
59  std::string tmp;
60  for(auto attrib: Parser(m_output)) {
61  switch( ::toupper(attrib.tag[0]) ) {
62  case 'C':
63  m_tagName = std::move(attrib.value);
64  break;
65  case 'A':
66  m_addrLeaf = std::move(attrib.value);
67  break;
68  default:
69  tmp += attrib.tag + "='" + attrib.value + "' ";
70  break;
71  }
72  }
73  m_output = std::move(tmp);
74  std::string::size_type idx = m_tagName[0]==SEPARATOR ? m_tagName.find(SEPARATOR,1) : 0;
75  log_node = m_tagName.substr(idx,m_tagName.find(SEPARATOR,idx+1));
76  log_file = log_node + " " + m_output + " SHARED='YES'";
77  }
78  m_addrColumn = nullptr; // reset pointer to item column
79  sc = OutputStream::initialize(); // Now initialize the base class
80  if ( sc.isSuccess() ) {
82  if ( src_mgr ) {
84  if ( data_mgr ) {
85  logical_name = data_mgr->rootName();
86  logical_name += SEPARATOR;
87  logical_name += log_node;
88  m_topLeafName = m_addrLeaf.substr(0,m_addrLeaf.find(SEPARATOR,m_addrLeaf[0]=='/' ? 1 : 0));
90  if ( src_mgr->isConnected(logical_name) ) return sc;
91  sc = src_mgr->connect(log_file);
92  if ( sc.isSuccess() ) return sc;
93  }
94  }
95  }
96  MsgStream log(msgSvc(), name());
97  log << MSG::ERROR << "Failed to initialize TagCollection Stream." << endmsg;
98  return StatusCode::FAILURE;
99 }
100 
101 // terminate data writer
103  MsgStream log(msgSvc(), name());
106  m_collectionSvc = nullptr;
107  m_addrColumn = nullptr;
108  return status;
109 }
110 
111 // Write tuple data
114  if ( !sc.isSuccess() ) {
115  MsgStream log(msgSvc(), name());
116  log << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
117  << "[Tuple write error]" << endmsg;
118  }
119  return sc;
120 }
121 
122 // Write data objects
125  if ( !sc.isSuccess() ) {
126  MsgStream log(msgSvc(), name());
127  log << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
128  << "[Object write error]" << endmsg;
129  }
130  return sc;
131 }
132 
133 // Write full event record
135  if ( writeTuple().isSuccess() ) {
137  }
138  return StatusCode::FAILURE;
139 }
140 
141 // Work entry point
144  if ( status.isSuccess() ) {
146  if ( status.isSuccess() ) {
147  if ( !m_addrColName.empty() ) {
149  if ( top != 0 ) {
150  IOpaqueAddress* pA = top->registry()->address();
151  if ( pA ) {
152  std::string* par = (std::string*)m_addr->par();
153  unsigned long* ipar = (unsigned long*)m_addr->ipar();
154  m_addr->setClID(pA->clID());
155  m_addr->setSvcType(pA->svcType());
156  par[0] = pA->par()[0];
157  par[1] = pA->par()[1];
158  ipar[0] = pA->ipar()[0];
159  ipar[1] = pA->ipar()[1];
160  *(IOpaqueAddress**)(m_addrColumn->buffer()) = m_addr.get();
161  if ( m_isTopLeaf ) return writeRecord();
162  // Handle redirection mode. Normal tag collection mode
163  // is the same like leaving this out....
165  if ( 0 != leaf ) {
166  IOpaqueAddress* redir = leaf->registry()->address();
167  if ( redir ) {
168  par[0] = redir->par()[0];
169  ipar[0] = ~0x0;
170  ipar[1] = redir->ipar()[1];
171  return writeRecord();
172  }
173  MsgStream log3(msgSvc(), name());
174  log3 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
175  << m_addrLeaf << "'s address not found." << endmsg;
176  return StatusCode::FAILURE;
177  }
178  MsgStream log2(msgSvc(), name());
179  log2 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
180  << m_addrLeaf << " not found." << endmsg;
181  return StatusCode::FAILURE;
182  }
183  MsgStream log1(msgSvc(), name());
184  log1 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
185  << m_topLeafName << "'s address not found." << endmsg;
186  return StatusCode::FAILURE;
187  }
188  MsgStream log0(msgSvc(), name());
189  log0 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
190  << m_topLeafName << " not found." << endmsg;
191  return StatusCode::FAILURE;
192  }
193  }
194  }
195  return status;
196 }
std::string m_addrColName
Property: Name of the address column of the tag collection.
virtual const std::string * par() const =0
Retrieve String parameters.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
std::string m_tagName
Property: Name of the tag collection in the transient store.
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
virtual StatusCode connectAddress()
Connect address column, if not already connected.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
StatusCode finalize() override
Terminate OutputStream.
StatusCode initialize() override
Initialize TagCollectionStream.
std::unique_ptr< GenericAddress > m_addr
Address buffer.
constexpr char SEPARATOR
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Specialized output stream class for event tag collections, where the basic Event entry point should b...
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
StatusCode writeData()
Write data objects.
STL namespace.
INTupleItem * m_addrColumn
NTuple column to hold the opaque address of the address leaf.
Generic Transient Address.
Data provider interface definition.
virtual long svcType() const =0
Retrieve service type.
StatusCode writeTuple()
Write tuple data.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
bool m_objectsFirst
Property: Flag to indicate that the objects should be written first.
A small to stream Data I/O.
Definition: OutputStream.h:29
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:792
virtual StatusCode connect(const std::string &logon, std::string &identifier)=0
Connect data source.
std::string m_addrLeaf
Property: Name of the address leaf in the transient event store.
virtual StatusCode writeObjects()
Select the different objects and write them to file.
StatusCode writeRecord()
Write full event record.
StatusCode initialize() override
Initialize OutputStream.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Algorithm.cpp:867
virtual const CLID & clID() const =0
Retrieve class information from link.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
StatusCode finalize() override
Terminate TagCollectionStream.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode writeRecord(NTuple::Tuple *tuple)=0
Write single record to N tuple.
virtual const std::string & rootName() const =0
Get Name of root Event.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
std::string m_collSvcName
Property: Name of the collection service.
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
virtual unsigned long release()=0
Release Interface instance.
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:46
INTupleSvc * m_collectionSvc
Keep reference to the tuple 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:208
Opaque address interface definition.
std::string m_output
Name of the output file specification.
Definition: OutputStream.h:49
NTuple::Item< IOpaqueAddress * > m_item
Address item buffer.
virtual bool isConnected(const std::string &identifier) const =0
Check if a datasource is connected.
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
void toupper(std::string &s)
bool m_isTopLeaf
Short cut flag to indicate if the address leaf is the top leaf (performace cache) ...
std::string m_topLeafName
Name of the top leaf (performance cache)
StatusCode writeObjects() override
OutputStream override: Select the different objects and write them to file.
virtual const void * buffer() const =0
Access data buffer (CONST)