1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
// -*- C++ -*-
//
// TreeFactory.h is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef LWH_TreeFactory_H
#define LWH_TreeFactory_H
//
// This is the declaration of the TreeFactory class.
//
#include "AITreeFactory.h"
#include <string>
#include <stdexcept>
#include "Tree.h"
namespace LWH {
using namespace AIDA;
/**
* The creator of trees.
*/
class TreeFactory: public ITreeFactory {
public:
/// Destructor.
virtual ~TreeFactory() {
clear();
}
/**
* Creates a new tree that is not associated with a store.
*/
ITree * create() {
Tree * tree = new Tree;
trees.insert(tree);
return tree;
}
/**
* Creates a new Tree and associates it with a store.
* The store is assumed to be write-only.
* The store will be created.
* @param storeName The name of the store, if empty (""), the tree is
* created in memory and therefore will not be associated
* with a file.
*/
Tree * createTree(const std::string & storeName) {
return new Tree(storeName);
}
/**
* Creates a new Tree and associates it with a store.
* The store is assumed to be write-only.
* The store will be created.
* @param storeName The name of the store, if empty (""), the tree is
* created in memory and therefore will not be associated
* with a file.
* @param storeType must be "xml".
* @param readOnly must be false since we cannot read in trees.
* @param createNew must be true indicating that the file will be created
*/
ITree * create(const std::string & storeName,
const std::string & storeType = "",
bool readOnly = false, bool createNew = false,
const std::string & = "") {
if ( storeType != "xml" && storeType != "" && storeType != "flat" )
throw std::runtime_error("Can only store trees in xml or flat format.");
if ( readOnly || !createNew )
throw std::runtime_error("Cannot read in trees.");
return new Tree(storeName, storeType != "flat");
}
private:
/** Delete all trees. */
void clear() {
for ( std::set<Tree *>::iterator it = trees.begin();
it != trees.end(); ++it ) delete *it;
trees.clear();
}
/** The created trees. */
std::set<Tree *> trees;
};
}
#endif /* LWH_TreeFactory_H */
|