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/AttribStringParser.h"
16 #include "GaudiKernel/IService.h"
17 #include "GaudiKernel/ISvcLocator.h"
18 #include "GaudiKernel/IConversionSvc.h"
19 #include "GaudiKernel/IDataManagerSvc.h"
20 #include "GaudiKernel/IPersistencySvc.h"
21 #include "GaudiKernel/PropertyMgr.h"
22 #include "GaudiKernel/MsgStream.h"
23 #include "GaudiKernel/EventSelectorDataStream.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 
89  SmartIF<IDataManagerSvc> eds(m_pSvcLocator->service("EventDataSvc"));
90  if( !eds.isValid() ) {
91  std::cout << "ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc"
92  << std::endl;
93  return StatusCode::FAILURE;
94  }
95  else {
96  cnt = eds->rootName();
97  }
99  m_properties->erase(m_properties->begin(), m_properties->end());
100 
101  using Parser = Gaudi::Utils::AttribStringParser;
102  for (auto attrib: Parser(m_definition)) {
103  long hash = -1;
104  switch( ::toupper(attrib.tag[0]) ) {
105  case 'A':
106  auth = std::move(attrib.value);
107  break;
108  case 'C':
109  svc = "EvtTupleSvc";
110  isData = false;
111  /* no break */
112  case 'E':
113  hash = attrib.value.find('#');
114  if ( hash > 0 ) {
115  cnt = attrib.value.substr(0, hash);
116  item = attrib.value.substr(hash + 1);
117  }
118  else {
119  cnt = std::move(attrib.value);
120  item = "Address";
121  }
122  break;
123  case 'D':
124  m_criteria = "FILE " + attrib.value;
125  m_dbName = std::move(attrib.value);
126  break;
127  case 'F':
128  switch( ::toupper(attrib.tag[1]) ) {
129  case 'I':
130  m_criteria = "FILE " + attrib.value;
131  m_dbName = std::move(attrib.value);
132  break;
133  case 'U':
134  stmt = std::move(attrib.value);
135  break;
136  default:
137  break;
138  }
139  break;
140  case 'J':
141  m_criteria = "JOBID " + attrib.value;
142  m_dbName = std::move(attrib.value);
143  dbtyp = "SICB";
144  break;
145  case 'T':
146  switch( ::toupper(attrib.tag[1]) ) {
147  case 'Y':
148  dbtyp = std::move(attrib.value);
149  break;
150  default:
151  break;
152  }
153  break;
154  case 'S':
155  switch( ::toupper(attrib.tag[1]) ) {
156  case 'E':
157  sel = std::move(attrib.value);
158  break;
159  case 'V':
160  svc = std::move(attrib.value);
161  collsvc = svc;
162  break;
163  default:
164  break;
165  }
166  break;
167  default:
168  m_properties->push_back(StringProperty(attrib.tag, attrib.value));
169  break;
170  }
171  }
172  if ( !isData ) { // Unfortunately options do not come in order...
173  m_selectorType = "EventCollectionSelector";
174  svc = "EvtTupleSvc";
175  }
176  else if ( dbtyp.substr(0,4) == "POOL" ) {
177  m_selectorType = "PoolDbEvtSelector";
178  }
179  else if ( svc.empty() ) {
180  m_selectorType = "DbEvtSelector";
181  }
182  else {
183  m_selectorType = svc;
184  }
186  if ( svc.length() == 0 && dbtyp.length() != 0 ) {
187  SmartIF<IPersistencySvc> ipers(m_pSvcLocator->service("EventPersistencySvc"));
188  if ( ipers.isValid() ) {
189  IConversionSvc* icnvSvc = 0;
190  status = ipers->getService(dbtyp, icnvSvc);
191  if ( status.isSuccess() ) {
192  IService* isvc = 0;
193  status = icnvSvc->queryInterface(IService::interfaceID(), pp_cast<void>(&isvc));
194  if ( status.isSuccess() ) {
195  svc = isvc->name();
196  isvc->release();
197  }
198  }
199  }
200  }
201  m_properties->push_back( StringProperty("Function", stmt));
202  m_properties->push_back( StringProperty("CnvService", svc));
203  m_properties->push_back( StringProperty("Authentication",auth));
204  m_properties->push_back( StringProperty("Container", cnt));
205  m_properties->push_back( StringProperty("Item", item));
206  m_properties->push_back( StringProperty("Criteria", sel));
207  m_properties->push_back( StringProperty("DbType", dbtyp));
208  m_properties->push_back( StringProperty("DB", m_criteria));
209  if ( !isData && !collsvc.empty() ) {
210  m_properties->push_back( StringProperty("DbService", collsvc));
211  }
212 
213  m_initialized = status.isSuccess();
214  return status;
215 }
216 
217 // Parse input criteria
219  setSelector(0);
220  if ( m_properties ) {
221  m_properties->clear();
222  }
223  m_initialized = false;
224  return StatusCode::SUCCESS;
225 }
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.
Properties * m_properties
Properties vector.
The Event Selector Interface.
Definition: IEvtSelector.h:19
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
std::string m_criteria
Criteria.
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
virtual StatusCode initialize()
Parse input criteria.
ISvcLocator * m_pSvcLocator
Reference to service locator.
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.
IEvtSelector * m_pSelector
Pointer to valid selector.
SimpleProperty< std::string > StringProperty
Definition: Property.h:743
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:244
tuple item
print s1,s2
Definition: ana.py:146
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.