HistMan.cxx File Reference

#include "HistMan.h"
#include <TSystem.h>
#include <TKey.h>
#include <TROOT.h>
#include <TFile.h>
#include <TH1.h>
#include <TH2.h>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <cassert>

Go to the source code of this file.

Functions

vector< string > parse_path (const char *path)
TFolder & mkdir_p (TFolder &top, const char *path)
static TFolder * directory_to_folder (TDirectory &directory)
static void folder_to_directory (TFolder *folder, TDirectory &directory)

Variables

static int histcount = 0

Function Documentation

static TFolder* directory_to_folder ( TDirectory &  directory  )  [static]

Definition at line 79 of file HistMan/HEAD/HistMan.cxx.

References it.

Referenced by HistMan::HistMan().

00080 {
00081     TFolder* folder = new TFolder(directory.GetName(),directory.GetName());
00082 
00083     TList *l = directory.GetListOfKeys();
00084     if (!l) return folder;
00085 
00086     TIter it(l->MakeIterator());
00087     TObject *obj=0;
00088     while ( (obj=it()) ) {
00089         TKey* key = dynamic_cast<TKey*>(obj);
00090         assert(key);
00091         obj = directory.Get(key->GetName());
00092         TDirectory* dir = dynamic_cast<TDirectory*>(obj);
00093         if (dir) {
00094             TFolder* fol = directory_to_folder(*dir);
00095             //cerr << "Adding folder " << fol->GetName()
00096             //<< " to folder " << folder->GetName()
00097             //<< " from directory " << dir->GetName() << endl;
00098             folder->Add(fol);
00099         }
00100         else {
00101             //cerr << "Adding object " << obj->GetName()
00102             //<< " to folder " << folder->GetName() << endl;
00103             folder->Add(obj);
00104         }
00105     }
00106     return folder;
00107 }

static void folder_to_directory ( TFolder *  folder,
TDirectory &  directory 
) [static]

Definition at line 211 of file HistMan/HEAD/HistMan.cxx.

References it.

Referenced by HistMan::WriteOut().

00212 {
00213     TDirectory*& prevdir = gDirectory, *dir = 0;
00214 
00215     TObject* obj = directory.Get(folder->GetName());
00216     if (obj) {
00217         dir = dynamic_cast<TDirectory*>(obj);
00218         if (!dir) {
00219             cerr << "Non-directory object \"" << folder->GetName()
00220                  << "\" already in directory\n";
00221             return;
00222         }
00223     }
00224     else
00225         dir = directory.mkdir(folder->GetName());
00226 
00227     dir->cd();
00228 
00229     TCollection* sf = folder->GetListOfFolders();
00230     if (!sf) {
00231         prevdir->cd();
00232         return;
00233     }
00234 
00235     TIter it(sf->MakeIterator());
00236     obj=0;
00237     while ( (obj=it()) ) {
00238         TFolder *fol = dynamic_cast<TFolder*>(obj);
00239         if (fol) folder_to_directory(fol,*dir);
00240         else {
00241             dir->cd();
00242             obj->Write();
00243         }
00244     }
00245     prevdir->cd();
00246 }

TFolder& mkdir_p ( TFolder &  top,
const char *  path 
)

Definition at line 43 of file HistMan/HEAD/HistMan.cxx.

References parse_path().

Referenced by HistMan::Adopt(), and HistMan::HistMan().

00044 {
00045     if (!path || path[0] == '\0') return top;
00046 
00047     vector<string> vp = parse_path(path);
00048     TFolder* folder = &top;
00049 
00050     for (unsigned int ind=0; ind < vp.size(); ++ind) {
00051         const char* name = vp[ind].c_str();
00052         TFolder* tmp = dynamic_cast<TFolder*>(folder->FindObject(name));
00053         if (tmp) folder = tmp;
00054         else folder = folder->AddFolder(name,name);
00055     }
00056     return *folder;
00057 }

vector<string> parse_path ( const char *  path  ) 

Definition at line 20 of file HistMan/HEAD/HistMan.cxx.

References done(), and find().

Referenced by HistMan::GetObject(), mkdir_p(), and test_parse_path().

00021 {
00022     vector<string> vs;
00023     string p(path);
00024     string::iterator it1=p.begin(), it2, done=p.end();
00025     for (it2=find(p.begin(),done,'/'); it2 != done; it2=find(it1,done,'/')) {
00026         if (it1==it2) {
00027             ++it1;
00028             continue;
00029         }
00030         string dir(it1,it2);
00031         if (dir != ".")
00032             vs.push_back(dir);
00033         it1 = it2+1;
00034     }
00035     if (it1 != it2) {
00036         string dir(it1,it2);
00037         if (dir != ".")
00038             vs.push_back(string(it1,it2));
00039     }
00040     return vs;
00041 }


Variable Documentation

int histcount = 0 [static]

Definition at line 59 of file HistMan/HEAD/HistMan.cxx.

Referenced by HistMan::HistMan().


Generated on 15 Jul 2018 for loon by  doxygen 1.6.1