| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
27 MsgStream& operator<<(MsgStream& s, const EventSelectorDataStream& obj) {
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
43 void EventSelectorDataStream::setSelector(IEvtSelector* pSelector) {
44 m_pSelector = pSelector;
45 }
46
47 // Allow access to individual properties by name
48 StringProperty* EventSelectorDataStream::property(const std::string& nam) {
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
62 StatusCode EventSelectorDataStream::initialize() {
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 }
77 m_selectorType = m_criteria = m_dbName= "";
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 }
164 StatusCode status = StatusCode::SUCCESS;
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
193 StatusCode EventSelectorDataStream::finalize() {
194 setSelector(nullptr);
195 m_properties.clear();
196 m_initialized = false;
197 return StatusCode::SUCCESS;
198 }
Gaudi::Utils::AttribStringParser
Parse attribute strings allowing iteration over the various attributes.
Definition: AttribStringParser.h:30
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
EventSelectorDataStream::m_initialized
bool m_initialized
Initialization state.
Definition: EventSelectorDataStream.h:70
SmartIF< INamedInterface >
EventSelectorDataStream::name
const std::string & name() const
Retrieve stream name.
Definition: EventSelectorDataStream.h:91
std::string::empty
T empty(T...args)
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
operator<<
MsgStream & operator<<(MsgStream &s, const EventSelectorDataStream &obj)
Output friend for MsgStream.
Definition: EventSelectorDataStream.cpp:27
IConversionSvc
Definition: IConversionSvc.h:37
MsgStream.h
Property::name
const std::string & name() const
property name
Definition: Property.h:45
IEvtSelector
The Event Selector Interface.
Definition: IEvtSelector.h:18
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
std::endl
T endl(T...args)
std::end
T end(T...args)
EventSelectorDataStream::m_criteria
std::string m_criteria
Criteria.
Definition: EventSelectorDataStream.h:58
EventSelectorDataStream::m_selectorType
std::string m_selectorType
Event selector type.
Definition: EventSelectorDataStream.h:62
EventSelectorDataStream::property
StringProperty * property(const std::string &nam)
Allow access to individual properties by name.
Definition: EventSelectorDataStream.cpp:48
std::string
STL class.
IPersistencySvc.h
EventSelectorDataStream::m_pSelector
SmartIF< IEvtSelector > m_pSelector
Pointer to valid selector.
Definition: EventSelectorDataStream.h:64
SimpleProperty< std::string >
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
EventSelectorDataStream::m_pSvcLocator
ISvcLocator * m_pSvcLocator
Reference to service locator.
Definition: EventSelectorDataStream.h:66
EventSelectorDataStream::initialize
virtual StatusCode initialize()
Parse input criteria.
Definition: EventSelectorDataStream.cpp:62
IDataManagerSvc.h
read_lhcb_event_file.sel
tuple sel
Definition: read_lhcb_event_file.py:10
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
EventSelectorDataStream::finalize
virtual StatusCode finalize()
Finalize stream and release resources.
Definition: EventSelectorDataStream.cpp:193
EventSelectorDataStream.h
std::vector::clear
T clear(T...args)
std::move
T move(T...args)
IService.h
EventSelectorDataStream::m_definition
std::string m_definition
Definition string.
Definition: EventSelectorDataStream.h:56
EventSelectorDataStream::definition
const std::string & definition() const
Retrieve definition string.
Definition: EventSelectorDataStream.h:107
std::find_if
T find_if(T...args)
EventSelectorDataStream::m_properties
Properties m_properties
Properties vector.
Definition: EventSelectorDataStream.h:68
IConversionSvc.h
IDataManagerSvc
Definition: IDataManagerSvc.h:45
std::begin
T begin(T...args)
EventSelectorDataStream
Definition of class EventSelectorDataStream.
Definition: EventSelectorDataStream.h:45
PropertyMgr.h
gaudirun.s
string s
Definition: gaudirun.py:245
ana.item
tuple item
print s1,s2
Definition: ana.py:146
AttribStringParser.h
std::string::substr
T substr(T...args)
IPersistencySvc
Data persistency service interface.
Definition: IPersistencySvc.h:19
EventSelectorDataStream::EventSelectorDataStream
EventSelectorDataStream(std::string nam, std::string def, ISvcLocator *svcloc)
Standard Constructor.
Definition: EventSelectorDataStream.cpp:37
EventSelectorDataStream::m_dbName
std::string m_dbName
String with name of the db as parsed.
Definition: EventSelectorDataStream.h:60
ana.i
list i
Definition: ana.py:128
std::ostream
STL class.
ISvcLocator.h
toupper
void toupper(std::string &s)
Definition: StatusCodeSvc.cpp:10
EventSelectorDataStream::setSelector
virtual void setSelector(IEvtSelector *pSelector)
Attach event selector object.
Definition: EventSelectorDataStream.cpp:43
std::string::compare
T compare(T...args)
std::vector::emplace_back
T emplace_back(T...args)