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