| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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/SmartIF.h"
26 #include "GaudiKernel/AttribStringParser.h"
27 #include "GaudiKernel/DataObject.h"
28 #include "GaudiKernel/ObjectFactory.h"
29 #include "GaudiKernel/GenericAddress.h"
30
31 #include "GaudiKernel/IProperty.h"
32 #include "GaudiKernel/ISvcManager.h"
33 #include "GaudiKernel/ISvcLocator.h"
34 #include "GaudiKernel/IConversionSvc.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)
47 : NTupleSvc(name, svc)
48 {
49 }
50
51
53 StatusCode TagCollectionSvc::connect(const std::string& ident, std::string& logname) {
54 DataObject* pO = nullptr;
55 StatusCode status = findObject(m_rootName, pO);
56 if ( status.isSuccess() ) {
57 status = INVALID_ROOT;
58 if ( pO->registry() ) {
59 char typ=0;
60 std::vector<Prop> props;
61 long loc = ident.find(" ");
62 std::string filename, svc = "DbCnvSvc";
63 logname = ident.substr(0,loc);
64 using Parser = Gaudi::Utils::AttribStringParser;
65 // we assume that there is always a " "
66 // (but if it is not there, we probably will not match the pattern)
67 for (auto attrib: Parser(ident.substr(loc + 1))) {
68 switch( ::toupper(attrib.tag[0]) ) {
69 case 'A':
70 props.emplace_back( "Server", attrib.value);
71 break;
72 case 'F': /* FILE='<file name>' */
73 case 'D': /* DATAFILE='<file name>' */
74 filename = std::move(attrib.value);
75 break;
76 case 'O': /* OPT='<NEW<CREATE,WRITE>, UPDATE, READ>' */
77 switch( ::toupper(attrib.value[0]) ) {
78 case 'C':
79 case 'N':
80 case 'W': typ = 'N'; break;
81 case 'U': typ = 'U'; break;
82 case 'O':
83 case 'R':
84 switch( ::toupper(attrib.value[2]) ) {
85 case 'C': /* RECREATE */ typ = 'R'; break;
86 case 'A': /* READ */
87 default: typ = 'O'; break;
88 }
89 break;
90 default: typ = 0; break;
91 }
92 break;
93 case 'S': // SVC='<service type>'
94 switch( ::toupper(attrib.tag[1]) ) {
95 case 'V': svc = std::move(attrib.value); break;
96 case 'H':
97 switch(::toupper(attrib.value[0])) {
98 case 'Y':
99 props.emplace_back( "ShareFiles", attrib.value);
100 break ;
101 }
102 break;
103 }
104 break;
105 case 'T': // TYP='<HBOOK,ROOT,OBJY,...>'
106 switch(::toupper(attrib.value[0])) {
107 case 'H':
108 svc = "HbookCnv::ConvSvc";
109 break;
110 case 'P':
111 props.emplace_back( "DbType", attrib.value);
112 svc = "PoolDbCnvSvc";
113 break;
114 default:
115 props.emplace_back( "DbType", attrib.value);
116 svc = "DbCnvSvc";
117 break;
118 }
119 break;
120 default:
121 props.emplace_back( attrib.tag, attrib.value);
122 break;
123 }
124 }
125 if ( 0 != typ ) {
126 IConversionSvc* pSvc = nullptr;
127 status = createService(name()+'.'+logname, svc, props, pSvc);
128 if ( status.isSuccess() ) {
129 status = attachTuple(filename,logname,typ,pSvc->repSvcType());
130 if ( status.isSuccess() ) {
131 m_connections.emplace(m_rootName+'/'+logname,Connection(pSvc));
132 return StatusCode::SUCCESS;
133 }
134 }
135 }
136 }
137 }
138 error() << "Cannot add " << ident << " invalid filename!" << endmsg;
139 return StatusCode::FAILURE;
140 }
141
143 StatusCode TagCollectionSvc::createService( const std::string& nam,
144 const std::string& typ,
145 const std::vector<Prop>& props,
146 IConversionSvc*& pSvc) {
147 pSvc = nullptr;
148 using Gaudi::Utils::TypeNameString;
149 auto mgr = serviceLocator()->as<ISvcManager>();
150
151 // TagCollectionSvc has to directly create a ConversionSvc to manage it directly.
152 StatusCode status = NO_INTERFACE;
153 if ( mgr ) {
154 SmartIF<IService> isvc = mgr->createService(TypeNameString(nam, typ));
155 if (isvc) {
156 auto icsvc = isvc.as<IConversionSvc>();
157 if ( icsvc ) {
158 auto iprop = isvc.as<IProperty>();
159 if ( iprop ) {
160 for ( const auto& p : props ) {
161 iprop->setProperty(p.first, p.second).ignore();
162 }
163 // NTupleSvc has to directly create a ConversionSvc to manage it directly.
164 status = isvc->sysInitialize();
165 if ( status.isSuccess() ) {
166 status = icsvc->setDataProvider(this);
167 if ( status.isSuccess() ) {
168 pSvc = icsvc.get();
169 pSvc->addRef();
170 }
171 }
172 }
173 }
174 }
175 }
176 return status;
177 }
Gaudi::Utils::AttribStringParser
Parse attribute strings allowing iteration over the various attributes.
Definition: AttribStringParser.h:30
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:28
StatusCode::FAILURE
Definition: StatusCode.h:29
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:74
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:106
graphanalysis.filename
string filename
Definition: graphanalysis.py:109
ISvcManager.h
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
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:53
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
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:110
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
DataSvc::findObject
StatusCode findObject(const std::string &fullPath, DataObject *&pObject) override
Find object identified by its full path in the data store.
Definition: DataSvc.cpp:828
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::ignore
void ignore() const
Definition: StatusCode.h:106
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
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:244
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:143
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