GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InnerNDB.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) IPNL, IN2P3, CNRS *
3  * Contibutor(s) : *
4  * Jeremie Dudouet dudouet(AT)ipnl.in2p3.fr [2014] *
5  * Olivier Stezowski stezow(AT)ipnl.in2p3.fr [2014] *
6  * *
7  * This program 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 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program 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 this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
25 #include "TSystem.h"
26 #include "TString.h"
27 #include "TSystemDirectory.h"
28 #include "TList.h"
29 #include "TObjArray.h"
30 #include "TObjString.h"
31 #include "TDatime.h"
32 
33 #include "Env.h"
34 #include "BashColor.h"
35 
36 #include "InnerNDB.h"
37 
38 
39 using namespace Gw;
40 using namespace std;
41 
42 
43 
44 InnerNDB::InnerNDB(Bool_t verbose) :
45  ConcreteNDB(),
46  fInnerDataBaseName("Inner"),
47  fGammaSourcesName("GammaSources"),
48  fListOfGammaSourceFiles(0x0),
49  fVerbose(verbose)
50 {
51  Init();
52 }
53 
54 InnerNDB::InnerNDB(const char * name, const char * title, Bool_t verbose) :
55  ConcreteNDB(name,title),
56  fInnerDataBaseName("Inner"),
57  fGammaSourcesName("GammaSources"),
58  fListOfGammaSourceFiles(0x0),
59  fVerbose(verbose)
60 {
61  Init();
62 }
63 
65 {
66 
67 }
68 
70 {
71  if(!gSystem->OpenDirectory(fDataBasePath))
72  {
74  cout<<"[DataBaseError] Error ! DataBase path: "<<fDataBasePath<<" not found; ==> Default one \""<<Gw::Env::GetPath("NdbPath")<<"\" is taken !"<<endl;
75  fDataBasePath = Gw::Env::GetPath("NdbPath");
77  }
78  else
79  {
81  if(fVerbose) cout<<"[DataBaseInfo] DataBase: "<<fDataBasePath<<" will be used !"<<endl;
83  }
84 
86 
87  if(!gSystem->OpenDirectory(fInnerDataBasePath))
88  {
90  cout<<"[DataBaseError] Inner DataBase path: "<<fInnerDataBaseName<<" not found in "<<fDataBasePath<<"; ==> Default one \"Inner\" is taken !"<<endl;
91  fInnerDataBaseName = "Inner";
94  }
95  else
96  {
98  if(fVerbose) cout<<"[DataBaseInfo] "<<fInnerDataBaseName<<" DataBase: loaded !"<<endl;
100  }
101 
103  if(!gSystem->OpenDirectory(fGammaSourcesPath))
104  {
106  cout<<"[DataBaseError] No Gamma sources directory named: "<<fGammaSourcesName<<"; ==> Default one \"GammaSources\" is taken !"<<endl;
107  fGammaSourcesName = "GammaSources";
110  }
111  else
112  {
114  if(fVerbose) cout<<"[DataBaseInfo] Gamma source files are located in ${DataBase}/"<<fInnerDataBaseName<<"/"<<fGammaSourcesName<<endl;
117  }
118 
120  cout<<flush;
121 }
122 
123 void InnerNDB::SetInnerDataBase(TString name)
124 {
125  fInnerDataBaseName = name;
126  Init();
127 }
128 
130 {
131  TSystemDirectory Dir;
132  Dir.SetDirectory(fGammaSourcesPath);
133  fListOfGammaSourceFiles = Dir.GetListOfFiles();
134  fListOfGammaSourceFiles->SetName("ListOfGammaSourceFiles");
135  fListOfGammaSourceFiles->Remove(fListOfGammaSourceFiles->FindObject(".")); // Pour supprimer /.
136  fListOfGammaSourceFiles->Remove(fListOfGammaSourceFiles->FindObject("..")); // Pour supprimer /.
137  fListOfGammaSourceFiles->Sort();
138 }
139 
140 void InnerNDB::Print(const char *option) const
141 {
142  TString StrOpt = option;
143  if(StrOpt =="*" || StrOpt.Contains("GammaSources"))
144  {
146  cout<<"List of available Sources:"<<endl;
147  fListOfGammaSourceFiles->Print();
149  }
150 }
151 
152 std::vector<GammaSourceRay *> InnerNDB::GetGammaSource(TString SourceName, double EMin, double IMin, TString Opt)
153 {
154  TString SourceFilePath = fGammaSourcesPath + "/" + SourceName + ".sou";
155  if(!gSystem->IsFileInIncludePath(SourceFilePath))
156  {
158  cout<<"No source file in "<<fGammaSourcesPath<<" for "<<SourceName<<" source !"<<endl;
159  Print("GammaSources");
160  return std::vector < Gw::GammaSourceRay* >();
162  }
163 
164  std::ifstream FileIn;
165  FileIn.open (SourceFilePath.Data(), std::ifstream::in);
166 
167  string line;
168  TString Buffer;
169  const char* tab = "\t";
170 
171  std::vector < Gw::GammaSourceRay* > ListOfGammas;
172 
173  while(FileIn)
174  {
175  getline(FileIn,line);
176  Buffer = line;
177 
178  if(Buffer=="")break;
179  if(Buffer.BeginsWith("#") || Buffer.BeginsWith("A")) continue;
180 
181  Int_t i=0;
182  TString toto[20];
183  TObjArray *loa=Buffer.Tokenize(tab);
184  TIter next(loa);
185  TObjString *os=0;
186  while((os=(TObjString *)next()))
187  {
188  toto[i] = os->GetString();
189  i++;
190  }
191 
192  TString DecayMode = toto[4].ReplaceAll(" ","").ReplaceAll(tab,"");
193  TString Daughter = toto[7].ReplaceAll(" ","").ReplaceAll(tab,"");
194  TString RadSubType = toto[9].ReplaceAll(" ","").ReplaceAll(tab,"");
195  double LifeTime = toto[6].ReplaceAll(" ","").ReplaceAll(tab,"").Atof();
196  double E = toto[10].ReplaceAll(" ","").ReplaceAll(tab,"").Atof();
197  double dE = toto[11].ReplaceAll(" ","").ReplaceAll(tab,"").Atof();
198  double I = toto[14].ReplaceAll(" ","").ReplaceAll(tab,"").Atof();
199  double dI = toto[15].ReplaceAll(" ","").ReplaceAll(tab,"").Atof();
200 
201  if(E<EMin) continue;
202  if(I<IMin) continue;
203  if(Opt.Contains("NoXR") && RadSubType.Contains("XR")) continue;
204 
205 // cout<<DecayMode<<tab<<Daughter<<tab<<RadSubType<<tab<<LifeTime<<tab<<E<<tab<<dE<<tab<<I<<tab<<dI<<endl;
206 
207  GammaSourceRay *Gamma = new GammaSourceRay(Form("%s_%.0lf",SourceName.Data(),E),Form("%s_%.0lf",SourceName.Data(),E));
208  Gamma->Emmiter = SourceName;
209  Gamma->Daughter = Daughter;
210  Gamma->DecayMode = DecayMode;
211  Gamma->RadSubType = RadSubType;
212 
213  Gw::Measure<Double_t> *LifeTimeMeas;
214  LifeTimeMeas = new Gw::Measure<Double_t>();
215  LifeTimeMeas->SetValue(LifeTime);
216  LifeTimeMeas->SetError(0.);
217 
218  Gamma->LifeTime = LifeTimeMeas;
219 
220  Gw::Measure<Double_t> *IntensityMeas;
221  IntensityMeas = new Gw::Measure<Double_t>();
222  IntensityMeas->SetValue(I);
223  IntensityMeas->SetError(dI);
224 
225  Gamma->Intensity = IntensityMeas;
226 
227  Gw::Measure<Double_t> *EnerMeas;
228  EnerMeas = new Gw::Measure<Double_t>();
229  EnerMeas->SetValue(E);
230  EnerMeas->SetError(dE);
231 
232  Gamma->Energy = EnerMeas;
233 
234  ListOfGammas.push_back(Gamma);
235  }
236 
237  return ListOfGammas;
238 }
239 
240 void InnerNDB::SaveGammaList(TString ListName, std::vector <double> Energies)
241 {
242  TString FileName = fInnerDataBasePath + "/" + ListName + ".peaklist";
243 
244  std::ofstream FileOut(FileName.Data());
245 
246  FileOut<<"#List of gamma named : "<<ListName<<endl;
247  TDatime date;
248  FileOut<<"#created on : "<<date.AsString()<<endl;
249  for(unsigned int i=0 ; i<Energies.size() ; i++)
250  {
251  FileOut<<Energies[i]<<endl;
252  }
253  FileOut.close();
254 
256  cout<<"Peak list saved in "<<FileName<<endl;
258 }
259 
260 std::vector <double> InnerNDB::LoadGammaList(TString ListName)
261 {
262  TString FileName = fInnerDataBasePath + "/" + ListName + ".peaklist";
263 
264  std::vector <double> Energies;
265 
266  if(!gSystem->IsFileInIncludePath(FileName))
267  {
269  cout<<FileName<<" not found !"<<endl;
271  cout<<"Here are the available gamma lists files in the "<<fInnerDataBasePath<<" directory"<<endl;
272  TSystemDirectory Dir;
273  Dir.SetDirectory(fInnerDataBasePath);
274  TList *l = Dir.GetListOfFiles();
275  l->Sort();
276  for(int i=0 ; i<l->GetSize() ; i++)
277  {
278  if(((TString)l->At(i)->GetName()).EndsWith(".peaklist"))
279  {
280  cout<<((TString)l->At(i)->GetName()).ReplaceAll(".peaklist","")<<endl;
281  }
282  }
284  return Energies;
285  }
286 
287  std::ifstream FileIn(FileName.Data());
288 
289  string line;
290  TString Buffer;
291 
292  while(FileIn)
293  {
294  getline(FileIn,line);
295  Buffer = line;
296  if(Buffer=="") break;
297  double E = Buffer.Atof();
298  if(E!=0) Energies.push_back(E);
299  }
300 
302  cout<<FileName<<" loaded !"<<endl;
304 
305  return Energies;
306 }
307 
TString fInnerDataBasePath
Definition: InnerNDB.h:39
virtual ~InnerNDB()
Definition: InnerNDB.cpp:64
Bool_t fVerbose
Definition: InnerNDB.h:44
void SetValue(Data_T data)
set the value, cannot be overloaded
Definition: Data.h:116
Measure< Double_t > * LifeTime
Definition: NDB.h:51
TString Emmiter
Definition: NDB.h:46
TString fInnerDataBaseName
Definition: InnerNDB.h:38
void Init()
Definition: InnerNDB.cpp:69
void SetInnerDataBase(TString name)
Definition: InnerNDB.cpp:123
virtual void Print(const char *option="*") const
Definition: InnerNDB.cpp:140
TString DecayMode
Definition: NDB.h:48
TList * fListOfGammaSourceFiles
Definition: InnerNDB.h:42
std::vector< Gw::GammaSourceRay * > GetGammaSource(TString SourceName, double EMin=100., double IMin=1., TString Opt="")
Definition: InnerNDB.cpp:152
Measure< Double_t > * Energy
Definition: NDB.h:52
TString fGammaSourcesPath
Definition: InnerNDB.h:41
void GetListOfSourceFiles()
Definition: InnerNDB.cpp:129
ADF::LogMessage & endl(ADF::LogMessage &log)
to get information about the gammaware configuration
Measure< Double_t > * Intensity
Definition: NDB.h:53
TString Daughter
Definition: NDB.h:47
TString fGammaSourcesName
Definition: InnerNDB.h:40
std::vector< double > LoadGammaList(TString ListName)
Definition: InnerNDB.cpp:260
TString fDataBasePath
Definition: NDB.h:86
void SaveGammaList(TString ListName, std::vector< double > Energies)
Definition: InnerNDB.cpp:240
BashColor * fBashColor
Definition: NDB.h:85
ClassImp(InnerNDB)
static const char * GetPath(const char *)
to get a particular GW environment variable
Definition: Env.cpp:47
TString RadSubType
Definition: NDB.h:49
InnerNDB(Bool_t verbose=true)
Definition: InnerNDB.cpp:44
virtual void SetError(Data_T derr)
set the error of this value
Definition: Measure.h:111