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);
89 for ( DBaseEntries::iterator j =
m_input.begin(); j !=
m_input.end(); ++j ) {
113 if ( !pRegistry )
return nullptr;
115 auto len = m_rootName.length();
117 std::string
path = (idx==std::string::npos) ? full : full.substr(0, idx);
124 typedef std::vector<IRegistry*> Leaves;
125 long need_update = 0;
132 iret = objectLeaves(pO, leaves);
135 for (
auto d = leaves.begin(); d != leaves.end(); d++ ) {
136 if ( !(*d)->object() )
continue;
139 unsigned long typ = pA->
ipar()[1];
140 if ( typ !=
'R' && typ !=
'N' && typ !=
'U' )
continue;
143 if ( !svc )
continue;
148 traverseSubTree ( (*d)->object(), &agent ).ignore();
149 for(
int i = sel->size()-1;
i >= 0;
i-- ) {
157 for(
int j = sel->size()-1; j >= 0; j-- ) {
161 if ( !status.
isSuccess() ) iret = status;
163 if ( iret.
isSuccess() ) need_update += sel->size();
171 else if ( need_update > 0 ) {
180 if ( isvc ) isvc->finalize().ignore();
199 m_connections.clear();
206 status = clearStore();
214 return connect(ident, logName);
220 StatusCode status = findObject(m_rootName, pO);
223 std::vector<Prop> props;
224 long loc = ident.find(
" ");
225 std::string filename, auth, svc =
"", db_typ =
"";
226 logname = ident.substr(0, loc);
227 using Parser = Gaudi::Utils::AttribStringParser;
230 for (
auto attrib: Parser(ident.substr(loc + 1))) {
231 switch( ::
toupper(attrib.tag[0]) ) {
236 filename = std::move(attrib.value);
239 switch( ::
toupper(attrib.value[0]) ) {
258 db_typ = std::move(attrib.value);
261 props.emplace_back( attrib.tag, attrib.value);
277 log <<
MSG::ERROR <<
"Cannot add " << ident <<
" invalid filename!" <<
endmsg;
282 const std::string& typ,
283 const std::vector<Prop>& ,
289 auto appPropMgr = serviceLocator()->as<
IProperty>();
297 StatusCode sts = appPropMgr->getProperty( &sp );
299 log <<
MSG::ERROR <<
"Could not get NTuple Persistency format"
300 <<
" from ApplicationMgr properties" <<
endmsg;
305 if ( sp.
value() ==
"HBOOK" ) {
308 else if ( sp.
value() ==
"ROOT" ) {
316 if ( !typ.empty() && typ != sp.
value() ) {
319 <<
"Type given by job option "
320 <<
"NTupleSvc.Input/Output ignored!" <<
endmsg;
336 auto status = pService->sysInitialize();
337 if ( !status.isSuccess() )
return status;
345 if ( typ == CLID_ColumnWiseTuple ) {
348 else if ( typ == CLID_RowWiseTuple ) {
365 std::string
path = fullPath;
372 StatusCode status = retrieveObject(path, pObj);
374 log <<
MSG::ERROR <<
"Cannot book N-tuple " << path <<
" (Exists already)" <<
endmsg;
378 if ( sep == std::string::npos ) {
379 log <<
MSG::ERROR <<
"Cannot book N-tuple " << path <<
" (Invalid path)" <<
endmsg;
383 std::string p_path (path, 0, sep);
384 std::string o_path (path, sep, path.length());
387 log <<
MSG::ERROR <<
"Cannot book N-tuple " << path <<
" (Invalid parent directory)" <<
endmsg;
393 log <<
MSG::ERROR <<
"Cannot book N-tuple " << path <<
" (Unknown reason)" <<
endmsg;
400 std::string full = dirPath;
403 return book(full, type, title);
408 return book( dirPath,
toStr(
id), type, title);
415 StatusCode status = findObject(pParent, relPath, *pp_cast<DataObject>(&pObj));
418 status =
create( type, title, pObj);
421 status = registerObject(pParent, relPath, pObj);
433 const std::string& title) {
434 return book( pParent,
toStr(
id), type, title);
439 const std::string& relPath) {
444 if (relPath[0]!=
'/') full +=
"/";
464 std::string full = dirPath;
465 if (relPath[0]!=
'/') full +=
"/";
474 StatusCode status = retrieveObject(m_rootName, p);
477 std::string entryname = m_rootName;
479 entryname += logname;
481 new GenericAddress(t, CLID_NTupleFile, filename, entryname, 0, typ);
482 status = registerAddress(p, logname, pA);
484 log <<
MSG::INFO <<
"Added stream file:" << filename <<
" as " << logname <<
endmsg;
489 log <<
MSG::ERROR <<
"Cannot add file:" << filename <<
" as " << logname <<
endmsg;
496 StatusCode status = findObject(fullPath, *pp_cast<DataObject>(&p));
499 if ( sep2 != std::string::npos ) {
500 std::string relPath = fullPath.substr(0, sep2);
505 status = registerObject(fullPath, p);
538 StatusCode status = findObject(fullPath, *pp_cast<DataObject>(&pObj));
539 return status.
isSuccess() ?
save ( pObj ) : INVALID_OBJ_PATH;
549 if ( pSvc && pReg ) {
562 return INVALID_OBJECT;
568 StatusCode status = findObject(pParent, relPath, *pp_cast<DataObject>(&pObj));
569 return status.
isSuccess() ?
save ( pObj ) : INVALID_OBJ_PATH;
597 return INVALID_OBJECT;
603 StatusCode status = findObject(fullPath, *pp_cast<DataObject>(&pObj));
610 StatusCode status = findObject(pParent, relPath, *pp_cast<DataObject>(&pObj));
628 status = pSvc->
updateObj(pAddr, n_tuple);
637 status = INVALID_OBJECT;
646 StatusCode status = findObject(fullPath, *pp_cast<DataObject>(&pObj));
653 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...
const char * toStr(IAuditor::StandardEventType e)
Simple mapping function from IAuditor::StandardEventType to string.
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.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
bool isSuccess() const
Test for a status code of SUCCESS.
unsigned long release() override
release reference to object
#define DECLARE_NAMESPACE_OBJECT_FACTORY(n, x)
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
const long ROOT_StorageType
No data loader available.
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)=0
Convert the transient object to the requested representation.
Generic Transient Address.
std::vector< DataObject * > IDataSelector
This is only a placeholder to allow me compiling until the responsible guy does his work! M...
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.
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.
#define DECLARE_COMPONENT(type)
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 of the basic interface.
virtual StatusCode reinitialize()
DataSvc overrides: reinitialize service.
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.
unsigned int CLID
Class ID definition.
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.
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.
const long TEST_StorageType
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.
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 HBOOK_StorageType
Connections m_connections
Container of connection points.