All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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/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  return s << "Stream:" << obj.name() << " Def:" << obj.definition();
29 }
30 
31 // Output friend
32 std::ostream& operator<<(std::ostream& s, const EventSelectorDataStream& obj) {
33  return s << "Stream:" << obj.name() << " Def:" << obj.definition();
34 }
35 
36 // Standard Constructor
37 EventSelectorDataStream::EventSelectorDataStream(std::string nam, std::string def, ISvcLocator* svcloc)
38 : m_name{ std::move(nam) }, m_definition{ std::move(def) }, m_pSvcLocator(svcloc)
39 {
40 }
41 
42 // Set selector
44  m_pSelector = pSelector;
45 }
46 
47 // Allow access to individual properties by name
49  auto i = std::find_if( std::begin(m_properties), std::end(m_properties),
50  [&](const StringProperty& j ) { return j.name() == nam ; } );
51  return i!=std::end(m_properties) ? &(*i) : nullptr;
52 }
53 
54 // Allow access to individual properties by name
55 const StringProperty* EventSelectorDataStream::property(const std::string& nam) const {
56  auto i = std::find_if( std::begin(m_properties), std::end(m_properties),
57  [&](const StringProperty& j ) { return j.name() == nam ; } );
58  return i!=std::end(m_properties) ? &(*i) : nullptr;
59 }
60 
61 // Parse input criteria
63  bool isData = true;
64  std::string auth, dbtyp, collsvc, item, crit, sel, svc, stmt;
65  std::string cnt = "/Event";
66  std::string db = "<Unknown>";
67 
68  auto eds = m_pSvcLocator->service<IDataManagerSvc>("EventDataSvc");
69  if( !eds ) {
70  std::cout << "ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc"
71  << std::endl;
72  return StatusCode::FAILURE;
73  }
74  else {
75  cnt = eds->rootName();
76  }
78  m_properties.clear();
79 
80  using Parser = Gaudi::Utils::AttribStringParser;
81  for (auto attrib: Parser(m_definition)) {
82  long hash = -1;
83  switch( ::toupper(attrib.tag[0]) ) {
84  case 'A':
85  auth = std::move(attrib.value);
86  break;
87  case 'C':
88  svc = "EvtTupleSvc";
89  isData = false;
90  /* no break */
91  case 'E':
92  hash = attrib.value.find('#');
93  if ( hash > 0 ) {
94  cnt = attrib.value.substr(0, hash);
95  item = attrib.value.substr(hash + 1);
96  }
97  else {
98  cnt = std::move(attrib.value);
99  item = "Address";
100  }
101  break;
102  case 'D':
103  m_criteria = "FILE " + attrib.value;
104  m_dbName = std::move(attrib.value);
105  break;
106  case 'F':
107  switch( ::toupper(attrib.tag[1]) ) {
108  case 'I':
109  m_criteria = "FILE " + attrib.value;
110  m_dbName = std::move(attrib.value);
111  break;
112  case 'U':
113  stmt = std::move(attrib.value);
114  break;
115  default:
116  break;
117  }
118  break;
119  case 'J':
120  m_criteria = "JOBID " + attrib.value;
121  m_dbName = std::move(attrib.value);
122  dbtyp = "SICB";
123  break;
124  case 'T':
125  switch( ::toupper(attrib.tag[1]) ) {
126  case 'Y':
127  dbtyp = std::move(attrib.value);
128  break;
129  default:
130  break;
131  }
132  break;
133  case 'S':
134  switch( ::toupper(attrib.tag[1]) ) {
135  case 'E':
136  sel = std::move(attrib.value);
137  break;
138  case 'V':
139  svc = std::move(attrib.value);
140  collsvc = svc;
141  break;
142  default:
143  break;
144  }
145  break;
146  default:
147  m_properties.emplace_back(attrib.tag, attrib.value);
148  break;
149  }
150  }
151  if ( !isData ) { // Unfortunately options do not come in order...
152  m_selectorType = "EventCollectionSelector";
153  svc = "EvtTupleSvc";
154  }
155  else if ( dbtyp.compare(0,4,"POOL") == 0 ) {
156  m_selectorType = "PoolDbEvtSelector";
157  }
158  else if ( svc.empty() ) {
159  m_selectorType = "DbEvtSelector";
160  }
161  else {
162  m_selectorType = svc;
163  }
165  if ( svc.empty() && !dbtyp.empty() ) {
166  auto ipers = m_pSvcLocator->service<IPersistencySvc>("EventPersistencySvc");
167  if ( ipers ) {
168  IConversionSvc* icnvSvc = nullptr;
169  status = ipers->getService(dbtyp, icnvSvc);
170  if ( status.isSuccess() ) {
171  auto isvc = SmartIF<INamedInterface>{ icnvSvc } ;
172  if ( isvc ) svc = isvc->name();
173  }
174  }
175  }
176  m_properties.emplace_back( "Function", stmt);
177  m_properties.emplace_back( "CnvService", svc);
178  m_properties.emplace_back( "Authentication",auth);
179  m_properties.emplace_back( "Container", cnt);
180  m_properties.emplace_back( "Item", item);
181  m_properties.emplace_back( "Criteria", sel);
182  m_properties.emplace_back( "DbType", dbtyp);
183  m_properties.emplace_back( "DB", m_criteria);
184  if ( !isData && !collsvc.empty() ) {
185  m_properties.emplace_back( "DbService", collsvc);
186  }
187 
188  m_initialized = status.isSuccess();
189  return status;
190 }
191 
192 // Parse input criteria
194  setSelector(nullptr);
195  m_properties.clear();
196  m_initialized = false;
197  return StatusCode::SUCCESS;
198 }
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:25
MsgStream & operator<<(MsgStream &s, const EventSelectorDataStream &obj)
Output friend for MsgStream.
const std::string & name() const
property name
Definition: Property.h:45
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
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.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
virtual StatusCode initialize()
Parse input criteria.
ISvcLocator * m_pSvcLocator
Reference to service locator.
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
SmartIF< IEvtSelector > m_pSelector
Pointer to valid selector.
virtual StatusCode finalize()
Finalize stream and release resources.
std::string m_definition
Definition string.
const std::string & definition() const
Retrieve definition string.
Properties m_properties
Properties vector.
Definition of class EventSelectorDataStream.
string s
Definition: gaudirun.py:245
tuple item
print s1,s2
Definition: ana.py:146
Data persistency service interface.
EventSelectorDataStream(std::string nam, std::string def, ISvcLocator *svcloc)
Standard Constructor.
std::string m_dbName
String with name of the db as parsed.
list i
Definition: ana.py:128
void toupper(std::string &s)
virtual void setSelector(IEvtSelector *pSelector)
Attach event selector object.