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_addrColumn(0),
20  m_isTopLeaf(false), m_collectionSvc(0)
21 {
22  declareProperty("AddressLeaf", m_addrLeaf = "/Event" );
23  declareProperty("AddressColumn", m_addrColName = "Address");
24  declareProperty("TagCollectionSvc", m_collSvcName = "NTupleSvc");
25  declareProperty("ObjectsFirst", m_objectsFirst = true);
26  declareProperty("Collection", m_tagName );
27  m_addr = new GenericAddress();
28 }
29 
30 // Standard Destructor
32  delete m_addr;
33 }
34 
35 // Connect address column, if not already connected
37  MsgStream log(msgSvc(), name());
39  if ( nt ) {
41  if ( 0 == m_addrColumn ) {
42  StatusCode sc = nt->addItem (m_addrColName,m_item);
43  if ( sc.isSuccess() ) {
44  m_addrColumn = m_item.operator->();
45  return sc;
46  }
47  log << MSG::ERROR << "Failed to add the address column:"
48  << m_addrColName << " to the tag collection " << m_tagName
49  << endmsg;
50  return sc;
51  }
52  return StatusCode::SUCCESS;
53  }
54  log << MSG::ERROR << "Failed to connect to the tag collection "
55  << m_tagName << endmsg;
56  return StatusCode::FAILURE;
57 }
58 
59 // initialize data writer
61  using Parser = Gaudi::Utils::AttribStringParser;
62  std::string log_node, log_file, logical_name;
64  if ( sc.isSuccess() ) {
65  std::string tmp;
66  for(auto attrib: Parser(m_output)) {
67  switch( ::toupper(attrib.tag[0]) ) {
68  case 'C':
69  m_tagName = std::move(attrib.value);
70  break;
71  case 'A':
72  m_addrLeaf = std::move(attrib.value);
73  break;
74  default:
75  tmp += attrib.tag + "='" + attrib.value + "' ";
76  break;
77  }
78  }
79  m_output = std::move(tmp);
80  std::string::size_type idx = m_tagName[0]==SEPARATOR ? m_tagName.find(SEPARATOR,1) : 0;
81  log_node = m_tagName.substr(idx,m_tagName.find(SEPARATOR,idx+1));
82  log_file = log_node + " " + m_output + " SHARED='YES'";
83  }
84  m_addrColumn = 0; // reset pointer to item column
85  sc = OutputStream::initialize(); // Now initialize the base class
86  if ( sc.isSuccess() ) {
88  if ( src_mgr.isValid() ) {
90  if ( data_mgr.isValid() ) {
91  logical_name = data_mgr->rootName();
92  logical_name += SEPARATOR;
93  logical_name += log_node;
94  m_topLeafName = m_addrLeaf.substr(0,m_addrLeaf.find(SEPARATOR,m_addrLeaf[0]=='/' ? 1 : 0));
96  if ( src_mgr->isConnected(logical_name) ) {
97  return sc;
98  }
99  sc = src_mgr->connect(log_file);
100  if ( sc.isSuccess() ) {
101  return sc;
102  }
103  }
104  }
105  }
106  MsgStream log(msgSvc(), name());
107  log << MSG::ERROR << "Failed to initialize TagCollection Stream." << endmsg;
108  return StatusCode::FAILURE;
109 }
110 
111 // terminate data writer
113  MsgStream log(msgSvc(), name());
116  m_collectionSvc = 0;
117  m_addrColumn = 0;
118  return status;
119 }
120 
121 // Write tuple data
124  if ( !sc.isSuccess() ) {
125  MsgStream log(msgSvc(), name());
126  log << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
127  << "[Tuple write error]" << endmsg;
128  }
129  return sc;
130 }
131 
132 // Write data objects
135  if ( !sc.isSuccess() ) {
136  MsgStream log(msgSvc(), name());
137  log << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
138  << "[Object write error]" << endmsg;
139  }
140  return sc;
141 }
142 
143 // Write full event record
145  if ( writeTuple().isSuccess() ) {
147  }
148  return StatusCode::FAILURE;
149 }
150 
151 // Work entry point
154  if ( status.isSuccess() ) {
156  if ( status.isSuccess() ) {
157  if ( !m_addrColName.empty() ) {
159  if ( top != 0 ) {
160  IOpaqueAddress* pA = top->registry()->address();
161  if ( pA != 0 ) {
162  std::string* par = (std::string*)m_addr->par();
163  unsigned long* ipar = (unsigned long*)m_addr->ipar();
164  m_addr->setClID(pA->clID());
165  m_addr->setSvcType(pA->svcType());
166  par[0] = pA->par()[0];
167  par[1] = pA->par()[1];
168  ipar[0] = pA->ipar()[0];
169  ipar[1] = pA->ipar()[1];
171  if ( m_isTopLeaf ) {
172  return writeRecord();
173  }
174  // Handle redirection mode. Normal tag collection mode
175  // is the same like leaving this out....
177  if ( 0 != leaf ) {
178  IOpaqueAddress* redir = leaf->registry()->address();
179  if ( redir ) {
180  par[0] = redir->par()[0];
181  ipar[0] = ~0x0;
182  ipar[1] = redir->ipar()[1];
183  return writeRecord();
184  }
185  MsgStream log3(msgSvc(), name());
186  log3 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
187  << m_addrLeaf << "'s address not found." << endmsg;
188  return StatusCode::FAILURE;
189  }
190  MsgStream log2(msgSvc(), name());
191  log2 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
192  << m_addrLeaf << " not found." << endmsg;
193  return StatusCode::FAILURE;
194  }
195  MsgStream log1(msgSvc(), name());
196  log1 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
197  << m_topLeafName << "'s address not found." << endmsg;
198  return StatusCode::FAILURE;
199  }
200  MsgStream log0(msgSvc(), name());
201  log0 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
202  << m_topLeafName << " not found." << endmsg;
203  return StatusCode::FAILURE;
204  }
205  }
206  }
207  return status;
208 }
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:26
constexpr char SEPARATOR
virtual std::string rootName() const =0
Get Name of root Event.
void setSvcType(long typ)
Access : set the storage type of the class id.
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:75
virtual StatusCode writeObjects()
OutputStream override: Select the different objects and write them to file.
StatusCode writeData()
Write data objects.
STL namespace.
INTupleItem * m_addrColumn
NTuple column to hold the opaque address of the address leaf.
return false
Definition: Bootstrap.cpp:338
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:69
bool m_objectsFirst
Property: Flag to indicate that the objects should be written first.
A small to stream Data I/O.
Definition: OutputStream.h:27
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.
virtual const std::string * par() const
Retrieve string parameters.
void setClID(const CLID &clid)
Access : Set class ID of the link.
virtual const unsigned long * ipar() const
Retrieve integer parameters.
virtual const CLID & clID() const =0
Retrieve class information from link.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
virtual StatusCode finalize()
Terminate TagCollectionStream.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode writeRecord(NTuple::Tuple *tuple)=0
Write single record to N tuple.
virtual StatusCode finalize()
Terminate OutputStream.
virtual const std::string & name() const
The identifying name of the algorithm object.
Definition: Algorithm.cpp:837
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Algorithm.cpp:896
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
std::string m_collSvcName
Property: Name of the collection service.
virtual StatusCode initialize()
Initialize TagCollectionStream.
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
virtual unsigned long release()=0
Release Interface instance.
virtual ~TagCollectionStream()
Standard Destructor.
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
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:210
Opaque address interface definition.
std::string m_output
Name of the output file specification.
Definition: OutputStream.h:47
NTuple::Item< IOpaqueAddress * > m_item
Address item buffer.
virtual bool isConnected(const std::string &identifier) const =0
Check if a datasource is connected.
virtual StatusCode initialize()
Initialize OutputStream.
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
void toupper(std::string &s)
GenericAddress * m_addr
Address buffer.
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)
virtual const void * buffer() const =0
Access data buffer (CONST)