| The Gaudi Framework v32r1 (f65d50dc)

TagCollectionSvc.cpp
Go to the documentation of this file.
1 //====================================================================
2 // TagCollectionSvc.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : GaudiSvc/TagCollectionSvc ( The LHCb Offline System)
6 //
7 // Description: implementation of the NTuple service
8 //
9 // Author : M.Frank
10 // History :
11 // +---------+----------------------------------------------+---------
12 // | Date | Comment | Who
13 // +---------+----------------------------------------------+---------
14 // | 29/10/98| Initial version | MF
15 // | 29/09/99| Added access to ICnvManager for missing |
16 // | | converters | MF
17 // | 20/09/00| Connect dynamically to conversion service |
18 // | | for N-tuple persistency | MF
19 // +---------+----------------------------------------------+---------
20 //
21 //====================================================================
22 #define GAUDISVC_TAGCOLLECTIONSVC_CPP
23
24 // Framework include files
25 #include "GaudiKernel/AttribStringParser.h"
26 #include "GaudiKernel/DataObject.h"
27 #include "GaudiKernel/GenericAddress.h"
28 #include "GaudiKernel/ObjectFactory.h"
29 #include "GaudiKernel/SmartIF.h"
30
31 #include "GaudiKernel/IConversionSvc.h"
32 #include "GaudiKernel/IProperty.h"
33 #include "GaudiKernel/ISvcLocator.h"
34 #include "GaudiKernel/ISvcManager.h"
35
36 #include "GaudiKernel/MsgStream.h"
37 #include "GaudiKernel/Property.h"
38
39 #include "TagCollectionSvc.h"
40
41 // Instantiation of a static factory class used by clients to create
42 // instances of this service
43 DECLARE_COMPONENT( TagCollectionSvc )
44
45 TagCollectionSvc::TagCollectionSvc( const std::string& name, ISvcLocator* svc ) : NTupleSvc( name, svc ) {}
47
49 StatusCode TagCollectionSvc::connect( const std::string& ident, std::string& logname ) {
50 DataObject* pO = nullptr;
51 StatusCode status = findObject( m_rootName.value(), pO );
52 if ( status.isSuccess() ) {
53 status = Status::INVALID_ROOT;
54 if ( pO->registry() ) {
55 char typ = 0;
56 std::vector<Prop> props;
57 long loc = ident.find( " " );
58 std::string filename, svc = "DbCnvSvc";
59 logname = ident.substr( 0, loc );
60 using Parser = Gaudi::Utils::AttribStringParser;
61 // we assume that there is always a " "
62 // (but if it is not there, we probably will not match the pattern)
63 for ( auto attrib : Parser( ident.substr( loc + 1 ) ) ) {
64 switch ( ::toupper( attrib.tag[0] ) ) {
65 case 'A':
66 props.emplace_back( "Server", attrib.value );
67 break;
68 case 'F': /* FILE='<file name>' */
69 case 'D': /* DATAFILE='<file name>' */
70 filename = std::move( attrib.value );
71 break;
72 case 'O': /* OPT='<NEW<CREATE,WRITE>, UPDATE, READ>' */
73 switch ( ::toupper( attrib.value[0] ) ) {
74 case 'C':
75 case 'N':
76 case 'W':
77 typ = 'N';
78 break;
79 case 'U':
80 typ = 'U';
81 break;
82 case 'O':
83 case 'R':
84 switch ( ::toupper( attrib.value[2] ) ) {
85 case 'C': /* RECREATE */
86 typ = 'R';
87 break;
88 case 'A': /* READ */
89 default:
90 typ = 'O';
91 break;
92 }
93 break;
94 default:
95 typ = 0;
96 break;
97 }
98 break;
99 case 'S': // SVC='<service type>'
100 switch ( ::toupper( attrib.tag[1] ) ) {
101 case 'V':
102 svc = std::move( attrib.value );
103 break;
104 case 'H':
105 switch ( ::toupper( attrib.value[0] ) ) {
106 case 'Y':
107 props.emplace_back( "ShareFiles", attrib.value );
108 break;
109 }
110 break;
111 }
112 break;
113 case 'T': // TYP='<HBOOK,ROOT,OBJY,...>'
114 switch ( ::toupper( attrib.value[0] ) ) {
115 case 'H':
116 svc = "HbookCnv::ConvSvc";
117 break;
118 case 'P':
119 props.emplace_back( "DbType", attrib.value );
120 svc = "PoolDbCnvSvc";
121 break;
122 default:
123 props.emplace_back( "DbType", attrib.value );
124 svc = "DbCnvSvc";
125 break;
126 }
127 break;
128 default:
129 props.emplace_back( attrib.tag, attrib.value );
130 break;
131 }
132 }
133 if ( 0 != typ ) {
134 IConversionSvc* pSvc = nullptr;
135 status = createService( name() + '.' + logname, svc, props, pSvc );
136 if ( status.isSuccess() ) {
137 status = attachTuple( filename, logname, typ, pSvc->repSvcType() );
138 if ( status.isSuccess() ) {
139 m_connections.emplace( m_rootName + '/' + logname, Connection( pSvc ) );
140 return StatusCode::SUCCESS;
141 }
142 }
143 }
144 }
145 }
146 error() << "Cannot add " << ident << " invalid filename!" << endmsg;
147 return StatusCode::FAILURE;
148 }
149
151 StatusCode TagCollectionSvc::createService( const std::string& nam, const std::string& typ,
152 const std::vector<Prop>& props, IConversionSvc*& pSvc ) {
153 pSvc = nullptr;
154 using Gaudi::Utils::TypeNameString;
155 auto mgr = serviceLocator()->as<ISvcManager>();
156
157 // TagCollectionSvc has to directly create a ConversionSvc to manage it directly.
158 StatusCode status = IInterface::Status::NO_INTERFACE;
159 if ( mgr ) {
160 SmartIF<IService> isvc = mgr->createService( TypeNameString( nam, typ ) );
161 if ( isvc ) {
162 auto icsvc = isvc.as<IConversionSvc>();
163 if ( icsvc ) {
164 auto iprop = isvc.as<IProperty>();
165 if ( iprop ) {
166 for ( const auto& p : props ) { iprop->setProperty( p.first, p.second ).ignore(); }
167 // NTupleSvc has to directly create a ConversionSvc to manage it directly.
168 status = isvc->sysInitialize();
169 if ( status.isSuccess() ) {
170 status = icsvc->setDataProvider( this );
171 if ( status.isSuccess() ) {
172 pSvc = icsvc.get();
173 pSvc->addRef();
174 }
175 }
176 }
177 }
178 }
179 }
180 return status;
181 }
Gaudi::Utils::AttribStringParser
Parse attribute strings allowing iteration over the various attributes.
Definition: AttribStringParser.h:30
IInterface::Status::NO_INTERFACE
Requested interface is not available.
SmartIF< IService >
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:277
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
IConversionSvc
Definition: IConversionSvc.h:37
MsgStream.h
ISvcManager
The ISvcManager is the interface implemented by the Service Factory in the Application Manager to sup...
Definition: ISvcManager.h:28
ObjectFactory.h
DataSvc::m_rootName
Gaudi::Property< std::string > m_rootName
Definition: DataSvc.h:52
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:107
NTupleSvc::m_connections
std::map< std::string, Connection > m_connections
Container of connection points.
Definition: NTupleSvc.h:118
ISvcLocator::as
SmartIF< IFace > as()
Definition: ISvcLocator.h:103
graphanalysis.filename
string filename
Definition: graphanalysis.py:119
ISvcManager.h
std::string
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
IService::sysInitialize
virtual StatusCode sysInitialize()=0
Initialize Service.
TagCollectionSvc::connect
StatusCode connect(const std::string &ident, std::string &logname) override
Add file to list I/O list.
Definition: TagCollectionSvc.cpp:49
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
IProperty::setProperty
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:10
TagCollectionSvc
Gaudi tag collection service definition.
Definition: TagCollectionSvc.h:26
IConverter::repSvcType
virtual long repSvcType() const =0
Retrieve the class type of the data store the converter uses.
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
SmartIF.h
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
std::move
T move(T... args)
TagCollectionSvc.h
std::string::find
T find(T... args)
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
IProperty.h
std::vector
STL class.
NTupleSvc
NTuple service.
Definition: NTupleSvc.h:23
IConversionSvc.h
NTupleSvc::Connection
Definition: NTupleSvc.h:25
Property.h
AttribStringParser.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
IInterface::addRef
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
std::string::substr
T substr(T... args)
DataSvc::findObject
StatusCode findObject(std::string_view fullPath, DataObject *&pObject) override
Find object identified by its full path in the data store.
Definition: DataSvc.cpp:640
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:20
NTupleSvc::attachTuple
StatusCode attachTuple(const std::string &filename, const std::string &logname, const char typ, const long t)
Attach output/input file.
Definition: NTupleSvc.cpp:426
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
GenericAddress.h
ISvcLocator.h
toupper
void toupper(std::string &s)
Definition: StatusCodeSvc.cpp:7
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
TagCollectionSvc::TagCollectionSvc
TagCollectionSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: TagCollectionSvc.cpp:46
TagCollectionSvc::createService
virtual StatusCode createService(const std::string &nam, const std::string &typ, const std::vector< Prop > &props, IConversionSvc *&pSvc)
Create conversion service.
Definition: TagCollectionSvc.cpp:151
DataObject.h
std::vector::emplace_back
T emplace_back(T... args)