ROOTPWA
TPDGDB.cc
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 // This Class' Header ------------------
23 #include "TPDGDB.h"
24 
25 // C/C++ Headers ----------------------
26 #include <iostream>
27 #include <fstream>
28 
29 using std::cout;
30 using std::endl;
31 using std::ifstream;
32 
33 // Collaborating Class Headers --------
34 #include "TString.h"
35 #include "TPDGEntry.h"
36 #include "TTree.h"
37 #include "TFile.h"
38 
39 // Class Member definitions -----------
40 
42 
43 
44 void
45 TPDGDB::Draw(char* com, char* sel, char* opt, int n, int s){
46  if(_tree!=NULL)_tree->Draw(com,sel,opt,n,s);
47 }
48 
49 unsigned int
50 TPDGDB::read(const TString& filename, int num){
51  ifstream infile(filename.Data());
52 
53  TString outname=filename+".root";
54  TFile* outfile=TFile::Open(outname,"RECREATE");
55  _tree=new TTree("pdg","pdg");
56 
57  TPDGEntry* entry=new TPDGEntry();
58  _tree->Branch("TPDGEntry",&entry);
59 
60 
61  int counter=0;
62  char line[500];
63  while(infile.good()){
64 
65  // strip comment lines
66  if(infile.peek()=='*'){
67  cout << "Stripping comment" << endl;
68 
69  infile.getline(line,500);
70  continue;
71  }
72 
73 
74  infile >> (*entry) ;
75  entry->Print();
76 
77 
78  _tree->Fill();
79 
80 
81  // discard rest of line
82  infile.getline(line,500);
83  if(num>0 && counter++>=num) break;
84  }
85  _tree->Write();
86  outfile->Close();
87  return 0;//_tree->GetEntries();
88 
89 }