18 #include "Riostream.h"
21 #include "TDirectory.h"
32 : TNamed(name,
"This is a Go4 export manager"),fiFilter(
GO4EX_ROOT)
83 if(myobject==0)
return;
84 if(myobject->InheritsFrom(TDirectory::Class()))
86 TDirectory* subdir=
dynamic_cast<TDirectory*
>(myobject);
89 else if (myobject->InheritsFrom(TFolder::Class()))
91 TFolder* subfold=
dynamic_cast<TFolder*
> (myobject);
94 else if (myobject->InheritsFrom(TCollection::Class()))
96 TCollection* col=
dynamic_cast<TCollection*
> (myobject);
99 else if(myobject->InheritsFrom(TH1::Class()))
101 TH1* histo=
dynamic_cast<TH1*
>(myobject);
104 else if (myobject->InheritsFrom(TGraph::Class()))
106 TGraph* graph=
dynamic_cast<TGraph*
>(myobject);
119 myobject->GetName(),myobject->ClassName());
127 TGo4Log::Message(0,
"ExportManager: Converting contents of folder %s",fold->GetName());
136 TString dirname=fold->GetName();
138 TString com=
"mkdir "+dirname;
140 gSystem->cd(dirname.Data());
142 TCollection* folderlist=fold->GetListOfFolders();
153 if(source==0)
return;
154 TGo4Log::Message(0,
"ExportManager: Converting contents of directory %s",source->GetName());
163 TString dirname=source->GetName();
164 if(!dirname.Contains(
".root"))
167 TString com=
"mkdir "+dirname;
169 gSystem->cd(dirname.Data());
176 TIter iter(source->GetListOfKeys());
177 while((mykey=(TKey*) iter())!=0)
179 myobject= mykey->ReadObj();
186 TGo4Log::Message(2,
"ExportManager: Could not read key %s", mykey->GetName());
189 if(!dirname.Contains(
".root"))
201 TGo4Log::Message(0,
"ExportManager: Converting contents of collection %s",col->GetName());
211 while((ob=iter())!=0)
269 TString objectname=histo->GetName();
270 TString outname=objectname;
271 outname.Append(
".hdat");
274 std::ofstream outfile(outname.Data());
277 TGo4Log::Message(3,
"ExportManager: Error opening outputfile %s",outname.Data());
281 TGo4Log::Message(0,
"ExportManager: Converting histogram %s to ASCII",histo->GetName());
283 Int_t maxbinX=histo->GetNbinsX();
284 Int_t maxbinY=histo->GetNbinsY();
285 Int_t maxbinZ=histo->GetNbinsZ();
288 outfile <<
"# Histogram "<<histo->ClassName() <<
": "<<histo->GetName()<< std::endl;
290 outfile <<
"# Xbin \tYbin \tZbin \tContent"<< std::endl;
292 outfile <<
"# X \tY \tZ \tContent"<< std::endl;
293 for(Int_t x=1; x<=maxbinX; ++x)
295 for(Int_t y=1; y<=maxbinY; ++y)
297 for(Int_t z=1; z<=maxbinZ; ++z)
299 globalbin=histo->GetBin(x,y,z);
300 cont=histo->GetBinContent(globalbin);
303 outfile <<x<<
" \t"<<y<<
" \t"<<z<<
" \t"<<cont<< std::endl;
308 TAxis* xax=histo->GetXaxis();
310 if(xax) xval=xax->GetBinLowEdge(x);
312 TAxis* yax=histo->GetYaxis();
314 if(yax) yval=yax->GetBinLowEdge(y);
316 TAxis* zax=histo->GetZaxis();
318 if(zax) zval=zax->GetBinLowEdge(z);
319 outfile <<xval<<
" \t"<<yval<<
" \t"<<zval<<
" \t"<<cont<< std::endl;
328 catch(std::exception& ex)
330 TGo4Log::Message(3,
"standard exception %s in TGo4ExportManager::ExportASCII(TH1*)",
335 TGo4Log::Message(3,
"!!! Unexpected exception in TGo4ExportManager::ExportASCII(TH1*)!!!");
346 TString objectname=graph->GetName();
347 TString outname=objectname;
348 outname.Append(
".gdat");
350 std::ofstream outfile(outname.Data());
352 TGo4Log::Message(3,
"ExportManager: Error opening outputfile %s",outname.Data());
355 TGo4Log::Message(0,
"ExportManager: Converting graph %s to ASCII",graph->GetName());
356 Int_t maxpoints=graph->GetN();
357 outfile <<
"# Graph "<<graph->ClassName() <<
": "<<graph->GetName()<< std::endl;
358 outfile <<
"# Point \tX \tY"<< std::endl;
359 for(Int_t point=0; point<maxpoints; ++point)
363 graph->GetPoint(point,xg,yg);
364 outfile <<point<<
" \t\t"<<xg<<
" \t"<<yg<< std::endl;
370 catch(std::exception& ex)
372 TGo4Log::Message(3,
"standard exception %s in TGo4ExportManager::ExportASCII(TGraph*)",
377 TGo4Log::Message(3,
"!!! Unexpected exception in TGo4ExportManager::ExportASCII(TGraph*)!!!");
392 if(histo->InheritsFrom(TH2::Class()))
394 TH2* map=
dynamic_cast<TH2*
>(histo);
397 else if (histo->InheritsFrom(TH3::Class()))
399 TGo4Log::Message(2,
"ExportManager: Converting 3d histogram %s to radware not supported yet!",histo->GetName());
405 TString objectname=histo->GetName();
406 TString outname=objectname;
407 outname.Append(
".spe");
408 TString hname = objectname;
410 Int_t maxbinX=histo->GetNbinsX();
411 Int_t l_chan=maxbinX;
420 std::ofstream outfile(outname.Data());
423 TGo4Log::Message(3,
"ExportManager: Error opening outputfile %s",outname.Data());
426 TGo4Log::Message(0,
"ExportManager: Converting 1d histogram %s to RADWARE",histo->GetName());
429 outfile.write((
char *) &first,
sizeof(Int_t));
431 outfile.write(hname.Data(), 8);
433 outfile.write((
char *) l_head, 6*
sizeof(Int_t));
436 for(Int_t xbin=0; xbin<maxbinX; ++xbin)
438 cont=(Float_t) histo->GetBinContent(xbin);
439 outfile.write( (
char *) &cont,
sizeof(Float_t) );
442 Int_t charnum=l_chan*
sizeof(Float_t);
443 outfile.write((
char *) &charnum,
sizeof(Int_t));
444 Int_t hislen = l_chan*4 + 40;
445 Int_t byteswritten=outfile.tellp();
449 if (byteswritten == hislen)
452 hname.Data(), byteswritten, hislen, outname.Data());
456 TGo4Log::Message(3,
"Histogram %s: Size mismatch: %d bytes written to %s, datalength is %d",
457 hname.Data(), byteswritten, outname.Data(), hislen);
464 catch(std::exception& ex)
466 TGo4Log::Message(3,
"standard exception %s in TGo4ExportManager::ExportRadware(TH1*)",
471 TGo4Log::Message(3,
"!!! Unexpected exception in TGo4ExportManager::ExportRadware(TH1*)!!!");
480 TGo4Log::Message(2,
"ExportManager: Converting 2d histo %s to radware not supported yet!",histo->GetName());
484 TGo4Log::Message(2,
"ExportManager: Converting graph %s to radware not supported yet!",graph->GetName());
490 TString fname=ob->GetName();
493 TFile* f = TFile::Open(fname.Data(),
"recreate");
498 TGo4Log::Message(0,
"ExportManager: Wrote object %s of class %s to root file %s",
499 ob->GetName(), ob->ClassName(),fname.Data() );
508 if(!fname.Contains(
".root")) fname.Append(
".root");
509 TFile* f = TFile::Open(fname.Data(),
"recreate");
511 f->SetTitle(ftitle.Data());
515 TGo4Log::Message(0,
"ExportManager: Wrote object %s of class %s to root file %s",
516 ob->GetName(), ob->ClassName(),fname.Data() );
void SetStartDir(const char *dir=0)
void ExportASCII(TH1 *histo, Bool_t channels=kTRUE)
void SetCurrentDir(const char *dir=0)
void ExportXML(TObject *ob)
void ExportRadware(TH1 *histo)
void ExportRoot(TObject *ob)
void SetFilter(Go4Export_t format)
static const char * Message(Int_t prio, const char *text,...)
void Export(TObject *ob, Go4Export_t format)
virtual ~TGo4ExportManager()