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 
47  : NTupleSvc(name, svc)
48 {
49 }
50 
51 
53 StatusCode TagCollectionSvc::connect(const std::string& ident, std::string& logname) {
54  MsgStream log ( msgSvc(), name() );
55  DataObject* pO = nullptr;
56  StatusCode status = findObject(m_rootName, pO);
57  if ( status.isSuccess() ) {
58  status = INVALID_ROOT;
59  if ( pO->registry() ) {
60  char typ=0;
61  std::vector<Prop> props;
62  long loc = ident.find(" ");
63  std::string filename, svc = "DbCnvSvc";
64  logname = ident.substr(0,loc);
65  using Parser = Gaudi::Utils::AttribStringParser;
66  // we assume that there is always a " "
67  // (but if it is not there, we probably will not match the pattern)
68  for (auto attrib: Parser(ident.substr(loc + 1))) {
69  switch( ::toupper(attrib.tag[0]) ) {
70  case 'A':
71  props.emplace_back( "Server", attrib.value);
72  break;
73  case 'F': /* FILE='<file name>' */
74  case 'D': /* DATAFILE='<file name>' */
75  filename = std::move(attrib.value);
76  break;
77  case 'O': /* OPT='<NEW<CREATE,WRITE>, UPDATE, READ>' */
78  switch( ::toupper(attrib.value[0]) ) {
79  case 'C':
80  case 'N':
81  case 'W': typ = 'N'; break;
82  case 'U': typ = 'U'; break;
83  case 'O':
84  case 'R':
85  switch( ::toupper(attrib.value[2]) ) {
86  case 'C': /* RECREATE */ typ = 'R'; break;
87  case 'A': /* READ */
88  default: typ = 'O'; break;
89  }
90  break;
91  default: typ = 0; break;
92  }
93  break;
94  case 'S': // SVC='<service type>'
95  switch( ::toupper(attrib.tag[1]) ) {
96  case 'V': svc = std::move(attrib.value); break;
97  case 'H':
98  switch(::toupper(attrib.value[0])) {
99  case 'Y':
100  props.emplace_back( "ShareFiles", attrib.value);
101  break ;
102  }
103  break;
104  }
105  break;
106  case 'T': // TYP='<HBOOK,ROOT,OBJY,...>'
107  switch(::toupper(attrib.value[0])) {
108  case 'H':
109  svc = "HbookCnv::ConvSvc";
110  break;
111  case 'P':
112  props.emplace_back( "DbType", attrib.value);
113  svc = "PoolDbCnvSvc";
114  break;
115  default:
116  props.emplace_back( "DbType", attrib.value);
117  svc = "DbCnvSvc";
118  break;
119  }
120  break;
121  default:
122  props.emplace_back( attrib.tag, attrib.value);
123  break;
124  }
125  }
126  if ( 0 != typ ) {
127  IConversionSvc* pSvc = nullptr;
128  status = createService(name()+'.'+logname, svc, props, pSvc);
129  if ( status.isSuccess() ) {
130  status = attachTuple(filename,logname,typ,pSvc->repSvcType());
131  if ( status.isSuccess() ) {
132  m_connections.emplace(m_rootName+'/'+logname,Connection(pSvc));
133  return StatusCode::SUCCESS;
134  }
135  }
136  }
137  }
138  }
139  log << MSG::ERROR << "Cannot add " << ident << " invalid filename!" << endmsg;
140  return StatusCode::FAILURE;
141 }
142 
145  const std::string& typ,
146  const std::vector<Prop>& props,
147  IConversionSvc*& pSvc) {
148  pSvc = nullptr;
150  auto mgr = serviceLocator()->as<ISvcManager>();
151 
152  // TagCollectionSvc has to directly create a ConversionSvc to manage it directly.
153  StatusCode status = NO_INTERFACE;
154  if ( mgr ) {
155  SmartIF<IService> isvc = mgr->createService(TypeNameString(nam, typ));
156  if (isvc) {
157  auto icsvc = isvc.as<IConversionSvc>();
158  if ( icsvc ) {
159  auto iprop = isvc.as<IProperty>();
160  if ( iprop ) {
161  for ( const auto& p : props ) {
162  iprop->setProperty(p.first, p.second).ignore();
163  }
164  // NTupleSvc has to directly create a ConversionSvc to manage it directly.
165  status = isvc->sysInitialize();
166  if ( status.isSuccess() ) {
167  status = icsvc->setDataProvider(this);
168  if ( status.isSuccess() ) {
169  pSvc = icsvc.get();
170  pSvc->addRef();
171  }
172  }
173  }
174  }
175  }
176  }
177  return status;
178 }
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:25
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
The ISvcManager is the interface implemented by the Service Factory in the Application Manager to sup...
Definition: ISvcManager.h:28
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
STL namespace.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
virtual StatusCode sysInitialize()=0
Initialize Service.
StatusCode connect(const std::string &ident, std::string &logname) override
Add file to list I/O list.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:110
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
Gaudi tag collection service definition.
#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:26
virtual StatusCode setProperty(const Property &p)=0
Set the property by property.
NTuple service.
Definition: NTupleSvc.h:24
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
void ignore() const
Definition: StatusCode.h:108
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
StatusCode attachTuple(const std::string &filename, const std::string &logname, const char typ, const long t)
Attach output/input file.
Definition: NTupleSvc.cpp:470
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
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.
Connections m_connections
Container of connection points.
Definition: NTupleSvc.h:126