20 #include "TDirectory.h" 31 : TNamed(name,
"This is a Go4 export manager"),fiFilter(
GO4EX_ROOT)
80 if (myobject->InheritsFrom(TDirectory::Class())) {
81 TDirectory *subdir =
dynamic_cast<TDirectory *
>(myobject);
83 }
else if (myobject->InheritsFrom(TFolder::Class())) {
84 TFolder *subfold =
dynamic_cast<TFolder *
>(myobject);
86 }
else if (myobject->InheritsFrom(TCollection::Class())) {
87 TCollection *col =
dynamic_cast<TCollection *
>(myobject);
89 }
else if (myobject->InheritsFrom(TH1::Class())) {
90 TH1 *histo =
dynamic_cast<TH1 *
>(myobject);
92 }
else if (myobject->InheritsFrom(TGraph::Class())) {
93 TGraph *graph =
dynamic_cast<TGraph *
>(myobject);
108 "ExportManager: NOT Converting object %s of class %s",
109 myobject->GetName(), myobject->ClassName());
128 TString dirname = fold->GetName();
130 TString com =
"mkdir " + dirname;
132 gSystem->cd(dirname.Data());
134 TCollection *folderlist = fold->GetListOfFolders();
146 TGo4Log::Message(0,
"ExportManager: Converting contents of directory %s", source->GetName());
154 TString dirname = source->GetName();
155 if (!dirname.Contains(
".root")) {
157 TString com =
"mkdir " + dirname;
159 gSystem->cd(dirname.Data());
164 TIter iter(source->GetListOfKeys());
165 while (
auto mykey = (TKey *)iter()) {
166 auto myobject = mykey->ReadObj();
170 TGo4Log::Message(2,
"ExportManager: Could not read key %s", mykey->GetName());
173 if (!dirname.Contains(
".root")) {
184 TGo4Log::Message(0,
"ExportManager: Converting contents of collection %s",col->GetName());
193 while(
auto ob = iter())
249 TString objectname=histo->GetName();
250 TString outname=objectname;
251 outname.Append(
".hdat");
254 std::ofstream outfile(outname.Data());
256 TGo4Log::Message(3,
"ExportManager: Error opening outputfile %s",outname.Data());
259 TGo4Log::Message(0,
"ExportManager: Converting histogram %s to ASCII",histo->GetName());
260 Int_t maxbinX = histo->GetNbinsX();
261 Int_t maxbinY = histo->GetNbinsY();
262 Int_t maxbinZ = histo->GetNbinsZ();
265 outfile <<
"# Histogram "<<histo->ClassName() <<
": "<<histo->GetName()<< std::endl;
267 outfile <<
"# Xbin \tYbin \tZbin \tContent"<< std::endl;
269 outfile <<
"# X \tY \tZ \tContent"<< std::endl;
270 for(Int_t x=1; x<=maxbinX; ++x)
272 for(Int_t y=1; y<=maxbinY; ++y)
274 for(Int_t z=1; z<=maxbinZ; ++z)
276 globalbin=histo->GetBin(x,y,z);
277 cont=histo->GetBinContent(globalbin);
280 outfile <<x<<
" \t"<<y<<
" \t"<<z<<
" \t"<<cont<< std::endl;
285 TAxis *xax = histo->GetXaxis();
287 if(xax) xval=xax->GetBinLowEdge(x);
289 TAxis *yax = histo->GetYaxis();
291 if(yax) yval = yax->GetBinLowEdge(y);
293 TAxis *zax = histo->GetZaxis();
295 if(zax) zval = zax->GetBinLowEdge(z);
296 outfile <<xval<<
" \t"<<yval<<
" \t"<<zval<<
" \t"<<cont<< std::endl;
305 catch(std::exception& ex)
307 TGo4Log::Message(3,
"standard exception %s in TGo4ExportManager::ExportASCII(TH1 *)",
312 TGo4Log::Message(3,
"!!! Unexpected exception in TGo4ExportManager::ExportASCII(TH1 *)!!!");
322 TString objectname = graph->GetName();
323 TString outname = objectname;
324 outname.Append(
".gdat");
326 std::ofstream outfile(outname.Data());
328 TGo4Log::Message(3,
"ExportManager: Error opening outputfile %s", outname.Data());
331 TGo4Log::Message(0,
"ExportManager: Converting graph %s to ASCII", graph->GetName());
332 Int_t maxpoints = graph->GetN();
333 outfile <<
"# Graph " << graph->ClassName() <<
": " << graph->GetName() << std::endl;
334 outfile <<
"# Point \tX \tY" << std::endl;
335 for (Int_t point = 0; point < maxpoints; ++point) {
336 Double_t xg = 0, yg = 0;
337 graph->GetPoint(point, xg, yg);
338 outfile << point <<
" \t\t" << xg <<
" \t" << yg << std::endl;
344 catch (std::exception &ex)
346 TGo4Log::Message(3,
"standard exception %s in TGo4ExportManager::ExportASCII(TGraph *)", ex.what());
348 TGo4Log::Message(3,
"!!! Unexpected exception in TGo4ExportManager::ExportASCII(TGraph *)!!!");
354 if (histo->InheritsFrom(TH2::Class())) {
355 TH2 *map =
dynamic_cast<TH2 *
>(histo);
357 }
else if (histo->InheritsFrom(TH3::Class())) {
358 TGo4Log::Message(2,
"ExportManager: Converting 3d histogram %s to radware not supported yet!", histo->GetName());
362 TString objectname = histo->GetName();
363 TString outname = objectname;
364 outname.Append(
".spe");
365 TString hname = objectname;
367 Int_t maxbinX = histo->GetNbinsX();
368 Int_t l_chan = maxbinX;
375 l_head[5] = l_chan * 4;
377 std::ofstream outfile(outname.Data());
379 TGo4Log::Message(3,
"ExportManager: Error opening outputfile %s", outname.Data());
382 TGo4Log::Message(0,
"ExportManager: Converting 1d histogram %s to RADWARE", histo->GetName());
385 outfile.write((
char *)&first,
sizeof(Int_t));
387 outfile.write(hname.Data(), 8);
389 outfile.write((
char *)l_head, 6 *
sizeof(Int_t));
392 for (Int_t xbin = 0; xbin < maxbinX; ++xbin) {
393 cont = (Float_t)histo->GetBinContent(xbin);
394 outfile.write((
char *)&cont,
sizeof(Float_t));
397 Int_t charnum = l_chan *
sizeof(Float_t);
398 outfile.write((
char *)&charnum,
sizeof(Int_t));
399 Int_t hislen = l_chan * 4 + 40;
400 Int_t byteswritten = outfile.tellp();
402 if (byteswritten == hislen) {
403 TGo4Log::Message(1,
"Histogram %s: %d bytes (data %d) written to %s", hname.Data(), byteswritten, hislen,
406 TGo4Log::Message(3,
"Histogram %s: Size mismatch: %d bytes written to %s, datalength is %d", hname.Data(),
407 byteswritten, outname.Data(), hislen);
413 catch (std::exception &ex)
415 TGo4Log::Message(3,
"standard exception %s in TGo4ExportManager::ExportRadware(TH1 *)", ex.what());
417 TGo4Log::Message(3,
"!!! Unexpected exception in TGo4ExportManager::ExportRadware(TH1 *)!!!");
425 TGo4Log::Message(2,
"ExportManager: Converting 2d histo %s to radware not supported yet!",histo->GetName());
429 TGo4Log::Message(2,
"ExportManager: Converting graph %s to radware not supported yet!",graph->GetName());
435 TString fname=ob->GetName();
438 TFile *f = TFile::Open(fname.Data(),
"recreate");
443 TGo4Log::Message(0,
"ExportManager: Wrote object %s of class %s to root file %s",
444 ob->GetName(), ob->ClassName(),fname.Data() );
453 if(!fname.Contains(
".root")) fname.Append(
".root");
454 TFile *f = TFile::Open(fname.Data(),
"recreate");
456 f->SetTitle(ftitle.Data());
460 TGo4Log::Message(0,
"ExportManager: Wrote object %s of class %s to root file %s",
461 ob->GetName(), ob->ClassName(),fname.Data() );
void ExportASCII(TH1 *histo, Bool_t channels=kTRUE)
void ExportXML(TObject *ob)
void ExportRadware(TH1 *histo)
void SetCurrentDir(const char *dir=nullptr)
static const char * Message(Int_t prio, const char *text,...) GO4_PRINTF2_ARGS
void ExportRoot(TObject *ob)
void SetFilter(Go4Export_t format)
void SetStartDir(const char *dir=nullptr)
void Export(TObject *ob, Go4Export_t format)
virtual ~TGo4ExportManager()