thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
TreeFactory.h
1// -*- C++ -*-
2//
3// TreeFactory.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef LWH_TreeFactory_H
10#define LWH_TreeFactory_H
11//
12// This is the declaration of the TreeFactory class.
13//
14
15#include "AITreeFactory.h"
16#include <string>
17#include <stdexcept>
18#include "Tree.h"
19
20namespace LWH {
21
22using namespace AIDA;
23
27class TreeFactory: public ITreeFactory {
28
29public:
30
32 virtual ~TreeFactory() {
33 clear();
34 }
35
39 ITree * create() {
40 Tree * tree = new Tree;
41 trees.insert(tree);
42 return tree;
43 }
44
53 Tree * createTree(const std::string & storeName) {
54 return new Tree(storeName);
55 }
56
68 ITree * create(const std::string & storeName,
69 const std::string & storeType = "",
70 bool readOnly = false, bool createNew = false,
71 const std::string & = "") {
72 if ( storeType != "xml" && storeType != "" && storeType != "flat" )
73 throw std::runtime_error("Can only store trees in xml or flat format.");
74 if ( readOnly || !createNew )
75 throw std::runtime_error("Cannot read in trees.");
76 return new Tree(storeName, storeType != "flat");
77 }
78
79private:
80
82 void clear() {
83 for ( std::set<Tree *>::iterator it = trees.begin();
84 it != trees.end(); ++it ) delete *it;
85 trees.clear();
86 }
87
89 std::set<Tree *> trees;
90
91};
92
93}
94
95#endif /* LWH_TreeFactory_H */
The creator of trees.
Definition: TreeFactory.h:27
void clear()
Delete all trees.
Definition: TreeFactory.h:82
Tree * createTree(const std::string &storeName)
Creates a new Tree and associates it with a store.
Definition: TreeFactory.h:53
ITree * create(const std::string &storeName, const std::string &storeType="", bool readOnly=false, bool createNew=false, const std::string &="")
Creates a new Tree and associates it with a store.
Definition: TreeFactory.h:68
std::set< Tree * > trees
The created trees.
Definition: TreeFactory.h:89
ITree * create()
Creates a new tree that is not associated with a store.
Definition: TreeFactory.h:39
virtual ~TreeFactory()
Destructor.
Definition: TreeFactory.h:32
The Tree class is a simple implementation of the AIDA::ITree interface.
Definition: Tree.h:32
The LWH namespace contains a Light-Weight Histogram package which implements the most rudimentary his...