22 #define GAUDISVC_NTUPLESVC_CPP
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"
31 #include "GaudiKernel/IProperty.h"
32 #include "GaudiKernel/ISvcLocator.h"
33 #include "GaudiKernel/IDataSelector.h"
35 #include "GaudiKernel/Property.h"
36 #include "GaudiKernel/Selector.h"
37 #include "GaudiKernel/MsgStream.h"
38 #include "GaudiKernel/ConversionSvc.h"
39 #include "GaudiKernel/DataSelectionAgent.h"
40 #include "GaudiKernel/NTupleImplementation.h"
54 inline std::string
toStr(
long id) {
55 std::ostringstream
s; s << id;
64 declareProperty(
"Input",
m_input);
66 m_rootName =
"/NTUPLES";
67 m_rootCLID = CLID_DataObject;
78 status = setProperties();
82 status = setRoot(m_rootName, root);
109 if ( !pRegistry )
return nullptr;
111 auto len = m_rootName.length();
113 std::string
path = (idx==std::string::npos) ? full : full.substr(0, idx);
120 typedef std::vector<IRegistry*> Leaves;
121 long need_update = 0;
128 iret = objectLeaves(pO, leaves);
131 for (
auto d = leaves.begin(); d != leaves.end(); d++ ) {
132 if ( !(*d)->object() )
continue;
135 unsigned long typ = pA->
ipar()[1];
136 if ( typ !=
'R' && typ !=
'N' && typ !=
'U' )
continue;
139 if ( !svc )
continue;
144 traverseSubTree ( (*d)->object(), &agent ).ignore();
145 for(
int i = sel->size()-1;
i >= 0;
i-- ) {
153 for(
int j = sel->size()-1; j >= 0; j-- ) {
157 if ( !status.
isSuccess() ) iret = status;
159 if ( iret.
isSuccess() ) need_update += sel->size();
167 else if ( need_update > 0 ) {
176 if ( isvc ) isvc->finalize().ignore();
195 m_connections.clear();
202 status = clearStore();
210 return connect(ident, logName);
216 StatusCode status = findObject(m_rootName, pO);
219 std::vector<Prop> props;
220 long loc = ident.find(
" ");
221 std::string
filename, auth, svc =
"", db_typ =
"";
222 logname = ident.substr(0, loc);
223 using Parser = Gaudi::Utils::AttribStringParser;
226 for (
auto attrib: Parser(ident.substr(loc + 1))) {
227 switch( ::
toupper(attrib.tag[0]) ) {
232 filename = std::move(attrib.value);
235 switch( ::
toupper(attrib.value[0]) ) {
254 db_typ = std::move(attrib.value);
257 props.emplace_back( attrib.tag, attrib.value);
273 log <<
MSG::ERROR <<
"Cannot add " << ident <<
" invalid filename!" <<
endmsg;
278 const std::string& typ,
279 const std::vector<Prop>& ,
285 auto appPropMgr = serviceLocator()->as<
IProperty>();
293 StatusCode sts = appPropMgr->getProperty( &sp );
295 log <<
MSG::ERROR <<
"Could not get NTuple Persistency format"
296 <<
" from ApplicationMgr properties" <<
endmsg;
301 if ( sp.
value() ==
"HBOOK" ) {
304 else if ( sp.
value() ==
"ROOT" ) {
312 if ( !typ.empty() && typ != sp.
value() ) {
315 <<
"Type given by job option "
316 <<
"NTupleSvc.Input/Output ignored!" <<
endmsg;
332 auto status = pService->sysInitialize();
333 if ( !status.isSuccess() )
return status;
341 if ( typ == CLID_ColumnWiseTuple ) {
344 else if ( typ == CLID_RowWiseTuple ) {
361 std::string
path = fullPath;
368 StatusCode status = retrieveObject(path, pObj);
370 log <<
MSG::ERROR <<
"Cannot book N-tuple " << path <<
" (Exists already)" <<
endmsg;
374 if ( sep == std::string::npos ) {
375 log <<
MSG::ERROR <<
"Cannot book N-tuple " << path <<
" (Invalid path)" <<
endmsg;
379 std::string p_path (path, 0, sep);
380 std::string o_path (path, sep, path.length());
383 log <<
MSG::ERROR <<
"Cannot book N-tuple " << path <<
" (Invalid parent directory)" <<
endmsg;
389 log <<
MSG::ERROR <<
"Cannot book N-tuple " << path <<
" (Unknown reason)" <<
endmsg;
396 std::string full = dirPath;
399 return book(full, type, title);
404 return book( dirPath,
toStr(
id), type, title);
411 StatusCode status = findObject(pParent, relPath, *pp_cast<DataObject>(&pObj));
414 status =
create( type, title, pObj);
417 status = registerObject(pParent, relPath, pObj);
429 const std::string& title) {
430 return book( pParent,
toStr(
id), type, title);
435 const std::string& relPath) {
440 if (relPath[0]!=
'/') full +=
"/";
460 std::string full = dirPath;
461 if (relPath[0]!=
'/') full +=
"/";
470 StatusCode status = retrieveObject(m_rootName, p);
473 std::string entryname = m_rootName;
475 entryname += logname;
477 new GenericAddress(t, CLID_NTupleFile, filename, entryname, 0, typ);
478 status = registerAddress(p, logname, pA);
480 log <<
MSG::INFO <<
"Added stream file:" << filename <<
" as " << logname <<
endmsg;
485 log <<
MSG::ERROR <<
"Cannot add file:" << filename <<
" as " << logname <<
endmsg;
492 StatusCode status = findObject(fullPath, *pp_cast<DataObject>(&p));
495 if ( sep2 != std::string::npos ) {
496 std::string relPath = fullPath.substr(0, sep2);
501 status = registerObject(fullPath, p);
534 StatusCode status = findObject(fullPath, *pp_cast<DataObject>(&pObj));
535 return status.
isSuccess() ?
save ( pObj ) : INVALID_OBJ_PATH;
545 if ( pSvc && pReg ) {
558 return INVALID_OBJECT;
564 StatusCode status = findObject(pParent, relPath, *pp_cast<DataObject>(&pObj));
565 return status.
isSuccess() ?
save ( pObj ) : INVALID_OBJ_PATH;
593 return INVALID_OBJECT;
599 StatusCode status = findObject(fullPath, *pp_cast<DataObject>(&pObj));
606 StatusCode status = findObject(pParent, relPath, *pp_cast<DataObject>(&pObj));
624 status = pSvc->
updateObj(pAddr, n_tuple);
633 status = INVALID_OBJECT;
642 StatusCode status = findObject(fullPath, *pp_cast<DataObject>(&pObj));
649 StatusCode status = findObject(pParent, relPath, *pp_cast<DataObject>(&pObj));
void releaseConnection(Connection &c)
Finalize single service.
Definition of the MsgStream class used to transmit messages.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
#define DECLARE_NAMESPACE_OBJECT_FACTORY(n, x)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
DataSelectionAgent base in charge of collecting all the refereces to DataObjects in a transient store...
virtual StatusCode finalize()
DataSvc overrides: stop the service.
virtual StatusCode save(const std::string &fullPath)
Save N tuple to disk. Must be called in order to close the ntuple file properly.
bool isSuccess() const
Test for a status code of SUCCESS.
unsigned long release() override
release reference to object
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
No data loader available.
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)=0
Convert the transient object to the requested representation.
Generic Transient Address.
virtual NTuple::Directory * createDirectory(DataObject *pParent, const std::string &title)
Create Ntuple directory and register it with the data store.
virtual StatusCode readRecord(NTuple::Tuple *tuple)
Read single record from N tuple.
virtual StatusCode updateRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the references of an already converted object.
std::vector< DataObject * > IDataSelector
This is only a placeholder to allow me compiling until the responsible guy does his work! M...
IRegistry * registry() const
Get pointer to Registry.
StatusCode updateDirectories()
Update directory data.
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject)=0
Update the transient object from the other representation.
StatusCode createService(const std::string &nam, const std::string &typ, const std::vector< Prop > &props, IConversionSvc *&pSvc)
Create conversion service.
IDataSelector * selectedObjects()
Return the set of selected DataObjects.
const char * toStr(IAuditor::StandardEventType e)
Simple mapping function from IAuditor::StandardEventType to string.
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.
#define DECLARE_COMPONENT(type)
Definition of the basic interface.
virtual StatusCode reinitialize()
DataSvc overrides: reinitialize service.
const long TEST_StorageType
virtual StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the references of an updated transient object.
NTupleSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
StatusCode finalize() override
Service initialization.
virtual StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the converted representation of a transient object.
virtual StatusCode connect(const std::string &ident)
Add file to list I/O list.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
virtual NTuple::Tuple * book(const std::string &fullPath, const CLID &type, const std::string &title)
Book Ntuple and register it with the data store.
const TYPE & value() const
explicit conversion
DBaseEntries m_input
Input streams.
const long HBOOK_StorageType
Abstract base class which allows the user to interact with the actual N tuple implementation.
virtual StatusCode writeRecord(NTuple::Tuple *tuple)
Write single record to N tuple.
virtual IConversionSvc * getDataLoader(IRegistry *pReg)
DataSvc overrides: Retrieve data loader.
virtual unsigned long release()
release reference to object
virtual unsigned long release()=0
Release Interface instance.
Base class used to extend a class implementing other interfaces.
StatusCode initialize() override
Service initialization.
virtual void setAddress(IOpaqueAddress *pAddress)=0
Set/Update Opaque storage address.
void setTupleService(INTupleSvc *svc)
Access conversion service.
DBaseEntries m_output
Output streams.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
virtual NTuple::Tuple * access(const std::string &fullPath, const std::string &filename)
Access N tuple on disk.
virtual StatusCode create(const CLID &typ, const std::string &title, NTuple::Tuple *&refpTuple)
Create requested N tuple (Hide constructor)
virtual StatusCode initialize()
DataSvc overrides: Initialize the service.
virtual const id_type & identifier() const =0
Full identifier (or key)
void setConversionService(IConversionSvc *svc)
Access conversion service.
Opaque address interface definition.
Base class for all conversion services.
unsigned int CLID
Class ID definition.
The IProperty is the basic interface for all components which have properties that can be set or get...
StatusCode attachTuple(const std::string &filename, const std::string &logname, const char typ, const long t)
Attach output/input file.
virtual StatusCode disconnect(const std::string &nam)
Close open connection.
virtual StatusCode disconnectAll()
Close all open connections.
A DataObject is the base class of any identifiable object on any data store.
Small class representing an N tuple directory in the transient store.
virtual bool isConnected(const std::string &identifier) const
Check if a datasource is connected.
virtual ~NTupleSvc()
Standard Destructor.
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Resolve the references of the converted object.
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
void toupper(std::string &s)
IConversionSvc * conversionService() const
Access conversion service.
const long ROOT_StorageType
Connections m_connections
Container of connection points.