| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

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 {
51 DataObject* pO = nullptr;
52 StatusCode status = findObject( m_rootName.value(), pO );
53 if ( status.isSuccess() ) {
54 status = INVALID_ROOT;
55 if ( pO->registry() ) {
56 char typ = 0;
57 std::vector<Prop> props;
58 long loc = ident.find( " " );
59 std::string filename, svc = "DbCnvSvc";
60 logname = ident.substr( 0, loc );
61 using Parser = Gaudi::Utils::AttribStringParser;
62 // we assume that there is always a " "
63 // (but if it is not there, we probably will not match the pattern)
64 for ( auto attrib : Parser( ident.substr( loc + 1 ) ) ) {
65 switch (::toupper( attrib.tag[0] ) ) {
66 case 'A':
67 props.emplace_back( "Server", attrib.value );
68 break;
69 case 'F': /* FILE='<file name>' */
70 case 'D': /* DATAFILE='<file name>' */
71 filename = std::move( attrib.value );
72 break;
73 case 'O': /* OPT='<NEW<CREATE,WRITE>, UPDATE, READ>' */
74 switch (::toupper( attrib.value[0] ) ) {
75 case 'C':
76 case 'N':
77 case 'W':
78 typ = 'N';
79 break;
80 case 'U':
81 typ = 'U';
82 break;
83 case 'O':
84 case 'R':
85 switch (::toupper( attrib.value[2] ) ) {
86 case 'C': /* RECREATE */
87 typ = 'R';
88 break;
89 case 'A': /* READ */
90 default:
91 typ = 'O';
92 break;
93 }
94 break;
95 default:
96 typ = 0;
97 break;
98 }
99 break;
100 case 'S': // SVC='<service type>'
101 switch (::toupper( attrib.tag[1] ) ) {
102 case 'V':
103 svc = std::move( attrib.value );
104 break;
105 case 'H':
106 switch (::toupper( attrib.value[0] ) ) {
107 case 'Y':
108 props.emplace_back( "ShareFiles", attrib.value );
109 break;
110 }
111 break;
112 }
113 break;
114 case 'T': // TYP='<HBOOK,ROOT,OBJY,...>'
115 switch (::toupper( attrib.value[0] ) ) {
116 case 'H':
117 svc = "HbookCnv::ConvSvc";
118 break;
119 case 'P':
120 props.emplace_back( "DbType", attrib.value );
121 svc = "PoolDbCnvSvc";
122 break;
123 default:
124 props.emplace_back( "DbType", attrib.value );
125 svc = "DbCnvSvc";
126 break;
127 }
128 break;
129 default:
130 props.emplace_back( attrib.tag, attrib.value );
131 break;
132 }
133 }
134 if ( 0 != typ ) {
135 IConversionSvc* pSvc = nullptr;
136 status = createService( name() + '.' + logname, svc, props, pSvc );
137 if ( status.isSuccess() ) {
138 status = attachTuple( filename, logname, typ, pSvc->repSvcType() );
139 if ( status.isSuccess() ) {
140 m_connections.emplace( m_rootName + '/' + logname, Connection( pSvc ) );
141 return StatusCode::SUCCESS;
142 }
143 }
144 }
145 }
146 }
147 error() << "Cannot add " << ident << " invalid filename!" << endmsg;
148 return StatusCode::FAILURE;
149 }
150
152 StatusCode TagCollectionSvc::createService( const std::string& nam, const std::string& typ,
153 const std::vector<Prop>& props, IConversionSvc*& pSvc )
154 {
155 pSvc = nullptr;
156 using Gaudi::Utils::TypeNameString;
157 auto mgr = serviceLocator()->as<ISvcManager>();
158
159 // TagCollectionSvc has to directly create a ConversionSvc to manage it directly.
160 StatusCode status = NO_INTERFACE;
161 if ( mgr ) {
162 SmartIF<IService> isvc = mgr->createService( TypeNameString( nam, typ ) );
163 if ( isvc ) {
164 auto icsvc = isvc.as<IConversionSvc>();
165 if ( icsvc ) {
166 auto iprop = isvc.as<IProperty>();
167 if ( iprop ) {
168 for ( const auto& p : props ) {
169 iprop->setProperty( p.first, p.second ).ignore();
170 }
171 // NTupleSvc has to directly create a ConversionSvc to manage it directly.
172 status = isvc->sysInitialize();
173 if ( status.isSuccess() ) {
174 status = icsvc->setDataProvider( this );
175 if ( status.isSuccess() ) {
176 pSvc = icsvc.get();
177 pSvc->addRef();
178 }
179 }
180 }
181 }
182 }
183 }
184 return status;
185 }
Gaudi::Utils::AttribStringParser
Parse attribute strings allowing iteration over the various attributes.
Definition: AttribStringParser.h:32
StatusCode::SUCCESS
Definition: StatusCode.h:29
SmartIF< IService >
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
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
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
ObjectFactory.h
DataSvc::m_rootName
Gaudi::Property< std::string > m_rootName
Definition: DataSvc.h:57
std
STL namespace.
ISvcLocator::as
SmartIF< IFace > as()
Definition: ISvcLocator.h:109
graphanalysis.filename
string filename
Definition: graphanalysis.py:117
ISvcManager.h
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:73
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
std::string
STL class.
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
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
IProperty::setProperty
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:115
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:12
TagCollectionSvc
Gaudi tag collection service definition.
Definition: TagCollectionSvc.h:26
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
SmartIF.h
std::move
T move(T...args)
TagCollectionSvc.h
std::string::find
T find(T...args)
IProperty.h
std::vector
STL class.
IConverter::repSvcType
virtual long repSvcType() const =0
Retrieve the class type of the data store the converter uses.
NTupleSvc
NTuple service.
Definition: NTupleSvc.h:23
IConversionSvc.h
NTupleSvc::Connection
Definition: NTupleSvc.h:26
Property.h
std::map::emplace
T emplace(T...args)
AttribStringParser.h
IInterface::addRef
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
std::string::substr
T substr(T...args)
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:84
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:462
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
GenericAddress.h
ISvcLocator.h
DataSvc::findObject
StatusCode findObject(boost::string_ref fullPath, DataObject *&pObject) override
Find object identified by its full path in the data store.
Definition: DataSvc.cpp:795
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:292
toupper
void toupper(std::string &s)
Definition: StatusCodeSvc.cpp:10
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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:152
DataObject.h
std::vector::emplace_back
T emplace_back(T...args)
NTupleSvc::m_connections
Connections m_connections
Container of connection points.
Definition: NTupleSvc.h:122