KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVElementDensityTable.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Thu Sep 27 17:23:50 2012
2 //Author: John Frankland,,,
3 
5 #include "KVFileReader.h"
6 #include "TEnv.h"
7 #include "KVElementDensity.h"
8 #include "KVUnits.h"
9 #include "KVBase.h"
10 
12 
13 
14 
18 {
19  // Default constructor
20  SetName("ElementDensity");
21 }
22 
23 
24 
25 
28 
30 {
31  // Destructor
32 }
33 
34 
35 
37 
39 {
40 
41  TString dfile;
42  dfile.Form("%s.DataFile", GetName());
43  TString cl_path;
44  if (!KVBase::SearchKVFile(gEnv->GetValue(dfile.Data(), ""), cl_path, "data")) {
45  Error("Initialize", "No file found for %s", GetName());
46  return;
47  }
48  else {
49 // Info("Initialize","%s will be read",gEnv->GetValue(dfile.Data(),""));
50  }
51  SetTitle(gEnv->GetValue(dfile.Data(), ""));
52 
53  Int_t ntot = 0;
54  nucMap = new TMap(50, 2);
55  KVFileReader* fr = new KVFileReader();
56  fr->OpenFileToRead(cl_path.Data());
57 
58  //Premier passage
59  //Lecture du nombre de noyaux a enregistrer
60  while (fr->IsOK()) {
61 
62  fr->ReadLine(" \t");
63  if (fr->GetCurrentLine().IsNull()) {
64  break;
65  }
66  else if (fr->GetNparRead() == 0) {
67  break;
68  }
69  else if (fr->GetReadPar(0).BeginsWith("//")) {
70 
71  kcomments += fr->GetCurrentLine();
72  kcomments += "\n";
73 
74  }
75  else {
76  Int_t zz = fr->GetIntReadPar(4);
77  Int_t aa = 2 * zz + 1;
78  GiveIndexToNucleus(zz, aa, ntot);
79  ntot += 1;
80  }
81  }
82 
83  if (!fr->PreparForReadingAgain()) return;
84 
85 // Info("Initialize","Set up map for %d nuclei", ntot);
86  CreateTable(ntot);
87 
88  KVElementDensity* lf = 0;
89  ntot = 0;
90  while (fr->IsOK()) {
91  fr->ReadLine(" \t");
92  if (fr->GetCurrentLine().IsNull()) {
93  break;
94  }
95  else if (fr->GetNparRead() == 0) {
96  break;
97  }
98  else if (fr->GetReadPar(0).BeginsWith("//")) { }
99  else {
100  CreateElement(ntot);
101  lf = (KVElementDensity*)GetCurrent();
102 
103  KVString unit = fr->GetReadPar(1);
104  Double_t units = KVUnits::g / KVUnits::cc;
105  if (unit == "g/L") {
106  lf->SetIsGas();
107  units = KVUnits::g / KVUnits::litre;
108  }
109  Double_t val = fr->GetDoubleReadPar(0);
110  lf->SetValue(val * units);
111  lf->SetElementSymbol(fr->GetReadPar(3));
112  lf->SetElementName(fr->GetReadPar(2));
113  lf->SetZ(fr->GetIntReadPar(4));
114  ntot += 1;
115  }
116 
117  }
118 
119 // Info("Initialize","table initialised correctly for %d/%d nuclei", ntot,GetNumberOfNuclei());
120  fr->CloseFile();
121  delete fr;
122 
123 }
124 
125 
126 
130 
132 {
133 
134  //Add a new entry in the table
135  //Masses are not important, we use aa=2*zz+1
136  aa = 2 * zz + 1;
138 }
139 
140 
141 
145 
147 {
148  // Return NDT::value object pointer stored at map position (Z,A).
149  //Masses are not important, we use aa=2*zz+1
150  aa = 2 * zz + 1;
151  return KVNuclDataTable::getNDTvalue(zz, aa);
152 }
153 
154 
155 
158 
160 {
161  // Search table for an element with the given name. Case-insensitive.
162  TString x = X;
163  x.ToUpper();
164  TIter next(tobj);
165  KVElementDensity* elem;
166  while ((elem = (KVElementDensity*)next())) {
167  TString el = elem->GetElementName();
168  el.ToUpper();
169  if (x == el) return elem;
170  }
171  return 0x0;
172 }
173 
174 
175 
178 
180 {
181  // Search table for an element with the given symbol. Case-insensitive.
182  TString x = X;
183  x.ToUpper();
184  TIter next(tobj);
185  KVElementDensity* elem;
186  while ((elem = (KVElementDensity*)next())) {
187  TString el = elem->GetElementSymbol();
188  el.ToUpper();
189  if (x == el) return elem;
190  }
191  return 0x0;
192 }
193 
194 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
double Double_t
R__EXTERN TEnv * gEnv
static Bool_t SearchKVFile(const Char_t *name, TString &fullpath, const Char_t *kvsubdir="")
Definition: KVBase.cpp:538
Table of atomic elements with their density.
virtual NDT::value * getNDTvalue(Int_t zz, Int_t aa) const
virtual ~KVElementDensityTable()
Destructor.
KVElementDensity * FindElementByName(const Char_t *) const
Search table for an element with the given name. Case-insensitive.
virtual void GiveIndexToNucleus(Int_t zz, Int_t aa, Int_t ntot)
KVElementDensity * FindElementBySymbol(const Char_t *) const
Search table for an element with the given symbol. Case-insensitive.
Atomic element with name, symbol and density.
const Char_t * GetElementName() const
void SetIsGas(Bool_t g=kTRUE)
const Char_t * GetElementSymbol() const
void SetZ(Int_t z)
void SetElementSymbol(const Char_t *s)
void SetElementName(const Char_t *en)
Handle reading columns of numeric data in text files.
Definition: KVFileReader.h:119
KVString GetCurrentLine()
Definition: KVFileReader.h:319
Bool_t PreparForReadingAgain()
Definition: KVFileReader.h:199
void CloseFile()
Definition: KVFileReader.h:236
ReadStatus ReadLine(const KVString &pattern="")
Definition: KVFileReader.h:242
Double_t GetDoubleReadPar(Int_t pos) const
Definition: KVFileReader.h:333
Int_t GetIntReadPar(Int_t pos) const
Definition: KVFileReader.h:337
Int_t GetNparRead() const
Definition: KVFileReader.h:324
Bool_t IsOK()
Definition: KVFileReader.h:230
KVString GetReadPar(Int_t pos) const
Definition: KVFileReader.h:341
Bool_t OpenFileToRead(const KVString &filename)
Definition: KVFileReader.h:209
Abstract base class for nuclear data table.
KVString kcomments
Commentaire provenant de la lecture fichier.
TMap * nucMap
mapping (Z,A) -> nucleus index
TObjArray * tobj
KVNumberList plageZ;.
KVNuclData * GetCurrent() const
TObjArray* tobj_rangeA; //! array where range of A associated to each Z is stored via KVIntegerList.
virtual NDT::value * getNDTvalue(Int_t zz, Int_t aa) const
Return NDT::value object pointer stored at map position (Z,A).
void CreateTable(Int_t ntot)
virtual void GiveIndexToNucleus(Int_t zz, Int_t aa, Int_t ntot)
Add a new entry in the table.
void CreateElement(Int_t idx)
void SetValue(Double_t val)
Definition: KVNuclData.cpp:97
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
virtual const char * GetValue(const char *name, const char *dflt) const
virtual const char * GetName() const
virtual void SetTitle(const char *title="")
virtual void Error(const char *method, const char *msgfmt,...) const
void ToUpper()
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
const char * Data() const
Bool_t IsNull() const
void Form(const char *fmt,...)
Double_t x[n]
gr SetName("gr")
const long double litre
Definition: KVUnits.h:84
const long double g
masses
Definition: KVUnits.h:72
const long double cc
volumes
Definition: KVUnits.h:83