Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
DataSetManager.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : DataSetManager *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
17  * *
18  * Copyright (c) 2006: *
19  * CERN, Switzerland *
20  * MPI-K Heidelberg, Germany *
21  * *
22  * Redistribution and use in source and binary forms, with or without *
23  * modification, are permitted according to the terms listed in LICENSE *
24  * (http://tmva.sourceforge.net/LICENSE) *
25  **********************************************************************************/
26 
27 /*! \class TMVA::DataSetManager
28 \ingroup TMVA
29 
30 Class that contains all the data information.
31 
32 */
33 
34 #include <vector>
35 #include <iostream>
36 using std::endl;
37 
38 #include "TMVA/DataSetManager.h"
39 #include "TMVA/DataSetFactory.h"
40 #include "TMVA/DataSet.h"
41 #include "TMVA/DataSetInfo.h"
42 #include "TMVA/MsgLogger.h"
43 
44 #include "TMVA/Types.h"
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// constructor
48 
49 TMVA::DataSetManager::DataSetManager( DataInputHandler& dataInput )
50  : fDatasetFactory(0),
51  fDataInput(&dataInput),
52  fDataSetInfoCollection(),
53  fLogger( new MsgLogger("DataSetManager", kINFO) )
54 {
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// constructor
59 
60 TMVA::DataSetManager::DataSetManager( )
61 : fDatasetFactory(0),
62 fDataInput(0),
63 fDataSetInfoCollection(),
64 fLogger( new MsgLogger("DataSetManager", kINFO) )
65 {
66 }
67 
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// destructor
71 /// fDataSetInfoCollection.SetOwner(); // DSMTEST --> created a segfault because the DataSetInfo-objects got deleted twice
72 
73 TMVA::DataSetManager::~DataSetManager()
74 {
75  if(fDatasetFactory) delete fDatasetFactory;
76 
77  delete fLogger;
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Creates the singleton dataset
82 
83 TMVA::DataSet* TMVA::DataSetManager::CreateDataSet( const TString& dsiName )
84 {
85  DataSetInfo* dsi = GetDataSetInfo( dsiName );
86  if (!dsi) Log() << kFATAL << "DataSetInfo object '" << dsiName << "' not found" << Endl;
87  if (!fDataInput ) Log() << kFATAL << "DataInputHandler object 'fDataInput' not found" << Endl;
88 
89  // factory to create dataset from datasetinfo and datainput
90  if(!fDatasetFactory) { fDatasetFactory =new DataSetFactory(); }
91  return fDatasetFactory->CreateDataSet( *dsi, *fDataInput );
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// returns datasetinfo object for given name
96 
97 TMVA::DataSetInfo* TMVA::DataSetManager::GetDataSetInfo(const TString& dsiName)
98 {
99  return (DataSetInfo*)fDataSetInfoCollection.FindObject( dsiName );
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// stores a copy of the dataset info object
104 
105 TMVA::DataSetInfo& TMVA::DataSetManager::AddDataSetInfo(DataSetInfo& dsi)
106 {
107  dsi.SetDataSetManager( this ); // DSMTEST
108 
109  DataSetInfo * dsiInList = GetDataSetInfo(dsi.GetName());
110  if (dsiInList!=0) return *dsiInList;
111  fDataSetInfoCollection.Add( const_cast<DataSetInfo*>(&dsi) );
112  return dsi;
113 }