thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
LWH::Tree Class Reference

The Tree class is a simple implementation of the AIDA::ITree interface. More...

#include <Tree.h>

Inheritance diagram for LWH::Tree:

Public Types

typedef std::vector< std::string > Path
 A path is a vector of directory names.
 
typedef std::set< PathPathSet
 A set of paths.
 
typedef std::map< std::string, IManagedObject * > ObjMap
 Map of paths to objects.
 

Public Member Functions

 Tree (std::string storename, bool xml=true)
 The standard constructor.
 
 Tree ()
 The default constructor.
 
 Tree (const Tree &dt)
 The copy constructor.
 
virtual ~Tree ()
 Destructor.
 
std::string storeName () const
 Get the name of the store.
 
IManagedObject * find (const std::string &path)
 Get the IManagedObject at a given path in the ITree.
 
ITree * findTree (const std::string &)
 LWH cannot get a mounted ITree at a given path in the current ITree.
 
bool cd (const std::string &dir)
 Change to a given directory.
 
bool insert (std::string str, IManagedObject *o)
 Insert the ManagedObject o in the tree with the path str.
 
std::string pwd () const
 Get the path of the current working directory.
 
bool ls (const std::string &=".", bool=false, std::ostream &=std::cout) const
 Not implemented in LWH.
 
std::vector< std::string > listObjectNames (const std::string &=".", bool=false) const
 Not implemented in LWH.
 
std::vector< std::string > listObjectTypes (const std::string &=".", bool=false) const
 Not implemented in LWH.
 
bool mkdir (const std::string &dir)
 Create a new directory.
 
bool mkdirs (const std::string &dir)
 Create a directory recursively.
 
bool mkdirs (Path p)
 Create a directory recursively.
 
bool rmdir (const std::string &dir)
 Remove a directory and all the contents underneeth.
 
bool rm (const std::string &path)
 Remove and delete an IManagedObject by specifying its path.
 
std::string findPath (const IManagedObject &o) const
 Get the full path of an IManagedObject.
 
bool mv (const std::string &oldp, const std::string &newp)
 Move an IManagedObject or a directory from one directory to another.
 
bool commit ()
 Print all histograms to the current filename.
 
void setOverwrite (bool o=true)
 Not implemented in LWH.
 
bool cp (const std::string &, const std::string &, bool=false)
 Not implemented in LWH.
 
bool symlink (const std::string &, const std::string &)
 Not implemented in LWH.
 
bool mount (const std::string &, ITree &, const std::string &)
 Not implemented in LWH.
 
bool unmount (const std::string &)
 Not implemented in LWH.
 
bool close ()
 Calls commit().
 
void * cast (const std::string &) const
 Not implemented in LWH.
 

Protected Member Functions

std::string sts (std::string s) const
 Strip trailing slash.
 
std::string stn (std::string s) const
 Strip trailing name.
 
std::string fullpath (std::string d) const
 Get proper full path from possibly relative path.
 
Path str2pth (std::string s) const
 Convert a string containing a path to a Path object.
 
std::string pth2str (const Path &pth) const
 Convert a Path object to a corresponding string.
 
Path purgepath (const Path &pth) const
 Remove '..' and '.
 

Private Attributes

std::string name
 The filename to print histograms to.
 
bool flat
 If true write histograms in FLAT format, otherwise in XML.
 
PathSet dirs
 The set of defined directories.
 
ObjMap objs
 The set of defined objects.
 
std::string cwd
 The current working directory.
 
bool overwrite
 Overwrite strategy.
 

Friends

class AnalysisFactory
 The AnalysisFactory is a friend.
 

Detailed Description

The Tree class is a simple implementation of the AIDA::ITree interface.

Definition at line 32 of file Tree.h.

Member Typedef Documentation

◆ ObjMap

typedef std::map<std::string, IManagedObject *> LWH::Tree::ObjMap

Map of paths to objects.

Definition at line 46 of file Tree.h.

◆ Path

typedef std::vector<std::string> LWH::Tree::Path

A path is a vector of directory names.

Definition at line 40 of file Tree.h.

◆ PathSet

typedef std::set<Path> LWH::Tree::PathSet

A set of paths.

Definition at line 43 of file Tree.h.

Constructor & Destructor Documentation

◆ Tree() [1/3]

LWH::Tree::Tree ( std::string  storename,
bool  xml = true 
)
inline

The standard constructor.

Definition at line 53 of file Tree.h.

References dirs.

◆ Tree() [2/3]

LWH::Tree::Tree ( )
inline

The default constructor.

Definition at line 61 of file Tree.h.

References dirs.

◆ Tree() [3/3]

LWH::Tree::Tree ( const Tree dt)
inline

The copy constructor.

Definition at line 68 of file Tree.h.

◆ ~Tree()

virtual LWH::Tree::~Tree ( )
inlinevirtual

Destructor.

Definition at line 73 of file Tree.h.

References objs.

Member Function Documentation

◆ cast()

void * LWH::Tree::cast ( const std::string &  ) const
inline

Not implemented in LWH.

Returns
null pointer always.

Definition at line 353 of file Tree.h.

◆ cd()

bool LWH::Tree::cd ( const std::string &  dir)
inline

Change to a given directory.

Parameters
dirThe absolute or relative path of the directory we are changing to.
Returns
false If the path does not exist.

Definition at line 111 of file Tree.h.

References cwd, dirs, fullpath(), pth2str(), purgepath(), str2pth(), and sts().

◆ close()

bool LWH::Tree::close ( )
inline

Calls commit().

Definition at line 345 of file Tree.h.

References commit().

◆ commit()

bool LWH::Tree::commit ( )
inline

Print all histograms to the current filename.

Returns
false if something went wrong.

Definition at line 281 of file Tree.h.

References flat, name, objs, LWH::ManagedObject::writeFLAT(), and LWH::ManagedObject::writeXML().

Referenced by close().

◆ cp()

bool LWH::Tree::cp ( const std::string &  ,
const std::string &  ,
bool  = false 
)
inline

Not implemented in LWH.

Returns
false always.

Definition at line 314 of file Tree.h.

◆ find()

IManagedObject * LWH::Tree::find ( const std::string &  path)
inline

Get the IManagedObject at a given path in the ITree.

The path can either be absolute or relative to the current working directory.

Parameters
pathThe path.
Returns
The corresponding IManagedObject.

Definition at line 92 of file Tree.h.

References objs.

◆ findPath()

std::string LWH::Tree::findPath ( const IManagedObject &  o) const
inline

Get the full path of an IManagedObject.

Parameters
oThe IManagedObject whose path is to be returned.
Returns
The object's absolute path. If the object does not exist, an empty string is returned.

Definition at line 251 of file Tree.h.

References objs.

Referenced by LWH::HistogramFactory::destroy(), and LWH::DataPointSetFactory::destroy().

◆ findTree()

ITree * LWH::Tree::findTree ( const std::string &  )
inline

LWH cannot get a mounted ITree at a given path in the current ITree.

Returns
0 always.

Definition at line 101 of file Tree.h.

◆ fullpath()

std::string LWH::Tree::fullpath ( std::string  d) const
inlineprotected

Get proper full path from possibly relative path.

Definition at line 373 of file Tree.h.

References cwd, pth2str(), purgepath(), and str2pth().

Referenced by cd(), insert(), mkdir(), mkdirs(), mv(), rm(), and rmdir().

◆ insert()

◆ listObjectNames()

std::vector< std::string > LWH::Tree::listObjectNames ( const std::string &  = ".",
bool  = false 
) const
inline

Not implemented in LWH.

Definition at line 162 of file Tree.h.

◆ listObjectTypes()

std::vector< std::string > LWH::Tree::listObjectTypes ( const std::string &  = ".",
bool  = false 
) const
inline

Not implemented in LWH.

Definition at line 170 of file Tree.h.

◆ ls()

bool LWH::Tree::ls ( const std::string &  = ".",
bool  = false,
std::ostream &  = std::cout 
) const
inline

Not implemented in LWH.

Returns
false always.

Definition at line 154 of file Tree.h.

◆ mkdir()

bool LWH::Tree::mkdir ( const std::string &  dir)
inline

Create a new directory.

Given a path only the last directory in it is created if all the intermediate subdirectories already exist.

Parameters
dirThe absolute or relative path of the new directory.
Returns
false If a subdirectory within the path does not exist or it is not a directory. Also if the directory already exists.

Definition at line 182 of file Tree.h.

References dirs, fullpath(), purgepath(), str2pth(), and sts().

◆ mkdirs() [1/2]

bool LWH::Tree::mkdirs ( const std::string &  dir)
inline

Create a directory recursively.

Given a path the last directory and all the intermediate non-existing subdirectories are created.

Parameters
dirThe absolute or relative path of the new directory.
Returns
false If an intermediate subdirectory is not a directory, or if the directory already exists.

Definition at line 198 of file Tree.h.

References fullpath(), mkdirs(), purgepath(), str2pth(), and sts().

Referenced by mkdirs().

◆ mkdirs() [2/2]

bool LWH::Tree::mkdirs ( Path  p)
inline

Create a directory recursively.

Given a Path the last directory and all the intermediate non-existing subdirectories are created.

Parameters
pThe full Path of the new directory.
Returns
false If an intermediate subdirectory is not a directory, or if the directory already exists.

Definition at line 209 of file Tree.h.

References dirs, and mkdirs().

◆ mount()

bool LWH::Tree::mount ( const std::string &  ,
ITree &  ,
const std::string &   
)
inline

Not implemented in LWH.

Returns
false always.

Definition at line 330 of file Tree.h.

◆ mv()

bool LWH::Tree::mv ( const std::string &  oldp,
const std::string &  newp 
)
inline

Move an IManagedObject or a directory from one directory to another.

Parameters
oldpThe path of the IManagedObject [not direcoty] to be moved.
newpThe path of the diretory in which the object has to be moved to.
Returns
false If either path does not exist.

Definition at line 264 of file Tree.h.

References dirs, fullpath(), insert(), objs, pth2str(), purgepath(), str2pth(), and sts().

◆ pth2str()

std::string LWH::Tree::pth2str ( const Path pth) const
inlineprotected

Convert a Path object to a corresponding string.

Definition at line 394 of file Tree.h.

Referenced by cd(), fullpath(), insert(), and mv().

◆ purgepath()

Path LWH::Tree::purgepath ( const Path pth) const
inlineprotected

Remove '..' and '.

' components of the given Path object.

Definition at line 401 of file Tree.h.

Referenced by cd(), fullpath(), insert(), mkdir(), mkdirs(), mv(), and rmdir().

◆ pwd()

std::string LWH::Tree::pwd ( ) const
inline

Get the path of the current working directory.

Returns
The path of the current working directory.

Definition at line 145 of file Tree.h.

References cwd.

◆ rm()

bool LWH::Tree::rm ( const std::string &  path)
inline

Remove and delete an IManagedObject by specifying its path.

Parameters
pathThe absolute or relative path of the IManagedObject to be removed.
Returns
false If path does not exist.

Definition at line 237 of file Tree.h.

References fullpath(), and objs.

Referenced by LWH::HistogramFactory::destroy(), and LWH::DataPointSetFactory::destroy().

◆ rmdir()

bool LWH::Tree::rmdir ( const std::string &  dir)
inline

Remove a directory and all the contents underneeth.

Parameters
dirThe absolute or relative path of the directory to be removed.
Returns
false If path does not exist or if it is not a directory or if the directory is not empty.

Definition at line 222 of file Tree.h.

References dirs, fullpath(), objs, purgepath(), str2pth(), and sts().

◆ setOverwrite()

void LWH::Tree::setOverwrite ( bool  o = true)
inline

Not implemented in LWH.

Definition at line 306 of file Tree.h.

References overwrite.

◆ stn()

std::string LWH::Tree::stn ( std::string  s) const
inlineprotected

Strip trailing name.

Definition at line 367 of file Tree.h.

◆ storeName()

std::string LWH::Tree::storeName ( ) const
inline

Get the name of the store.

Returns
The store's name.

Definition at line 82 of file Tree.h.

References name.

◆ str2pth()

Path LWH::Tree::str2pth ( std::string  s) const
inlineprotected

Convert a string containing a path to a Path object.

Definition at line 379 of file Tree.h.

Referenced by cd(), fullpath(), insert(), mkdir(), mkdirs(), mv(), and rmdir().

◆ sts()

std::string LWH::Tree::sts ( std::string  s) const
inlineprotected

Strip trailing slash.

Definition at line 360 of file Tree.h.

Referenced by cd(), mkdir(), mkdirs(), mv(), and rmdir().

◆ symlink()

bool LWH::Tree::symlink ( const std::string &  ,
const std::string &   
)
inline

Not implemented in LWH.

Returns
false always.

Definition at line 322 of file Tree.h.

◆ unmount()

bool LWH::Tree::unmount ( const std::string &  )
inline

Not implemented in LWH.

Returns
false always.

Definition at line 338 of file Tree.h.

Friends And Related Function Documentation

◆ AnalysisFactory

friend class AnalysisFactory
friend

The AnalysisFactory is a friend.

Definition at line 37 of file Tree.h.

Member Data Documentation

◆ cwd

std::string LWH::Tree::cwd
private

The current working directory.

Definition at line 425 of file Tree.h.

Referenced by cd(), fullpath(), and pwd().

◆ dirs

PathSet LWH::Tree::dirs
private

The set of defined directories.

Definition at line 419 of file Tree.h.

Referenced by cd(), insert(), mkdir(), mkdirs(), mv(), rmdir(), and Tree().

◆ flat

bool LWH::Tree::flat
private

If true write histograms in FLAT format, otherwise in XML.

Definition at line 416 of file Tree.h.

Referenced by commit().

◆ name

std::string LWH::Tree::name
private

The filename to print histograms to.

Definition at line 413 of file Tree.h.

Referenced by commit(), and storeName().

◆ objs

ObjMap LWH::Tree::objs
private

The set of defined objects.

Definition at line 422 of file Tree.h.

Referenced by commit(), find(), findPath(), insert(), mv(), rm(), rmdir(), and ~Tree().

◆ overwrite

bool LWH::Tree::overwrite
private

Overwrite strategy.

Definition at line 428 of file Tree.h.

Referenced by insert(), and setOverwrite().


The documentation for this class was generated from the following file: