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
44 
45 TagCollectionSvc::TagCollectionSvc(const std::string& name, ISvcLocator* svc)
47  : NTupleSvc(name, svc)
48 {
49 }
50 
53 }
54 
58  return status;
59 }
60 
64  return status;
65 }
66 
68 StatusCode TagCollectionSvc::connect(const std::string& ident, std::string& logname) {
69  MsgStream log ( msgSvc(), name() );
70  DataObject* pO = 0;
71  StatusCode status = findObject(m_rootName, pO);
72  if ( status.isSuccess() ) {
73  status = INVALID_ROOT;
74  if ( 0 != pO->registry() ) {
75  char typ=0;
76  std::vector<Prop> props;
77  long loc = ident.find(" ");
78  std::string filename, auth, svc = "DbCnvSvc";
79  logname = ident.substr(0,loc);
80  using Parser = Gaudi::Utils::AttribStringParser;
81  // we assume that there is always a " "
82  // (but if it is not there, we probably will not match the pattern)
83  for (auto attrib: Parser(ident.substr(loc + 1))) {
84  switch( ::toupper(attrib.tag[0]) ) {
85  case 'A':
86  props.push_back( Prop("Server", attrib.value));
87  break;
88  case 'F': /* FILE='<file name>' */
89  case 'D': /* DATAFILE='<file name>' */
90  filename = std::move(attrib.value);
91  break;
92  case 'O': /* OPT='<NEW<CREATE,WRITE>, UPDATE, READ>' */
93  switch( ::toupper(attrib.value[0]) ) {
94  case 'C':
95  case 'N':
96  case 'W': typ = 'N'; break;
97  case 'U': typ = 'U'; break;
98  case 'O':
99  case 'R':
100  switch( ::toupper(attrib.value[2]) ) {
101  case 'C': /* RECREATE */ typ = 'R'; break;
102  case 'A': /* READ */
103  default: typ = 'O'; break;
104  }
105  break;
106  default: typ = 0; break;
107  }
108  break;
109  case 'S': // SVC='<service type>'
110  switch( ::toupper(attrib.tag[1]) ) {
111  case 'V': svc = std::move(attrib.value); break;
112  case 'H':
113  switch(::toupper(attrib.value[0])) {
114  case 'Y':
115  props.push_back( Prop("ShareFiles", attrib.value));
116  break ;
117  }
118  break;
119  }
120  break;
121  case 'T': // TYP='<HBOOK,ROOT,OBJY,...>'
122  switch(::toupper(attrib.value[0])) {
123  case 'H':
124  svc = "HbookCnv::ConvSvc";
125  break;
126  case 'P':
127  props.push_back( Prop("DbType", attrib.value));
128  svc = "PoolDbCnvSvc";
129  break;
130  default:
131  props.push_back( Prop("DbType", attrib.value));
132  svc = "DbCnvSvc";
133  break;
134  }
135  break;
136  default:
137  props.push_back( Prop(attrib.tag, attrib.value));
138  break;
139  }
140  }
141  if ( 0 != typ ) {
142  IConversionSvc* pSvc = 0;
143  status = createService(name()+'.'+logname, svc, props, pSvc);
144  if ( status.isSuccess() ) {
145  status = attachTuple(filename,logname,typ,pSvc->repSvcType());
146  if ( status.isSuccess() ) {
147  m_connections.insert(Connections::value_type(m_rootName+'/'+logname,Connection(pSvc)));
148  return StatusCode::SUCCESS;
149  }
150  }
151  }
152  }
153  }
154  log << MSG::ERROR << "Cannot add " << ident << " invalid filename!" << endmsg;
155  return StatusCode::FAILURE;
156 }
157 
160  const std::string& typ,
161  const std::vector<Prop>& props,
162  IConversionSvc*& pSvc) {
165 
166  // TagCollectionSvc has to directly create a ConversionSvc to manage it directly.
167  StatusCode status = NO_INTERFACE;
168  if ( mgr.isValid() ) {
169 
170  SmartIF<IService> &isvc = mgr->createService(TypeNameString(nam, typ));
171  if (isvc.isValid()) {
172  status = isvc->queryInterface(IConversionSvc::interfaceID(), (void**)&pSvc);
173  if ( status.isSuccess() ) {
174  SmartIF<IProperty> iprop(isvc);
175  status = NO_INTERFACE;
176  if ( iprop.isValid( ) ) {
177  for ( std::vector<Prop>::const_iterator j = props.begin(); j != props.end(); j++) {
178  iprop->setProperty(StringProperty((*j).first, (*j).second)).ignore();
179  }
180  // NTupleSvc has to directly create a ConversionSvc to manage it directly.
181  status = isvc->sysInitialize();
182  if ( status.isSuccess() ) {
183  status = pSvc->setDataProvider(this);
184  if ( status.isSuccess() ) {
185  return status;
186  }
187  }
188  }
189  pSvc->release();
190  }
191  }
192  }
193  pSvc = 0;
194  return status;
195 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
virtual StatusCode findObject(const std::string &fullPath, DataObject *&pObject)
Find object identified by its full path in the data store.
Definition: DataSvc.cpp:855
virtual StatusCode finalize()
DataSvc overrides: stop the service.
Definition: NTupleSvc.cpp:217
virtual StatusCode initialize()
DataSvc overrides: Initialize the service.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
std::string m_rootName
Name of root event.
Definition: DataSvc.h:50
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
STL namespace.
Invalid root path object cannot be retrieved or stored.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:69
virtual StatusCode sysInitialize()=0
Initialize Service.
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
std::pair< std::string, std::string > Prop
Definition: NTupleSvc.h:36
Gaudi tag collection service definition.
virtual StatusCode finalize()
DataSvc overrides: stop the service.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
virtual long repSvcType() const =0
Retrieve the class type of the data store the converter uses.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype)=0
Creates and instance of a service type that has been declared beforehand and assigns it a name...
Requested interface is not available.
Definition: IInterface.h:221
virtual StatusCode setProperty(const Property &p)=0
Set the property by property.
SimpleProperty< std::string > StringProperty
Definition: Property.h:743
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
virtual ~TagCollectionSvc()
Standard Destructor.
virtual unsigned long release()=0
Release Interface instance.
NTuple service.
Definition: NTupleSvc.h:25
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
virtual StatusCode initialize()
DataSvc overrides: Initialize the service.
Definition: NTupleSvc.cpp:76
virtual StatusCode connect(const std::string &ident, std::string &logname)
Add file to list I/O list.
void ignore() const
Definition: StatusCode.h:107
StatusCode attachTuple(const std::string &filename, const std::string &logname, const char typ, const long t)
Attach output/input file.
Definition: NTupleSvc.cpp:494
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:171
void toupper(std::string &s)
virtual StatusCode createService(const std::string &nam, const std::string &typ, const std::vector< Prop > &props, IConversionSvc *&pSvc)
Create conversion service.
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:334
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
Connections m_connections
Container of connection points.
Definition: NTupleSvc.h:127