Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EventCollectionSelector.cpp
Go to the documentation of this file.
1 //$Id: EventCollectionSelector.cpp,v 1.16 2007/01/09 16:54:47 hmd Exp $
2 
3 // Include files
4 #include "GaudiKernel/SmartIF.h"
10 #include "GaudiKernel/INTupleSvc.h"
15 #include "GaudiKernel/NTuple.h"
17 
19 
20 #include <memory>
21 
23 
24 
30 public:
32 private:
35  ListName m_files;
39 
40 public:
44  virtual ~EventCollectionContext();
45  const std::string& currentInput() const {
46  return m_currentInput;
47  }
48  void setCurrentInput(const std::string& v) {
49  m_currentInput = v;
50  }
51  ListName& files() {
52  return m_files;
53  }
54  virtual void* identifier() const {
55  return (void*)m_pSelector;
56  }
57  void setCriteria(const std::string& crit) {
58  m_criteria = crit;
59  }
61  return m_fileIterator;
62  }
63  void setFileIterator(ListName::const_iterator new_iter)
64  { m_fileIterator = new_iter; }
65 };
66 
69 }
70 
72  : m_pSelector(pSelector)
73 {
76 }
77 
78 // Standard constructor
80  : base_class(name, svcloc)
81 {
82  declareProperty("CnvService", m_tupleSvcName = "EvtTupleSvc");
83  declareProperty("Authentication",m_authentication= "");
84  declareProperty("Container", m_cntName = "B2PiPi");
85  declareProperty("Item", m_itemName = "Address");
86  declareProperty("Criteria", m_criteria = "");
87  declareProperty("DB", m_database = "");
88  declareProperty("DbType", m_dbType = "");
89  declareProperty("DbService", m_dbSvc = "");
90  declareProperty("Function", m_statement= "NTuple::Selector");
91 }
92 
94 }
95 
96 // IService implementation: Db event selector override
98  // Initialize base class
100  MsgStream log(msgSvc(), name());
101  if ( !status.isSuccess() ) {
102  log << MSG::ERROR << "Error initializing base class Service!" << endmsg;
103  return status;
104  }
105  m_pAddrCreator = serviceLocator()->service("EventPersistencySvc");
106  if(!m_pAddrCreator.isValid()) {
107  log << MSG::ERROR << "Unable to locate IAddressCreator interface of " << "EventPersistencySvc" << endmsg;
108  return status;
109  }
111  if( !m_tupleSvc.isValid() ) {
112  log << MSG::ERROR << "Unable to locate INTupleSvc interface of " << m_tupleSvcName << endmsg;
113  return status;
114  }
115  return status;
116 }
117 
118 // Connect collection to selector
123  if ( svc.isValid( ) && db.length() > 0 ) {
124  std::string ident = name() + ' ';
125  ident += "DATAFILE='" + m_database.substr(5,m_database.length()) + "' ";
126  if ( !m_dbSvc.empty() )
127  ident += "SVC='" + m_dbSvc + "' ";
128  else
129  ident += "TYP='" + m_dbType + "' ";
130  ident += "OPT='READ' ";
131  if ( m_authentication.length() > 0 ) {
132  ident += "AUTH='" + m_authentication + "' ";
133  }
134  status = svc->connect(ident);
135  }
136  return status;
137 }
138 
142  std::string top = "/NTUPLES/" + name() + '/' + nam;
143  StatusCode status = m_tupleSvc->retrieveObject(top, (DataObject*&)tup);
144  if ( status.isSuccess() ) {
145  item = new NTuple::Item<IOpaqueAddress*>();
146  status = tup->item(itName, *item);
147  if ( status.isSuccess() ) {
148  return status;
149  }
150  else {
151  MsgStream log(msgSvc(), name());
152  log << MSG::ERROR << "Item " << itName << " is not part of the collection:" << top << endmsg;
153  }
154  delete item;
155  item = 0;
156  }
157  else {
158  MsgStream err(msgSvc(), name());
159  err << MSG::ERROR << "Cannot connect to collection:" << top << endmsg;
160  }
161  tup = 0;
162  return status;
163 }
164 
168  std::string seltyp = typ;
169  if ( seltyp.length() > 0 || crit.length() > 0 ) {
170  if ( crit.length() > 0 && seltyp.length() == 0 ) seltyp = "NTuple::Selector";
171  SmartIF<ISelectStatement> stmt(ROOT::Reflex::PluginService::Create<IInterface*>(seltyp, (IInterface*)serviceLocator()));
172  if ( stmt.isValid( ) ) {
173  if ( crit.length() > 0 ) stmt->setCriteria(crit);
174  tuple->attachSelector(stmt).ignore();
175  return StatusCode::SUCCESS;
176  }
177  return StatusCode::FAILURE;
178  }
179  return StatusCode::SUCCESS;
180 }
181 
185  if ( 0 != tuple ) {
186  do {
187  status = m_tupleSvc->readRecord(tuple);
188  if ( status.isSuccess() ) {
189  ISelectStatement* statement = tuple->selector();
190  bool use_it = (statement) ? (*statement)(tuple) : true;
191  if ( use_it ) {
192  return status;
193  }
194  }
195  } while ( status.isSuccess() );
196  }
197  return status;
198 }
199 
203  if ( tuple ) {
204  IRegistry* pReg = tuple->registry();
205  if ( pReg ) {
206  IOpaqueAddress* pAddr = pReg->address();
207  if ( pAddr ) {
208  long* ip = (long*)pAddr->ipar();
209  do {
210  if ( ip[1] > 1 ) {
211  ip[1] -= 2;
212  status = m_tupleSvc->readRecord(tuple);
213  if ( status.isSuccess() ) {
214  ISelectStatement* statement = tuple->selector();
215  bool use_it = (statement) ? (*statement)(tuple) : true;
216  if ( use_it ) {
217  return status;
218  }
219  }
220  }
221  else {
222  return StatusCode::FAILURE;
223  }
224  } while ( status.isSuccess() );
225  }
226  }
227  }
228  return StatusCode::FAILURE;
229 }
230 
231 // Connect collection to selector
233 {
234  if ( ctxt ) {
236  if ( status.isSuccess() ) {
237  status = connectTuple(m_cntName, m_itemName, ctxt->tuple, ctxt->item);
238  if ( status.isSuccess() ) {
239  status = connectStatement(m_statement, m_criteria, ctxt->tuple);
240  if ( status.isSuccess() ) {
241  *(ctxt->item) = 0;
242  return status;
243  }
244  }
245  }
246  return status;
247  }
248  return StatusCode::FAILURE;
249 }
250 
251 // Finalize service
253  // release services
254  m_pAddrCreator = 0;
255  m_tupleSvc = 0;
256  return Service::finalize();
257 }
258 
262 {
263  refpCtxt = 0;
265  StatusCode status = connectCollection(ctxt.get());
266  if( !status.isSuccess() ) {
267  MsgStream log(msgSvc(), name());
268  log << MSG::ERROR << "Unable to connect Collection file \"" << m_database << "\"" << endmsg;
269  return status;
270  }
271  refpCtxt = ctxt.release();
272  return StatusCode::SUCCESS;
273 }
274 
278 {
279  return next(refCtxt, 1);
280 }
281 
284 EventCollectionSelector::next(Context& refCtxt,int jump) const
285 {
286  MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt);
287  if ( ctxt ) {
288  *(ctxt->item) = ctxt->addressBuffer;
290  for ( int i=0; i<jump && sc.isSuccess(); ++i ) {
291  sc = getNextRecord(ctxt->tuple);
292  }
293  return sc;
294  }
295  return StatusCode::FAILURE;
296 }
297 
301 {
302  return previous(refCtxt, 1);
303 }
304 
308 {
309  MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt);
310  if ( ctxt ) {
311  *(ctxt->item) = ctxt->addressBuffer;
313  for ( int i=0; i<jump && sc.isSuccess(); ++i ) {
314  sc = getPreviousRecord(ctxt->tuple);
315  }
316  return sc;
317  }
318  return StatusCode::FAILURE;
319 }
320 
324 {
325  return StatusCode::FAILURE;
326 }
327 
331 {
332  const MyContextType* ctxt = dynamic_cast<const MyContextType*>(&refCtxt);
333  if ( ctxt ) {
334  IOpaqueAddress* pA = *(ctxt->item);
335  if ( pA ) {
336  IOpaqueAddress* pAddress = 0;
337  StatusCode status = m_pAddrCreator->createAddress(pA->svcType(),
338  pA->clID(),
339  pA->par(),
340  pA->ipar(),
341  pAddress);
342  if ( status.isSuccess() ) {
343  refpAddr = pAddress;
344  return StatusCode::SUCCESS;
345  }
346  else {
347  MsgStream log(msgSvc(), name());
348  log << MSG::ERROR << "Failed to access " << pA->par()[0]
349  << ":" << pA->par()[1]
350  << " SvcTyp:" << long(pA->svcType())
351  << " CLID:" << pA->clID()
352  << endmsg;
353  }
354  }
355  }
356  return StatusCode::FAILURE;
357 }
358 
362 {
363  MyContextType *ctxt = dynamic_cast<MyContextType*>(refCtxt);
364  if ( ctxt ) {
365  delete ctxt;
366  ctxt = 0;
367  return StatusCode::SUCCESS;
368  }
369  return StatusCode::FAILURE;
370 }
371 
376 {
377  MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt);
378  if ( ctxt ) {
379  ctxt->criteria = cr;
380  return StatusCode::SUCCESS;
381  }
382  return StatusCode::FAILURE;
383 }
384 
388 {
389  return StatusCode::FAILURE;
390 }

Generated at Wed Jan 30 2013 17:13:38 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004