ROOTPWA
loadFitResult.C
Go to the documentation of this file.
1 
2 //
3 // Copyright 2009 Sebastian Neubert
4 //
5 // This file is part of rootpwa
6 //
7 // rootpwa is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // rootpwa is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19 //
21 //-----------------------------------------------------------
22 // File and Version Information:
23 // $Id$
24 //
25 // Description:
26 // Adds trees in file list specified by name pattern to chain.
27 // The chain is created in case it does not exist.
28 //
29 //
30 // Author List:
31 // Sebastian Neubert TUM (original author)
32 //
33 //
34 //-----------------------------------------------------------
35 
36 
37 #include <iostream>
38 #include <string>
39 
40 #include "TFileCollection.h"
41 #include "TChain.h"
42 #include "THashList.h"
43 
44 #include "reportingUtils.hpp"
45 
46 
47 using namespace std;
48 using namespace rpwa;
49 
50 
51 TChain*
52 loadFitResult(const string& fileNamePattern,
53  TChain* chain = 0,
54  const string& treeName = "pwa")
55 {
56  // use TFileCollection to expand file name pattern into file list,
57  // because TChain::Add() does support wildcards only for the root
58  // files themselves (not in directories)
59  printInfo << "constructing chain for '" << fileNamePattern << "' ..." << endl;
60  TFileCollection fileList("fitresults", "fitresults");
61  fileList.Add(fileNamePattern.c_str());
62  cout << " file list contains " << fileList.GetNFiles() << " files." << endl;
63  if (!chain)
64  chain = new TChain(treeName.c_str(), treeName.c_str());
65  if (!chain->AddFileInfoList(fileList.GetList()))
66  printWarn << "chain has problems reading file list." << endl;
67  cout << " chain '" << chain->GetName() << "' contains " << chain->GetEntries()
68  << " entries." << endl;
69  return chain;
70 }