The Gaudi Framework  v30r3 (a5ef0a68)
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 {
27  return s << "Stream:" << obj.name() << " Def:" << obj.definition();
28 }
29 
30 // Output friend
32 {
33  return s << "Stream:" << obj.name() << " Def:" << obj.definition();
34 }
35 
36 // Standard Constructor
38  : m_name{std::move( nam )}, m_definition{std::move( def )}, m_pSvcLocator( svcloc )
39 {
40 }
41 
42 // Set selector
44 
45 // Allow access to individual properties by name
47 {
49  [&]( const Gaudi::Property<std::string>& j ) { return j.name() == nam; } );
50  return i != std::end( m_properties ) ? &( *i ) : nullptr;
51 }
52 
53 // Allow access to individual properties by name
55 {
57  [&]( const Gaudi::Property<std::string>& j ) { return j.name() == nam; } );
58  return i != std::end( m_properties ) ? &( *i ) : nullptr;
59 }
60 
61 // Parse input criteria
63 {
64  bool isData = true;
65  std::string auth, dbtyp, collsvc, item, crit, sel, svc, stmt;
66  std::string cnt = "/Event";
67  std::string db = "<Unknown>";
68 
69  auto eds = m_pSvcLocator->service<IDataManagerSvc>( "EventDataSvc" );
70  if ( !eds ) {
71  std::cout << "ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc" << std::endl;
72  return StatusCode::FAILURE;
73  } else {
74  cnt = eds->rootName();
75  }
78 
79  using Parser = Gaudi::Utils::AttribStringParser;
80  for ( auto attrib : Parser( m_definition ) ) {
81  long hash = -1;
82  switch (::toupper( attrib.tag[0] ) ) {
83  case 'A':
84  auth = std::move( attrib.value );
85  break;
86  case 'C':
87  svc = "EvtTupleSvc";
88  isData = false;
89  /* FALLTHROUGH */
90  case 'E':
91  hash = attrib.value.find( '#' );
92  if ( hash > 0 ) {
93  cnt = attrib.value.substr( 0, hash );
94  item = attrib.value.substr( hash + 1 );
95  } else {
96  cnt = std::move( attrib.value );
97  item = "Address";
98  }
99  break;
100  case 'D':
101  m_criteria = "FILE " + attrib.value;
102  m_dbName = std::move( attrib.value );
103  break;
104  case 'F':
105  switch (::toupper( attrib.tag[1] ) ) {
106  case 'I':
107  m_criteria = "FILE " + attrib.value;
108  m_dbName = std::move( attrib.value );
109  break;
110  case 'U':
111  stmt = std::move( attrib.value );
112  break;
113  default:
114  break;
115  }
116  break;
117  case 'J':
118  m_criteria = "JOBID " + attrib.value;
119  m_dbName = std::move( attrib.value );
120  dbtyp = "SICB";
121  break;
122  case 'T':
123  switch (::toupper( attrib.tag[1] ) ) {
124  case 'Y':
125  dbtyp = std::move( attrib.value );
126  break;
127  default:
128  break;
129  }
130  break;
131  case 'S':
132  switch (::toupper( attrib.tag[1] ) ) {
133  case 'E':
134  sel = std::move( attrib.value );
135  break;
136  case 'V':
137  svc = std::move( attrib.value );
138  collsvc = svc;
139  break;
140  default:
141  break;
142  }
143  break;
144  default:
145  m_properties.emplace_back( attrib.tag, attrib.value );
146  break;
147  }
148  }
149  if ( !isData ) { // Unfortunately options do not come in order...
150  m_selectorType = "EventCollectionSelector";
151  svc = "EvtTupleSvc";
152  } else if ( dbtyp.compare( 0, 4, "POOL" ) == 0 ) {
153  m_selectorType = "PoolDbEvtSelector";
154  } else if ( svc.empty() ) {
155  m_selectorType = "DbEvtSelector";
156  } else {
157  m_selectorType = svc;
158  }
160  if ( svc.empty() && !dbtyp.empty() ) {
161  auto ipers = m_pSvcLocator->service<IPersistencySvc>( "EventPersistencySvc" );
162  if ( ipers ) {
163  IConversionSvc* icnvSvc = nullptr;
164  status = ipers->getService( dbtyp, icnvSvc );
165  if ( status.isSuccess() ) {
166  auto isvc = SmartIF<INamedInterface>{icnvSvc};
167  if ( isvc ) svc = isvc->name();
168  }
169  }
170  }
171  m_properties.emplace_back( "Function", stmt );
172  m_properties.emplace_back( "CnvService", svc );
173  m_properties.emplace_back( "Authentication", auth );
174  m_properties.emplace_back( "Container", cnt );
175  m_properties.emplace_back( "Item", item );
176  m_properties.emplace_back( "Criteria", sel );
177  m_properties.emplace_back( "DbType", dbtyp );
179  if ( !isData && !collsvc.empty() ) {
180  m_properties.emplace_back( "DbService", collsvc );
181  }
182 
183  m_initialized = status.isSuccess();
184  return status;
185 }
186 
187 // Parse input criteria
189 {
190  setSelector( nullptr );
192  m_initialized = false;
193  return StatusCode::SUCCESS;
194 }
Parse attribute strings allowing iteration over the various attributes.
constexpr static const auto FAILURE
Definition: StatusCode.h:88
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:381
const std::string name() const
property name
Definition: Property.h:40
The Event Selector Interface.
Definition: IEvtSelector.h:18
bool isSuccess() const
Definition: StatusCode.h:287
T endl(T...args)
sel
Definition: IOTest.py:95
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:79
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:51
virtual StatusCode finalize()
Finalize stream and release resources.
T clear(T...args)
T move(T...args)
std::string m_definition
Definition string.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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:253
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)