The Gaudi Framework  v33r1 (b1225454)
EventSelectorDataStream.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 //====================================================================
12 // EventSelectorDataStream.cpp
13 //--------------------------------------------------------------------
14 //
15 // Package : EventSelectorDataStream (The LHCb Event Selector Package)
16 //
17 //
18 // Author : M.Frank
19 // Created : 4/10/00
20 // Changes : R. Lambert 2009-09-04
21 //
22 //====================================================================
23 #define GAUDISVC_EVENTSELECTOR_EVENTSELECTORDATASTREAM_CPP 1
24 // Include files
30 #include "GaudiKernel/IService.h"
32 #include "GaudiKernel/MsgStream.h"
33 
34 // Output friend
36  return s << "Stream:" << obj.name() << " Def:" << obj.definition();
37 }
38 
39 // Output friend
41  return s << "Stream:" << obj.name() << " Def:" << obj.definition();
42 }
43 
44 // Standard Constructor
46  : m_name{std::move( nam )}, m_definition{std::move( def )}, m_pSvcLocator( svcloc ) {}
47 
48 // Set selector
50 
51 // Allow access to individual properties by name
54  [&]( const Gaudi::Property<std::string>& j ) { return j.name() == nam; } );
55  return i != std::end( m_properties ) ? &( *i ) : nullptr;
56 }
57 
58 // Allow access to individual properties by name
61  [&]( const Gaudi::Property<std::string>& j ) { return j.name() == nam; } );
62  return i != std::end( m_properties ) ? &( *i ) : nullptr;
63 }
64 
65 // Parse input criteria
67  bool isData = true;
68  std::string auth, dbtyp, collsvc, item, crit, sel, svc, stmt;
69  std::string cnt = "/Event";
70  std::string db = "<Unknown>";
71 
72  auto eds = m_pSvcLocator->service<IDataManagerSvc>( "EventDataSvc" );
73  if ( !eds ) {
74  std::cout << "ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc" << std::endl;
75  return StatusCode::FAILURE;
76  } else {
77  cnt = eds->rootName();
78  }
81 
82  using Parser = Gaudi::Utils::AttribStringParser;
83  for ( auto attrib : Parser( m_definition ) ) {
84  long hash = -1;
85  switch ( ::toupper( attrib.tag[0] ) ) {
86  case 'A':
87  auth = std::move( attrib.value );
88  break;
89  case 'C':
90  svc = "EvtTupleSvc";
91  isData = false;
92  [[fallthrough]];
93  case 'E':
94  hash = attrib.value.find( '#' );
95  if ( hash > 0 ) {
96  cnt = attrib.value.substr( 0, hash );
97  item = attrib.value.substr( hash + 1 );
98  } else {
99  cnt = std::move( attrib.value );
100  item = "Address";
101  }
102  break;
103  case 'D':
104  m_criteria = "FILE " + attrib.value;
105  m_dbName = std::move( attrib.value );
106  break;
107  case 'F':
108  switch ( ::toupper( attrib.tag[1] ) ) {
109  case 'I':
110  m_criteria = "FILE " + attrib.value;
111  m_dbName = std::move( attrib.value );
112  break;
113  case 'U':
114  stmt = std::move( attrib.value );
115  break;
116  default:
117  break;
118  }
119  break;
120  case 'J':
121  m_criteria = "JOBID " + attrib.value;
122  m_dbName = std::move( attrib.value );
123  dbtyp = "SICB";
124  break;
125  case 'T':
126  switch ( ::toupper( attrib.tag[1] ) ) {
127  case 'Y':
128  dbtyp = std::move( attrib.value );
129  break;
130  default:
131  break;
132  }
133  break;
134  case 'S':
135  switch ( ::toupper( attrib.tag[1] ) ) {
136  case 'E':
137  sel = std::move( attrib.value );
138  break;
139  case 'V':
140  svc = std::move( attrib.value );
141  collsvc = svc;
142  break;
143  default:
144  break;
145  }
146  break;
147  default:
148  m_properties.emplace_back( attrib.tag, attrib.value );
149  break;
150  }
151  }
152  if ( !isData ) { // Unfortunately options do not come in order...
153  m_selectorType = "EventCollectionSelector";
154  svc = "EvtTupleSvc";
155  } else if ( dbtyp.compare( 0, 4, "POOL" ) == 0 ) {
156  m_selectorType = "PoolDbEvtSelector";
157  } else if ( svc.empty() ) {
158  m_selectorType = "DbEvtSelector";
159  } else {
160  m_selectorType = svc;
161  }
163  if ( svc.empty() && !dbtyp.empty() ) {
164  auto ipers = m_pSvcLocator->service<IPersistencySvc>( "EventPersistencySvc" );
165  if ( ipers ) {
166  IConversionSvc* icnvSvc = nullptr;
167  status = ipers->getService( dbtyp, icnvSvc );
168  if ( status.isSuccess() ) {
169  auto isvc = SmartIF<INamedInterface>{icnvSvc};
170  if ( isvc ) svc = isvc->name();
171  }
172  }
173  }
174  m_properties.emplace_back( "Function", stmt );
175  m_properties.emplace_back( "CnvService", svc );
176  m_properties.emplace_back( "Authentication", auth );
177  m_properties.emplace_back( "Container", cnt );
178  m_properties.emplace_back( "Item", item );
179  m_properties.emplace_back( "Criteria", sel );
180  m_properties.emplace_back( "DbType", dbtyp );
182  if ( !isData && !collsvc.empty() ) { m_properties.emplace_back( "DbService", collsvc ); }
183 
184  m_initialized = status.isSuccess();
185  return status;
186 }
187 
188 // Parse input criteria
190  setSelector( nullptr );
192  m_initialized = false;
193  return StatusCode::SUCCESS;
194 }
Parse attribute strings allowing iteration over the various attributes.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
bool m_initialized
Initialization state.
T empty(T... args)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
MsgStream & operator<<(MsgStream &s, const EventSelectorDataStream &obj)
Output friend for MsgStream.
Implementation of property with value of concrete type.
Definition: Property.h:370
The Event Selector Interface.
Definition: IEvtSelector.h:28
T endl(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
const std::string & name() const
Retrieve stream name.
T end(T... args)
std::string m_criteria
Criteria.
const std::string name() const
property name
Definition: Property.h:46
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:86
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:61
virtual StatusCode finalize()
Finalize stream and release resources.
T clear(T... args)
bool isSuccess() const
Definition: StatusCode.h:365
T move(T... args)
std::string m_definition
Definition string.
T find_if(T... args)
Properties m_properties
Properties vector.
const std::string & definition() const
Retrieve definition string.
T begin(T... args)
Definition of class EventSelectorDataStream.
string s
Definition: gaudirun.py:328
constexpr static const auto FAILURE
Definition: StatusCode.h:101
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)