Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
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
20 #include "GaudiKernel/IService.h"
22 #include "GaudiKernel/MsgStream.h"
23 
24 // Output friend
26  return s << "Stream:" << obj.name() << " Def:" << obj.definition();
27 }
28 
29 // Output friend
31  return s << "Stream:" << obj.name() << " Def:" << obj.definition();
32 }
33 
34 // Standard Constructor
36  : m_name{std::move( nam )}, m_definition{std::move( def )}, m_pSvcLocator( svcloc ) {}
37 
38 // Set selector
40 
41 // Allow access to individual properties by name
44  [&]( const Gaudi::Property<std::string>& j ) { return j.name() == nam; } );
45  return i != std::end( m_properties ) ? &( *i ) : nullptr;
46 }
47 
48 // Allow access to individual properties by name
51  [&]( const Gaudi::Property<std::string>& j ) { return j.name() == nam; } );
52  return i != std::end( m_properties ) ? &( *i ) : nullptr;
53 }
54 
55 // Parse input criteria
57  bool isData = true;
58  std::string auth, dbtyp, collsvc, item, crit, sel, svc, stmt;
59  std::string cnt = "/Event";
60  std::string db = "<Unknown>";
61 
62  auto eds = m_pSvcLocator->service<IDataManagerSvc>( "EventDataSvc" );
63  if ( !eds ) {
64  std::cout << "ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc" << std::endl;
65  return StatusCode::FAILURE;
66  } else {
67  cnt = eds->rootName();
68  }
71 
72  using Parser = Gaudi::Utils::AttribStringParser;
73  for ( auto attrib : Parser( m_definition ) ) {
74  long hash = -1;
75  switch ( ::toupper( attrib.tag[0] ) ) {
76  case 'A':
77  auth = std::move( attrib.value );
78  break;
79  case 'C':
80  svc = "EvtTupleSvc";
81  isData = false;
82  /* FALLTHROUGH */
83  case 'E':
84  hash = attrib.value.find( '#' );
85  if ( hash > 0 ) {
86  cnt = attrib.value.substr( 0, hash );
87  item = attrib.value.substr( hash + 1 );
88  } else {
89  cnt = std::move( attrib.value );
90  item = "Address";
91  }
92  break;
93  case 'D':
94  m_criteria = "FILE " + attrib.value;
95  m_dbName = std::move( attrib.value );
96  break;
97  case 'F':
98  switch ( ::toupper( attrib.tag[1] ) ) {
99  case 'I':
100  m_criteria = "FILE " + attrib.value;
101  m_dbName = std::move( attrib.value );
102  break;
103  case 'U':
104  stmt = std::move( attrib.value );
105  break;
106  default:
107  break;
108  }
109  break;
110  case 'J':
111  m_criteria = "JOBID " + attrib.value;
112  m_dbName = std::move( attrib.value );
113  dbtyp = "SICB";
114  break;
115  case 'T':
116  switch ( ::toupper( attrib.tag[1] ) ) {
117  case 'Y':
118  dbtyp = std::move( attrib.value );
119  break;
120  default:
121  break;
122  }
123  break;
124  case 'S':
125  switch ( ::toupper( attrib.tag[1] ) ) {
126  case 'E':
127  sel = std::move( attrib.value );
128  break;
129  case 'V':
130  svc = std::move( attrib.value );
131  collsvc = svc;
132  break;
133  default:
134  break;
135  }
136  break;
137  default:
138  m_properties.emplace_back( attrib.tag, attrib.value );
139  break;
140  }
141  }
142  if ( !isData ) { // Unfortunately options do not come in order...
143  m_selectorType = "EventCollectionSelector";
144  svc = "EvtTupleSvc";
145  } else if ( dbtyp.compare( 0, 4, "POOL" ) == 0 ) {
146  m_selectorType = "PoolDbEvtSelector";
147  } else if ( svc.empty() ) {
148  m_selectorType = "DbEvtSelector";
149  } else {
150  m_selectorType = svc;
151  }
153  if ( svc.empty() && !dbtyp.empty() ) {
154  auto ipers = m_pSvcLocator->service<IPersistencySvc>( "EventPersistencySvc" );
155  if ( ipers ) {
156  IConversionSvc* icnvSvc = nullptr;
157  status = ipers->getService( dbtyp, icnvSvc );
158  if ( status.isSuccess() ) {
159  auto isvc = SmartIF<INamedInterface>{icnvSvc};
160  if ( isvc ) svc = isvc->name();
161  }
162  }
163  }
164  m_properties.emplace_back( "Function", stmt );
165  m_properties.emplace_back( "CnvService", svc );
166  m_properties.emplace_back( "Authentication", auth );
167  m_properties.emplace_back( "Container", cnt );
168  m_properties.emplace_back( "Item", item );
169  m_properties.emplace_back( "Criteria", sel );
170  m_properties.emplace_back( "DbType", dbtyp );
172  if ( !isData && !collsvc.empty() ) { m_properties.emplace_back( "DbService", collsvc ); }
173 
174  m_initialized = status.isSuccess();
175  return status;
176 }
177 
178 // Parse input criteria
180  setSelector( nullptr );
182  m_initialized = false;
183  return StatusCode::SUCCESS;
184 }
Parse attribute strings allowing iteration over the various attributes.
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.
T empty(T...args)
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.
Implementation of property with value of concrete type.
Definition: Property.h:352
const std::string name() const
property name
Definition: Property.h:36
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Definition: StatusCode.h:267
T endl(T...args)
sel
Definition: IOTest.py:93
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
T end(T...args)
std::string m_criteria
Criteria.
std::string m_selectorType
Event selector type.
STL class.
SmartIF< IEvtSelector > m_pSelector
Pointer to valid selector.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
ISvcLocator * m_pSvcLocator
Reference to service locator.
virtual StatusCode initialize()
Parse input criteria.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
virtual StatusCode finalize()
Finalize stream and release resources.
T clear(T...args)
T move(T...args)
std::string m_definition
Definition string.
const std::string & definition() const
Retrieve definition string.
T find_if(T...args)
Properties m_properties
Properties vector.
T begin(T...args)
Definition of class EventSelectorDataStream.
string s
Definition: gaudirun.py:312
constexpr static const auto FAILURE
Definition: StatusCode.h:86
T substr(T...args)
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.
Gaudi::Property< std::string > * property(const std::string &nam)
Allow access to individual properties by name.
STL class.
void toupper(std::string &s)
virtual void setSelector(IEvtSelector *pSelector)
Attach event selector object.
T compare(T...args)
T emplace_back(T...args)