GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HistoConverter.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2006 by Christophe Theisen & Olivier Stezowski *
3  * christophe.theisen(AT)cea.fr, stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef GW_HISTOCONVERTER_H
24 #define GW_HISTOCONVERTER_H
25 
26 #include "GwLogMessage.h"
27 
28 // root's includes
29 #ifndef ROOT_TH1
30 #include <TH1.h>
31 #endif
32 
33 #ifndef ROOT_TH2
34 #include <TH2.h>
35 #endif
36 
37 #ifndef ROOT_THStack
38 #include <THStack.h>
39 #endif
40 
41 #ifndef ROOT_TString
42 #include <TString.h>
43 #endif
44 
45 // std's includes
46 #include <map>
47 #include <string>
48 #include <fstream>
49 
50 // to correct a CC (solaris) bug
51 // The fstream::read method does not work properly on CC solaris (at least on my machine ..)
52 // Because it wasn't easy to change things that work properly on other
53 // systems, a wrapper is used and the fstream::get method which works is used instead.
54 //
55 // \warning if you use this wrapper, be careful that fstream::gcount does not
56 // give you the correct answer .. better to use fstream::good to know if the reading was correct
57 //
58 // Much better to use the c or the system implementation in the futur !
59 //
60 /*
61 namespace {
62 class CCBug : public ifstream
63 {
64 public:
65  explicit CCBug();
66 
67  virtual istream &CCBug::read(char *, int);
68  };
69 
70  CCBug::CCBug() : ifstream() { ; }
71 
72  istream & CCBug::read(char *s, int n)
73  {
74  for ( int i = 0; i < n; i++ ) ifstream::get(s[i]);
75  return (*this);
76  }
77  }
78 */
79 
80 namespace Gw {
81 
108 #define MAXCYCLE 999
109 #ifndef ROOT_TString
110 #include "TString.h"
111 #endif
112 
114 {
115 private:
116  static std::map <const char *, HistoConverter *> *gPrototypes;
117  static Int_t gAllocated;
118 
119 public:
121 
127 
129 
135 
136  static int fVerboseLevel; // 0 for no message when writing / reading spectra
137  // 1 for message when writing / reading spectra. Default mode
138 
139 protected:
140  int fMode ; // open mode: kVersion or kOverwrite
141  TString fName; // name of the histoconverter system
142 
143  int fStatus ; // current status of the stream
144  TString fError; // string to explain the last error in case the last operation failed
145 
146  char fCycle; // character used in a versionning mode
147 
148  TString fType; // character used for type definition (e.g.: eg, rad, gpsi, etc...)
149 
150  TString fFileExt; // character used for file extension (e.g.: asc, spe, s, etc...)
151 
152  bool fIsSwapping; // true if swapping is needed to read the data
153 
154  TString fOptions; // option for the differents converter
155 
156  mutable LogMessage fLog; // log message
157 
158 
159 protected:
160  short Short(char *buf);
161  int Int(char *buf);
162  long Long(char *buf);
163  float Float(char *buf);
164 
165  unsigned short UShort(char *buf);
166  unsigned int UInt(char *buf);
167  unsigned long ULong(char *buf);
168 
170 
178  virtual void CheckDirectory(const char *name);
179 
180  TString CheckFileVersion(TString filename);
181 
182  void AddMineTypes();
183 
184 
185 public:
186  HistoConverter();
187  HistoConverter(const char *name);
188  virtual ~HistoConverter();
189 
191  static void AddPrototype(const char *, HistoConverter *) ;
192 
194  std::map <const char *, HistoConverter *>* GetMapPrototype() {return gPrototypes;}
195 
196  // ! set verbose level. 0 for no I/O messages. 1 (default) for I/O messages.
197  static void SetVerboseLevel(const int);
198  // ! return verbose level
199  static int GetVerboseLevel();
200 
202  int GetMode() const { return fMode; }
203  void SetMode(HistoConverter::EMode mode) { fMode = mode; }
204 
205  int GetStatus() const { return fStatus; }
206  const char *GetError() const { return fName.Data() ; }
207 
209  void SetError(HistoConverter::EStatus status = kGood, const char *msgerror = "");
210 
212  void SetCycle(char c) { fCycle = c; }
213 
215  void SetType(TString type) { fType = type; }
216 
218  void SetFileExt(TString ext) { fFileExt = ext; }
219  TString GetFileExt() const { return fFileExt; }
220 
222  void SetOption(Option_t* opt, const char* mode = "reset");
223  Option_t* GetOption() const {return fOptions.Data();}
224 
226 
229  virtual TH1 *Get(int /*i*/);
231 
235  virtual TH1 *Get(const char */*name*/);
236 
238 
241  virtual bool Read(TH1 &);
243 
246  virtual bool Write(const TH1 &);
248 
252  virtual bool Read(TH2 &/*h*/) { return false; }
254 
258  virtual bool Write(const TH2 &/*h*/) { return false;}
259 
261 
268  virtual bool Read(THStack &/*hs*/) { return false; }
270  virtual bool Write(const THStack &/*hs*/) { return false; }
271 
273  virtual HistoConverter *NewDB(const char *) const;
274 
276  virtual const char *GetType() const { return "null" ; }
277 
279  virtual void ls(Option_t *) const ;
280 
282  void CheckMineTypes();
283 
285  static void DrawSpectrum(const char* spectrum);
286 
288  ClassDef(HistoConverter,0); // base class to read/write histograms
289 };
290 }
291 #endif
Option_t * GetOption() const
void SetError(HistoConverter::EStatus status=kGood, const char *msgerror="")
to set/reset the status of this converter
virtual bool Read(THStack &)
to read several histograms
EStatus
current status of the converter
static void AddPrototype(const char *, HistoConverter *)
to add a new type of database service
static void DrawSpectrum(const char *spectrum)
draw spectrum for mine types
float Float(char *buf)
virtual bool Write(const TH2 &)
to write an histogram
void SetFileExt(TString ext)
to set/get file extension of the spectra/histo
void SetOption(Option_t *opt, const char *mode="reset")
set options
short Short(char *buf)
virtual const char * GetType() const
to know what type of HistoConverter system it is
Base class for a Log message.
Definition: GwLogMessage.h:94
int GetMode() const
long Long(char *buf)
header file for GwLogMessage.cpp
virtual bool Read(TH1 &)
to read an histogram
virtual bool Write(const TH1 &)
to write an histogram
void SetMode(HistoConverter::EMode mode)
unsigned short UShort(char *buf)
int GetStatus() const
EMode
current working mode
TString GetFileExt() const
virtual bool Read(TH2 &)
to read an histogram
void SetCycle(char c)
to set/reset the status of this converter
static void SetVerboseLevel(const int)
ClassDef(HistoConverter, 0)
rootcint dictionary
virtual TH1 * Get(int)
to get histo number i in the list
static int fVerboseLevel
unsigned int UInt(char *buf)
const char * GetError() const
virtual void ls(Option_t *) const
to show the spectra in this DB system on the standard output
virtual bool Write(const THStack &)
to write several histograms in one operation
virtual void CheckDirectory(const char *name)
check if the given directory can be read/written
virtual HistoConverter * NewDB(const char *) const
to creat a new DB system
int Int(char *buf)
static int GetVerboseLevel()
std::map< const char *, HistoConverter * > * GetMapPrototype()
Get prototype map.
TString CheckFileVersion(TString filename)
unsigned long ULong(char *buf)
void SetType(TString type)
to set the type of the spectra/histo
void CheckMineTypes()
check mine types