23 #ifndef GW_HISTOCONVERTER_H
39 #ifndef ROOT_TSystemDirectory
40 #include <TSystemDirectory.h>
43 #ifndef ROOT_TGMimeTypes
44 #include <TGMimeTypes.h>
59 Int_t HistoConverter::fVerboseLevel = 1;
60 Int_t HistoConverter::gAllocated = 0;
63 map<const char *, HistoConverter *>* HistoConverter::gPrototypes;
66 HistoConverter::HistoConverter()
76 fLog(
"HistoConverter")
79 gPrototypes =
new map<const char *, HistoConverter *>;
95 fLog(
"HistoConverter")
104 if ( gAllocated-- == 1 ) {
105 clog <<
"HistoConverter::~HistoConverter()\n[...\n" ;
106 clog <<
" Destroying the global prototype map ... " <<
endl;
108 clog <<
" done\n...]" <<
endl;
119 if (!inc.EndsWith(
"]")) {
123 if ( strncmp(mode,
"append",
sizeof(opt)) == 0 )
125 else if ( strncmp(mode,
"reset",
sizeof(opt)) == 0 )
147 map<const char *, HistoConverter *>::iterator im;
149 bool isnew_type =
true;
150 for (im = gPrototypes->begin() ; im != gPrototypes->end() ; im++ ) {
151 if ( im->first == type ) { isnew_type =
false;
break; }
154 if (isnew_type) gPrototypes->insert(pair<const char *, HistoConverter *>(type, proto));
161 TGMimeTypes* mineTypes = gClient->GetMimeTypeList();
165 Bool_t ok = mineTypes->GetType(ext.Data(), type);
174 TString application(
"[application/");
175 application +=
fType;
176 application.Append(
"]");
182 if (!icon.EndsWith(
"/")) icon.Append(
"/");
183 icon.Append(
"hdb_s.xpm");
187 command =
"Gw::HistoConverter::DrawSpectrum(\"%s\")";
189 TGMimeTypes* mineTypes = gClient->GetMimeTypeList();
191 mineTypes->AddType(application.Data(), ext.Data(), icon.Data(), icon.Data(), command.Data());
198 TString hname(spectrum);
202 TString ext(spectrum);
203 ext = ext(ext.Last(
'.'), ext.Length()-ext.Last(
'.'));
205 map<const char *, HistoConverter *>::iterator im;
207 for (im = gPrototypes->begin(); im != gPrototypes->end(); ++im ) {
208 if ( strncmp( im->second->GetFileExt(), ext.Data(),
sizeof(im->second->GetFileExt())) == 0 ) {
209 if ( strcmp(im->first,
"gpsi") == 0 ) {
210 im->second->CheckDirectory(hname);
211 im->second->ls(
"all");
214 h = im->second->Get(hname);
215 h->SetDirectory(gROOT);
229 hname.ReplaceAll(
" ",
"");
231 hname.Remove(hname.Last(
'.'));
233 filename = hname; filename +=
fFileExt;
236 TSystemDirectory dir;
237 dir.SetDirectory(
fName.Data()); TList *list = dir.GetListOfFiles();
242 for (
int i = 0; i <=
MAXCYCLE; i++ ) {
245 if ( i == 0 ) tmp.Form(
"%s%s",hname.Data(),
fFileExt.Data());
249 if ( !list->FindObject(tmp.Data()) ) {
break; }
252 filename.Form(
"%s%s",hname.Data(),
fFileExt.Data());
257 if ( 0 < cycle && cycle <
MAXCYCLE ) {
259 filename.Form(
"%s%c%d%s",hname.Data(),
fCycle,cycle,
fFileExt.Data());
263 filename.Form(
"%s%s",hname.Data(),
fFileExt.Data());
265 filename.Form(
"%s%c%d%s",hname.Data(),
fCycle,cycle,
fFileExt.Data());
270 cerr <<
"Cycle is " << cycle <<
endl;
275 return TString(filename);
282 if ((level != 0) && (level != 1))
283 cout <<
"verbose level must be 0 or 1 " <<
endl;
301 c = buf[1]; buf[1] = buf[0]; buf[0] = c;
303 short *s = (
short*)buf;
return s[0];
311 c = buf[1]; buf[1] = buf[0]; buf[0] = c;
313 short *s = (
short*)buf;
return s[0];
321 c = buf[3]; buf[3] = buf[0]; buf[0] = c;
322 c = buf[2]; buf[2] = buf[1]; buf[1] = c;
324 long *s = (
long*)buf;
return s[0];
332 c = buf[3]; buf[3] = buf[0]; buf[0] = c;
333 c = buf[2]; buf[2] = buf[1]; buf[1] = c;
335 unsigned long *s = (
unsigned long*)buf;
return s[0];
343 c = buf[3]; buf[3] = buf[0]; buf[0] = c;
344 c = buf[2]; buf[2] = buf[1]; buf[1] = c;
346 int *s = (
int*)buf;
return s[0];
354 c = buf[3]; buf[3] = buf[0]; buf[0] = c;
355 c = buf[2]; buf[2] = buf[1]; buf[1] = c;
357 unsigned int *s = (
unsigned int*)buf;
return s[0];
365 c = buf[3]; buf[3] = buf[0]; buf[0] = c;
366 c = buf[2]; buf[2] = buf[1]; buf[1] = c;
368 float *s = (
float*)buf;
return s[0];
379 if ( tmp.Length() > 0 && tmp.EndsWith(
"/") == kFALSE ) tmp +=
"/";
380 path = gSystem->UnixPathName(tmp.Data()); gSystem->ExpandPathName(path);
382 void *dir = gSystem->OpenDirectory(path.Data());
386 Form(
"the directory %s is not reachabled !",name));
388 gSystem->FreeDirectory(dir);
409 fLog <<
warning << Form(
"Reading ROOT histogram %s in a black hole ! \n",h.GetName()) <<
dolog;
418 fLog <<
warning << Form(
"Writing ROOT histogram %s in a black hole ! \n",h.GetName()) <<
dolog;
void SetError(HistoConverter::EStatus status=kGood, const char *msgerror="")
to set/reset the status of this converter
LogMessage & error(LogMessage &)
EStatus
current status of the converter
static void AddPrototype(const char *, HistoConverter *)
to add a new type of database service
LogMessage & warning(LogMessage &)
static void DrawSpectrum(const char *spectrum)
draw spectrum for mine types
void SetOption(Option_t *opt, const char *mode="reset")
set options
virtual const char * GetType() const
to know what type of HistoConverter system it is
header file for the HistoDB facility
virtual bool Read(TH1 &)
to read an histogram
virtual bool Write(const TH1 &)
to write an histogram
unsigned short UShort(char *buf)
#define MAXCYCLE
Base class that interfaces all other histograms DB systems.
LogMessage & dolog(LogMessage &)
virtual std::string & GetProcessName()
To get the Process name.
static void SetVerboseLevel(const int)
ADF::LogMessage & endl(ADF::LogMessage &log)
to get information about the gammaware configuration
virtual TH1 * Get(int)
to get histo number i in the list
unsigned int UInt(char *buf)
virtual ~HistoConverter()
virtual void ls(Option_t *) const
to show the spectra in this DB system on the standard output
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
virtual std::string & GetProcessMethod()
To get the current method.
static const char * GetPath(const char *)
to get a particular GW environment variable
static int GetVerboseLevel()
TString CheckFileVersion(TString filename)
unsigned long ULong(char *buf)
void CheckMineTypes()
check mine types