Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TagCollectionStream.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/SmartIF.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  std::string log_node, log_file, logical_name;
63  if ( sc.isSuccess() ) {
64  Tokenizer tok(true);
65  tok.analyse(m_output, " ", "", "", "=", "'", "'");
66  m_output = "";
67  for(Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); ++i) {
68  const std::string& tag = (*i).tag();
69  const std::string& val = (*i).value();
70  switch( ::toupper(tag[0]) ) {
71  case 'C':
72  m_tagName = val;
73  break;
74  case 'A':
75  m_addrLeaf = val;
76  break;
77  default:
78  m_output += tag + "='" + val + "' ";
79  break;
80  }
81  }
82  std::string::size_type idx = m_tagName[0]==SEPARATOR ? m_tagName.find(SEPARATOR,1) : 0;
83  log_node = m_tagName.substr(idx,m_tagName.find(SEPARATOR,idx+1));
84  log_file = log_node + " " + m_output + " SHARED='YES'";
85  }
86  m_addrColumn = 0; // reset pointer to item column
87  sc = OutputStream::initialize(); // Now initialize the base class
88  if ( sc.isSuccess() ) {
90  if ( src_mgr.isValid() ) {
92  if ( data_mgr.isValid() ) {
93  logical_name = data_mgr->rootName();
94  logical_name += SEPARATOR;
95  logical_name += log_node;
96  m_topLeafName = m_addrLeaf.substr(0,m_addrLeaf.find(SEPARATOR,m_addrLeaf[0]=='/' ? 1 : 0));
98  if ( src_mgr->isConnected(logical_name) ) {
99  return sc;
100  }
101  sc = src_mgr->connect(log_file);
102  if ( sc.isSuccess() ) {
103  return sc;
104  }
105  }
106  }
107  }
108  MsgStream log(msgSvc(), name());
109  log << MSG::ERROR << "Failed to initialize TagCollection Stream." << endmsg;
110  return StatusCode::FAILURE;
111 }
112 
113 // terminate data writer
115  MsgStream log(msgSvc(), name());
118  m_collectionSvc = 0;
119  m_addrColumn = 0;
120  return status;
121 }
122 
123 // Write tuple data
126  if ( !sc.isSuccess() ) {
127  MsgStream log(msgSvc(), name());
128  log << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
129  << "[Tuple write error]" << endmsg;
130  }
131  return sc;
132 }
133 
134 // Write data objects
137  if ( !sc.isSuccess() ) {
138  MsgStream log(msgSvc(), name());
139  log << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
140  << "[Object write error]" << endmsg;
141  }
142  return sc;
143 }
144 
145 // Write full event record
147  if ( writeTuple().isSuccess() ) {
149  }
150  return StatusCode::FAILURE;
151 }
152 
153 // Work entry point
156  if ( status.isSuccess() ) {
158  if ( status.isSuccess() ) {
159  if ( !m_addrColName.empty() ) {
161  if ( top != 0 ) {
162  IOpaqueAddress* pA = top->registry()->address();
163  if ( pA != 0 ) {
164  std::string* par = (std::string*)m_addr->par();
165  unsigned long* ipar = (unsigned long*)m_addr->ipar();
166  m_addr->setClID(pA->clID());
167  m_addr->setSvcType(pA->svcType());
168  par[0] = pA->par()[0];
169  par[1] = pA->par()[1];
170  ipar[0] = pA->ipar()[0];
171  ipar[1] = pA->ipar()[1];
173  if ( m_isTopLeaf ) {
174  return writeRecord();
175  }
176  // Handle redirection mode. Normal tag collection mode
177  // is the same like leaving this out....
179  if ( 0 != leaf ) {
180  IOpaqueAddress* redir = leaf->registry()->address();
181  if ( redir ) {
182  par[0] = redir->par()[0];
183  ipar[0] = ~0x0;
184  ipar[1] = redir->ipar()[1];
185  return writeRecord();
186  }
187  MsgStream log3(msgSvc(), name());
188  log3 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
189  << m_addrLeaf << "'s address not found." << endmsg;
190  return StatusCode::FAILURE;
191  }
192  MsgStream log2(msgSvc(), name());
193  log2 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
194  << m_addrLeaf << " not found." << endmsg;
195  return StatusCode::FAILURE;
196  }
197  MsgStream log1(msgSvc(), name());
198  log1 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
199  << m_topLeafName << "'s address not found." << endmsg;
200  return StatusCode::FAILURE;
201  }
202  MsgStream log0(msgSvc(), name());
203  log0 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
204  << m_topLeafName << " not found." << endmsg;
205  return StatusCode::FAILURE;
206  }
207  }
208  }
209  return status;
210 }

Generated at Wed Jun 4 2014 14:48:56 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004