All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EventSelectorDataStream.cpp
Go to the documentation of this file.
1 //====================================================================
2 // EventSelectorDataStream.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : EventSelectorDataStream (The LHCb Event Selector Package)
6 //
7 //
8 // Author : M.Frank
9 // Created : 4/10/00
10 // Changes : R. Lambert 2009-09-04
11 //
12 //====================================================================
13 #define GAUDISVC_EVENTSELECTOR_EVENTSELECTORDATASTREAM_CPP 1
14 // Include files
15 #include "GaudiKernel/Tokenizer.h"
16 #include "GaudiKernel/IService.h"
22 #include "GaudiKernel/MsgStream.h"
24 
25 
26 // Output friend
28  s << "Stream:" << obj.name() << " Def:" << obj.definition();
29  return s;
30 }
31 
32 // Output friend
33 std::ostream& operator<<(std::ostream& s, const EventSelectorDataStream& obj) {
34  s << "Stream:" << obj.name() << " Def:" << obj.definition();
35  return s;
36 }
37 
38 // Standard Constructor
39 EventSelectorDataStream::EventSelectorDataStream(const std::string& nam, const std::string& def, ISvcLocator* svcloc)
40 : m_pSelector(0),
41  m_pSvcLocator(svcloc)
42 {
43  m_name = nam;
44  m_definition = def;
45  m_initialized = false;
46  m_properties = new Properties();
47 }
48 
49 // Standard Constructor
51  setSelector(0);
52  delete m_properties;
53 }
54 
55 // Set selector
57  if ( 0 != pSelector ) pSelector->addRef();
58  if ( 0 != m_pSelector ) m_pSelector->release();
59  m_pSelector = pSelector;
60 }
61 
62 // Allow access to individual properties by name
64  for ( Properties::iterator i = m_properties->begin(); i != m_properties->end(); i++ ) {
65  if ( (*i).name() == nam ) {
66  return &(*i);
67  }
68  }
69  return 0;
70 }
71 
72 // Allow access to individual properties by name
73 const StringProperty* EventSelectorDataStream::property(const std::string& nam) const {
74  for ( Properties::const_iterator i = m_properties->begin(); i != m_properties->end(); i++ ) {
75  if ( (*i).name() == nam ) {
76  return &(*i);
77  }
78  }
79  return 0;
80 }
81 
82 // Parse input criteria
84  bool isData = true;
85  std::string auth, dbtyp, collsvc, item, crit, sel, svc, stmt;
86  std::string cnt = "/Event";
87  std::string db = "<Unknown>";
88  Tokenizer tok(true);
89 
90  SmartIF<IDataManagerSvc> eds(m_pSvcLocator->service("EventDataSvc"));
91  if( !eds.isValid() ) {
92  std::cout << "ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc"
93  << std::endl;
94  return StatusCode::FAILURE;
95  }
96  else {
97  cnt = eds->rootName();
98  }
100  m_properties->erase(m_properties->begin(), m_properties->end());
101 
102  tok.analyse(m_definition, " ", "", "", "=", "'", "'");
103  for ( Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++ ) {
104  long hash = -1;
105  const std::string& tag = (*i).tag();
106  const std::string& val = (*i).value();
107  switch( ::toupper(tag[0]) ) {
108  case 'A':
109  auth = val;
110  break;
111  case 'C':
112  svc = "EvtTupleSvc";
113  isData = false;
114  case 'E':
115  hash = val.find('#');
116  if ( hash > 0 ) {
117  cnt = val.substr(0,hash);
118  item = val.substr(hash+1, val.length()-hash-1);
119  }
120  else {
121  cnt = val;
122  item = "Address";
123  }
124  break;
125  case 'D':
126  m_criteria = "FILE " + val;
127  m_dbName=val;
128  break;
129  case 'F':
130  switch( ::toupper(tag[1]) ) {
131  case 'I':
132  m_criteria = "FILE " + val;
133  m_dbName=val;
134  break;
135  case 'U':
136  stmt = val;
137  break;
138  default:
139  break;
140  }
141  break;
142  case 'J':
143  m_criteria = "JOBID " + val;
144  m_dbName=val;
145  dbtyp = "SICB";
146  break;
147  case 'T':
148  switch( ::toupper(tag[1]) ) {
149  case 'Y':
150  dbtyp = val;
151  break;
152  default:
153  break;
154  }
155  break;
156  case 'S':
157  switch( ::toupper(tag[1]) ) {
158  case 'E':
159  sel = val;
160  break;
161  case 'V':
162  svc = val;
163  collsvc = val;
164  break;
165  default:
166  break;
167  }
168  break;
169  default:
170  m_properties->push_back(StringProperty(tag,val));
171  break;
172  }
173  }
174  if ( !isData ) { // Unfortunately options do not come in order...
175  m_selectorType = "EventCollectionSelector";
176  svc = "EvtTupleSvc";
177  }
178  else if ( dbtyp.substr(0,4) == "POOL" ) {
179  m_selectorType = "PoolDbEvtSelector";
180  }
181  else if ( svc.empty() ) {
182  m_selectorType = "DbEvtSelector";
183  }
184  else {
185  m_selectorType = svc;
186  }
188  if ( svc.length() == 0 && dbtyp.length() != 0 ) {
189  SmartIF<IPersistencySvc> ipers(m_pSvcLocator->service("EventPersistencySvc"));
190  if ( ipers.isValid() ) {
191  IConversionSvc* icnvSvc = 0;
192  status = ipers->getService(dbtyp, icnvSvc);
193  if ( status.isSuccess() ) {
194  IService* isvc = 0;
195  status = icnvSvc->queryInterface(IService::interfaceID(), pp_cast<void>(&isvc));
196  if ( status.isSuccess() ) {
197  svc = isvc->name();
198  isvc->release();
199  }
200  }
201  }
202  }
203  m_properties->push_back( StringProperty("Function", stmt));
204  m_properties->push_back( StringProperty("CnvService", svc));
205  m_properties->push_back( StringProperty("Authentication",auth));
206  m_properties->push_back( StringProperty("Container", cnt));
207  m_properties->push_back( StringProperty("Item", item));
208  m_properties->push_back( StringProperty("Criteria", sel));
209  m_properties->push_back( StringProperty("DbType", dbtyp));
210  m_properties->push_back( StringProperty("DB", m_criteria));
211  if ( !isData && !collsvc.empty() ) {
212  m_properties->push_back( StringProperty("DbService", collsvc));
213  }
214 
215  m_initialized = status.isSuccess();
216  return status;
217 }
218 
219 // Parse input criteria
221  setSelector(0);
222  if ( m_properties ) {
223  m_properties->clear();
224  }
225  m_initialized = false;
226  return StatusCode::SUCCESS;
227 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool m_initialized
Initialization state.
const std::string & name() const
Retrieve stream name.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
MsgStream & operator<<(MsgStream &s, const EventSelectorDataStream &obj)
Output friend for MsgStream.
Items & items()
Access token collection.
Definition: Tokenizer.h:99
The Event Selector Interface.
Definition: IEvtSelector.h:19
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
IEvtSelector * m_pSelector
Pointer to valid selector.
void analyse(const std::string &s, const char *delim, const char *tagBegin, const char *tagEnd, const char *eq, const char *valBegin, const char *valEnd)
Analyse tokens from string.
Definition: Tokenizer.cpp:37
std::string m_criteria
Criteria.
SimpleProperty< std::string > StringProperty
Definition: Property.h:743
std::string m_selectorType
Event selector type.
StringProperty * property(const std::string &nam)
Allow access to individual properties by name.
virtual const std::string & name() const =0
Retrieve the name of the instance.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:82
ISvcLocator * m_pSvcLocator
Reference to service locator.
virtual StatusCode initialize()
Parse input criteria.
std::vector< StringProperty > Properties
General service interface definition.
Definition: IService.h:19
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode finalize()
Finalize stream and release resources.
STL Include files.
Definition: Tokenizer.h:24
std::string m_definition
Definition string.
const std::string & definition() const
Retrieve definition string.
EventSelectorDataStream(const std::string &nam, const std::string &def, ISvcLocator *svcloc)
Standard Constructor.
virtual unsigned long release()=0
Release Interface instance.
Definition of class EventSelectorDataStream.
string s
Definition: gaudirun.py:210
tuple item
print s1,s2
Definition: ana.py:146
Properties * m_properties
Properties vector.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
virtual ~EventSelectorDataStream()
Standard Destructor.
std::string m_dbName
String with name of the db as parsed.
list i
Definition: ana.py:128
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:171
void toupper(std::string &s)
virtual void setSelector(IEvtSelector *pSelector)
Attach event selector object.
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.