Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EventCollectionSelector.cpp
Go to the documentation of this file.
1 // Include files
2 #include "GaudiKernel/SmartIF.h"
12 #include "GaudiKernel/NTuple.h"
14 
16 
17 #include <memory>
18 
20 
21 
27 public:
28  typedef std::list<std::string> ListName;
29 private:
32  ListName m_files;
33  std::string m_criteria;
34  ListName::const_iterator m_fileIterator;
35  std::string m_currentInput;
36 
37 public:
41  virtual ~EventCollectionContext();
42  const std::string& currentInput() const {
43  return m_currentInput;
44  }
45  void setCurrentInput(const std::string& v) {
46  m_currentInput = v;
47  }
48  ListName& files() {
49  return m_files;
50  }
51  virtual void* identifier() const {
52  return (void*)m_pSelector;
53  }
54  void setCriteria(const std::string& crit) {
55  m_criteria = crit;
56  }
57  ListName::const_iterator fileIterator() {
58  return m_fileIterator;
59  }
60  void setFileIterator(ListName::const_iterator new_iter)
61  { m_fileIterator = new_iter; }
62 };
63 
66 }
67 
69  : m_pSelector(pSelector)
70 {
73 }
74 
75 // Standard constructor
77  : base_class(name, svcloc)
78 {
79  declareProperty("CnvService", m_tupleSvcName = "EvtTupleSvc");
80  declareProperty("Authentication",m_authentication= "");
81  declareProperty("Container", m_cntName = "B2PiPi");
82  declareProperty("Item", m_itemName = "Address");
83  declareProperty("Criteria", m_criteria = "");
84  declareProperty("DB", m_database = "");
85  declareProperty("DbType", m_dbType = "");
86  declareProperty("DbService", m_dbSvc = "");
87  declareProperty("Function", m_statement= "NTuple::Selector");
88 }
89 
91 }
92 
93 // IService implementation: Db event selector override
95  // Initialize base class
97  MsgStream log(msgSvc(), name());
98  if ( !status.isSuccess() ) {
99  log << MSG::ERROR << "Error initializing base class Service!" << endmsg;
100  return status;
101  }
102  m_pAddrCreator = serviceLocator()->service("EventPersistencySvc");
103  if(!m_pAddrCreator.isValid()) {
104  log << MSG::ERROR << "Unable to locate IAddressCreator interface of " << "EventPersistencySvc" << endmsg;
105  return status;
106  }
108  if( !m_tupleSvc.isValid() ) {
109  log << MSG::ERROR << "Unable to locate INTupleSvc interface of " << m_tupleSvcName << endmsg;
110  return status;
111  }
112  return status;
113 }
114 
115 // Connect collection to selector
117 EventCollectionSelector::connectDataSource(const std::string& db, const std::string& /* typ */ ) const {
120  if ( svc.isValid( ) && db.length() > 0 ) {
121  std::string ident = name() + ' ';
122  ident += "DATAFILE='" + m_database.substr(5,m_database.length()) + "' ";
123  if ( !m_dbSvc.empty() )
124  ident += "SVC='" + m_dbSvc + "' ";
125  else
126  ident += "TYP='" + m_dbType + "' ";
127  ident += "OPT='READ' ";
128  if ( m_authentication.length() > 0 ) {
129  ident += "AUTH='" + m_authentication + "' ";
130  }
131  status = svc->connect(ident);
132  }
133  return status;
134 }
135 
138 EventCollectionSelector::connectTuple(const std::string& nam, const std::string& itName, NTuple::Tuple*& tup, NTuple::Item<IOpaqueAddress*>*& item) const {
139  std::string top = "/NTUPLES/" + name() + '/' + nam;
140  StatusCode status = m_tupleSvc->retrieveObject(top, (DataObject*&)tup);
141  if ( status.isSuccess() ) {
142  item = new NTuple::Item<IOpaqueAddress*>();
143  status = tup->item(itName, *item);
144  if ( status.isSuccess() ) {
145  return status;
146  }
147  else {
148  MsgStream log(msgSvc(), name());
149  log << MSG::ERROR << "Item " << itName << " is not part of the collection:" << top << endmsg;
150  }
151  delete item;
152  item = 0;
153  }
154  else {
155  MsgStream err(msgSvc(), name());
156  err << MSG::ERROR << "Cannot connect to collection:" << top << endmsg;
157  }
158  tup = 0;
159  return status;
160 }
161 
164 EventCollectionSelector::connectStatement(const std::string& typ, const std::string& crit, INTuple* tuple) const {
165  std::string seltyp = typ;
166  if ( seltyp.length() > 0 || crit.length() > 0 ) {
167  if ( crit.length() > 0 && seltyp.length() == 0 ) seltyp = "NTuple::Selector";
168  SmartIF<ISelectStatement> stmt(ObjFactory::create(seltyp, serviceLocator()));
169  if ( stmt.isValid( ) ) {
170  if ( crit.length() > 0 ) stmt->setCriteria(crit);
171  tuple->attachSelector(stmt).ignore();
172  return StatusCode::SUCCESS;
173  }
174  return StatusCode::FAILURE;
175  }
176  return StatusCode::SUCCESS;
177 }
178 
182  if ( 0 != tuple ) {
183  do {
184  status = m_tupleSvc->readRecord(tuple);
185  if ( status.isSuccess() ) {
186  ISelectStatement* statement = tuple->selector();
187  bool use_it = (statement) ? (*statement)(tuple) : true;
188  if ( use_it ) {
189  return status;
190  }
191  }
192  } while ( status.isSuccess() );
193  }
194  return status;
195 }
196 
200  if ( tuple ) {
201  IRegistry* pReg = tuple->registry();
202  if ( pReg ) {
203  IOpaqueAddress* pAddr = pReg->address();
204  if ( pAddr ) {
205  long* ip = (long*)pAddr->ipar();
206  do {
207  if ( ip[1] > 1 ) {
208  ip[1] -= 2;
209  status = m_tupleSvc->readRecord(tuple);
210  if ( status.isSuccess() ) {
211  ISelectStatement* statement = tuple->selector();
212  bool use_it = (statement) ? (*statement)(tuple) : true;
213  if ( use_it ) {
214  return status;
215  }
216  }
217  }
218  else {
219  return StatusCode::FAILURE;
220  }
221  } while ( status.isSuccess() );
222  }
223  }
224  }
225  return StatusCode::FAILURE;
226 }
227 
228 // Connect collection to selector
230 {
231  if ( ctxt ) {
233  if ( status.isSuccess() ) {
234  status = connectTuple(m_cntName, m_itemName, ctxt->tuple, ctxt->item);
235  if ( status.isSuccess() ) {
236  status = connectStatement(m_statement, m_criteria, ctxt->tuple);
237  if ( status.isSuccess() ) {
238  *(ctxt->item) = 0;
239  return status;
240  }
241  }
242  }
243  return status;
244  }
245  return StatusCode::FAILURE;
246 }
247 
248 // Finalize service
250  // release services
251  m_pAddrCreator = 0;
252  m_tupleSvc = 0;
253  return Service::finalize();
254 }
255 
259 {
260  refpCtxt = 0;
261  std::auto_ptr<MyContextType> ctxt(new MyContextType());
262  StatusCode status = connectCollection(ctxt.get());
263  if( !status.isSuccess() ) {
264  MsgStream log(msgSvc(), name());
265  log << MSG::ERROR << "Unable to connect Collection file \"" << m_database << "\"" << endmsg;
266  return status;
267  }
268  refpCtxt = ctxt.release();
269  return StatusCode::SUCCESS;
270 }
271 
275 {
276  return next(refCtxt, 1);
277 }
278 
281 EventCollectionSelector::next(Context& refCtxt,int jump) const
282 {
283  MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt);
284  if ( ctxt ) {
285  *(ctxt->item) = ctxt->addressBuffer;
287  for ( int i=0; i<jump && sc.isSuccess(); ++i ) {
288  sc = getNextRecord(ctxt->tuple);
289  }
290  return sc;
291  }
292  return StatusCode::FAILURE;
293 }
294 
298 {
299  return previous(refCtxt, 1);
300 }
301 
305 {
306  MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt);
307  if ( ctxt ) {
308  *(ctxt->item) = ctxt->addressBuffer;
310  for ( int i=0; i<jump && sc.isSuccess(); ++i ) {
311  sc = getPreviousRecord(ctxt->tuple);
312  }
313  return sc;
314  }
315  return StatusCode::FAILURE;
316 }
317 
321 {
322  return StatusCode::FAILURE;
323 }
324 
328 {
329  const MyContextType* ctxt = dynamic_cast<const MyContextType*>(&refCtxt);
330  if ( ctxt ) {
331  IOpaqueAddress* pA = *(ctxt->item);
332  if ( pA ) {
333  IOpaqueAddress* pAddress = 0;
334  StatusCode status = m_pAddrCreator->createAddress(pA->svcType(),
335  pA->clID(),
336  pA->par(),
337  pA->ipar(),
338  pAddress);
339  if ( status.isSuccess() ) {
340  refpAddr = pAddress;
341  return StatusCode::SUCCESS;
342  }
343  else {
344  MsgStream log(msgSvc(), name());
345  log << MSG::ERROR << "Failed to access " << pA->par()[0]
346  << ":" << pA->par()[1]
347  << " SvcTyp:" << long(pA->svcType())
348  << " CLID:" << pA->clID()
349  << endmsg;
350  }
351  }
352  }
353  return StatusCode::FAILURE;
354 }
355 
359 {
360  MyContextType *ctxt = dynamic_cast<MyContextType*>(refCtxt);
361  if ( ctxt ) {
362  delete ctxt;
363  ctxt = 0;
364  return StatusCode::SUCCESS;
365  }
366  return StatusCode::FAILURE;
367 }
368 
372 EventCollectionSelector::resetCriteria(const std::string& cr,Context& refCtxt) const
373 {
374  MyContextType *ctxt = dynamic_cast<MyContextType*>(&refCtxt);
375  if ( ctxt ) {
376  ctxt->criteria = cr;
377  return StatusCode::SUCCESS;
378  }
379  return StatusCode::FAILURE;
380 }
381 
385 {
386  return StatusCode::FAILURE;
387 }

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