The Gaudi Framework
master (53dee381)
Toggle main menu visibility
Loading...
Searching...
No Matches
EventSelectorDataStream.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 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
#include <
GaudiKernel/AttribStringParser.h
>
12
#include <
GaudiKernel/EventSelectorDataStream.h
>
13
#include <
GaudiKernel/IConversionSvc.h
>
14
#include <
GaudiKernel/IDataManagerSvc.h
>
15
#include <
GaudiKernel/IPersistencySvc.h
>
16
#include <
GaudiKernel/IService.h
>
17
#include <
GaudiKernel/ISvcLocator.h
>
18
#include <
GaudiKernel/MsgStream.h
>
19
20
// Output friend
21
MsgStream
&
operator<<
(
MsgStream
& s,
const
EventSelectorDataStream
& obj ) {
22
return
s <<
"Stream:"
<< obj.
name
() <<
" Def:"
<< obj.
definition
();
23
}
24
25
// Output friend
26
std::ostream&
operator<<
( std::ostream& s,
const
EventSelectorDataStream
& obj ) {
27
return
s <<
"Stream:"
<< obj.
name
() <<
" Def:"
<< obj.
definition
();
28
}
29
30
// Standard Constructor
31
EventSelectorDataStream::EventSelectorDataStream
( std::string nam, std::string def,
ISvcLocator
* svcloc )
32
:
m_name
{
std
::move( nam ) },
m_definition
{
std
::move( def ) },
m_pSvcLocator
( svcloc ) {}
33
34
// Set selector
35
void
EventSelectorDataStream::setSelector
(
IEvtSelector
* pSelector ) {
m_pSelector
= pSelector; }
36
37
// Allow access to individual properties by name
38
Gaudi::Property<std::string>
*
EventSelectorDataStream::property
(
const
std::string& nam ) {
39
auto
i = std::find_if( std::begin(
m_properties
), std::end(
m_properties
),
40
[&](
const
Gaudi::Property<std::string>
& j ) {
return
j.
name
() == nam; } );
41
return
i != std::end(
m_properties
) ? &( *i ) :
nullptr
;
42
}
43
44
// Allow access to individual properties by name
45
const
Gaudi::Property<std::string>
*
EventSelectorDataStream::property
(
const
std::string& nam )
const
{
46
auto
i = std::find_if( std::begin(
m_properties
), std::end(
m_properties
),
47
[&](
const
Gaudi::Property<std::string>
& j ) {
return
j.
name
() == nam; } );
48
return
i != std::end(
m_properties
) ? &( *i ) :
nullptr
;
49
}
50
51
// Parse input criteria
52
StatusCode
EventSelectorDataStream::initialize
() {
53
bool
isData =
true
;
54
std::string auth, dbtyp, collsvc, item, crit, sel, svc, stmt;
55
std::string cnt =
"/Event"
;
56
std::string db =
"<Unknown>"
;
57
58
auto
eds =
m_pSvcLocator
->service<
IDataManagerSvc
>(
"EventDataSvc"
);
59
if
( !eds ) {
60
std::cout <<
"ERROR: Unable to localize interface IDataManagerSvc from service EventDataSvc"
<< std::endl;
61
return
StatusCode::FAILURE
;
62
}
else
{
63
cnt = eds->rootName();
64
}
65
m_selectorType
=
m_criteria
=
m_dbName
=
""
;
66
m_properties
.clear();
67
68
using
Parser =
Gaudi::Utils::AttribStringParser
;
69
for
(
auto
attrib : Parser(
m_definition
) ) {
70
long
hash = -1;
71
switch
(
::toupper
( attrib.tag[0] ) ) {
72
case
'A'
:
73
auth = std::move( attrib.value );
74
break
;
75
case
'C'
:
76
svc =
"EvtTupleSvc"
;
77
isData =
false
;
78
[[fallthrough]];
79
case
'E'
:
80
hash = attrib.value.find(
'#'
);
81
if
( hash > 0 ) {
82
cnt = attrib.value.substr( 0, hash );
83
item = attrib.value.substr( hash + 1 );
84
}
else
{
85
cnt = std::move( attrib.value );
86
item =
"Address"
;
87
}
88
break
;
89
case
'D'
:
90
m_criteria
=
"FILE "
+ attrib.value;
91
m_dbName
= std::move( attrib.value );
92
break
;
93
case
'F'
:
94
switch
(
::toupper
( attrib.tag[1] ) ) {
95
case
'I'
:
96
m_criteria
=
"FILE "
+ attrib.value;
97
m_dbName
= std::move( attrib.value );
98
break
;
99
case
'U'
:
100
stmt = std::move( attrib.value );
101
break
;
102
default
:
103
break
;
104
}
105
break
;
106
case
'J'
:
107
m_criteria
=
"JOBID "
+ attrib.value;
108
m_dbName
= std::move( attrib.value );
109
dbtyp =
"SICB"
;
110
break
;
111
case
'T'
:
112
switch
(
::toupper
( attrib.tag[1] ) ) {
113
case
'Y'
:
114
dbtyp = std::move( attrib.value );
115
break
;
116
default
:
117
break
;
118
}
119
break
;
120
case
'S'
:
121
switch
(
::toupper
( attrib.tag[1] ) ) {
122
case
'E'
:
123
sel = std::move( attrib.value );
124
break
;
125
case
'V'
:
126
svc = std::move( attrib.value );
127
collsvc = svc;
128
break
;
129
default
:
130
break
;
131
}
132
break
;
133
default
:
134
m_properties
.emplace_back( attrib.tag, attrib.value );
135
break
;
136
}
137
}
138
if
( !isData ) {
// Unfortunately options do not come in order...
139
m_selectorType
=
"EventCollectionSelector"
;
140
svc =
"EvtTupleSvc"
;
141
}
else
if
( svc.empty() ) {
142
m_selectorType
=
"DbEvtSelector"
;
143
}
else
{
144
m_selectorType
= svc;
145
}
146
StatusCode
status =
StatusCode::SUCCESS
;
147
if
( svc.empty() && !dbtyp.empty() ) {
148
auto
ipers =
m_pSvcLocator
->service<
IPersistencySvc
>(
"EventPersistencySvc"
);
149
if
( ipers ) {
150
IConversionSvc
* icnvSvc =
nullptr
;
151
status = ipers->getService( dbtyp, icnvSvc );
152
if
( status.
isSuccess
() ) {
153
auto
isvc =
SmartIF<INamedInterface>
{ icnvSvc };
154
if
( isvc ) svc = isvc->name();
155
}
156
}
157
}
158
m_properties
.emplace_back(
"Function"
, stmt );
159
m_properties
.emplace_back(
"CnvService"
, svc );
160
m_properties
.emplace_back(
"Authentication"
, auth );
161
m_properties
.emplace_back(
"Container"
, cnt );
162
m_properties
.emplace_back(
"Item"
, item );
163
m_properties
.emplace_back(
"Criteria"
, sel );
164
m_properties
.emplace_back(
"DbType"
, dbtyp );
165
m_properties
.emplace_back(
"DB"
,
m_criteria
);
166
if
( !isData && !collsvc.empty() ) {
m_properties
.emplace_back(
"DbService"
, collsvc ); }
167
168
m_initialized
= status.
isSuccess
();
169
return
status;
170
}
171
172
// Parse input criteria
173
StatusCode
EventSelectorDataStream::finalize
() {
174
setSelector
(
nullptr
);
175
m_properties
.clear();
176
m_initialized
=
false
;
177
return
StatusCode::SUCCESS
;
178
}
AttribStringParser.h
operator<<
MsgStream & operator<<(MsgStream &s, const EventSelectorDataStream &obj)
Output friend for MsgStream.
Definition
EventSelectorDataStream.cpp:21
EventSelectorDataStream.h
toupper
void toupper(std::string &s)
Definition
ExceptionSvc.cpp:36
IConversionSvc.h
IDataManagerSvc.h
IPersistencySvc.h
IService.h
ISvcLocator.h
MsgStream.h
EventSelectorDataStream::finalize
virtual StatusCode finalize()
Finalize stream and release resources.
Definition
EventSelectorDataStream.cpp:173
EventSelectorDataStream::m_selectorType
std::string m_selectorType
Event selector type.
Definition
EventSelectorDataStream.h:58
EventSelectorDataStream::m_pSelector
SmartIF< IEvtSelector > m_pSelector
Pointer to valid selector.
Definition
EventSelectorDataStream.h:60
EventSelectorDataStream::name
const std::string & name() const
Retrieve stream name.
Definition
EventSelectorDataStream.h:86
EventSelectorDataStream::EventSelectorDataStream
EventSelectorDataStream(std::string nam, std::string def, ISvcLocator *svcloc)
Standard Constructor.
Definition
EventSelectorDataStream.cpp:31
EventSelectorDataStream::m_properties
Properties m_properties
Properties vector.
Definition
EventSelectorDataStream.h:64
EventSelectorDataStream::m_name
std::string m_name
Name.
Definition
EventSelectorDataStream.h:50
EventSelectorDataStream::definition
const std::string & definition() const
Retrieve definition string.
Definition
EventSelectorDataStream.h:94
EventSelectorDataStream::m_definition
std::string m_definition
Definition string.
Definition
EventSelectorDataStream.h:52
EventSelectorDataStream::initialize
virtual StatusCode initialize()
Parse input criteria.
Definition
EventSelectorDataStream.cpp:52
EventSelectorDataStream::m_criteria
std::string m_criteria
Criteria.
Definition
EventSelectorDataStream.h:54
EventSelectorDataStream::property
Gaudi::Property< std::string > * property(const std::string &nam)
Allow access to individual properties by name.
Definition
EventSelectorDataStream.cpp:38
EventSelectorDataStream::setSelector
virtual void setSelector(IEvtSelector *pSelector)
Attach event selector object.
Definition
EventSelectorDataStream.cpp:35
EventSelectorDataStream::m_pSvcLocator
ISvcLocator * m_pSvcLocator
Reference to service locator.
Definition
EventSelectorDataStream.h:62
EventSelectorDataStream::m_dbName
std::string m_dbName
String with name of the db as parsed.
Definition
EventSelectorDataStream.h:56
EventSelectorDataStream::m_initialized
bool m_initialized
Initialization state.
Definition
EventSelectorDataStream.h:66
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition
PropertyBase.h:38
Gaudi::Property
Implementation of property with value of concrete type.
Definition
Property.h:35
Gaudi::Utils::AttribStringParser
Parse attribute strings allowing iteration over the various attributes.
Definition
AttribStringParser.h:39
IConversionSvc
Definition
IConversionSvc.h:43
IEvtSelector
The Event Selector Interface.
Definition
IEvtSelector.h:26
IPersistencySvc
Data persistency service interface.
Definition
IPersistencySvc.h:25
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition
ISvcLocator.h:42
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition
MsgStream.h:29
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition
SmartIF.h:28
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isSuccess
bool isSuccess() const
Definition
StatusCode.h:302
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
std
STL namespace.
IDataManagerSvc
Definition
IDataManagerSvc.h:47
GaudiKernel
src
Lib
EventSelectorDataStream.cpp
Generated on
for The Gaudi Framework by
1.17.0