Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

HistoFile.cxx

Go to the documentation of this file.
00001 
00002 // $Id: HistoFile.cxx,v 1.2 2008/08/29 22:18:12 fmwk Exp $
00003 //
00005 //
00006 // messier@indiana.edu
00008 #include <string>
00009 extern "C" {
00010 #include <unistd.h>
00011 }
00012 #include "TFile.h"
00013 #include "JobControl/HistoFile.h"
00014 using namespace jobc;
00015 
00016 static std::string gsFileName("histos.root");
00017 static TFile*      gsTFile    = 0;
00018 static TDirectory* gsCurrDir  = 0;
00019 static bool        gsSaveHistos = true;
00020 
00021 //......................................................................
00022 
00023 bool HistoFile::SaveHistos()
00024 {
00025   return gsSaveHistos;
00026 }
00027 
00028 //......................................................................
00029 
00030 void HistoFile::SetFileName(const char* name) 
00031 {
00032   if (name==0) return;
00033 
00034   std::string sname = name;
00035   if (sname=="") return;
00036 
00037   if (sname=="0") {
00038     gsSaveHistos = false;
00039     return;
00040   }
00041 
00042   gsFileName = name;
00043 }
00044 
00045 //......................................................................
00046 
00047 const char* HistoFile::FileName() {return gsFileName.c_str(); }
00048 
00049 //......................................................................
00050 
00051 TFile* HistoFile::File() { return gsTFile; }
00052 
00053 //......................................................................
00054 
00055 void HistoFile::StepIn(const char* dirname) 
00056 {
00057   if (gsTFile==0) {
00058     // Check that the file name is not already in use
00059     const int fOK     = 0;
00060     int       fexists = access(gsFileName.c_str(),F_OK);
00061     for (int i = 1; (i < 100) && (fexists == fOK); ++i) {
00062       std::string::size_type pos = gsFileName.find(".root");
00063       if (pos == std::string::npos) {
00064         gsFileName += ".root";
00065         i--;
00066       }
00067       else {
00068         if (i == 1) {
00069           gsFileName.insert(pos, "-01");
00070         }
00071         else if (i % 10 == 0) {
00072           pos--;
00073           gsFileName[pos--] = '0';
00074           char s = '0' + i / 10;
00075           gsFileName[pos] = s;
00076         }
00077         else {
00078           char s = '0' + i % 10;
00079           gsFileName[pos - 1] = s;
00080         }
00081       }
00082       fexists = access(gsFileName.c_str(), F_OK);
00083     } 
00084     gsTFile = new TFile(gsFileName.c_str(), "RECREATE");
00085   }
00086   gsCurrDir = gDirectory;
00087   if (dirname == 0) { gsTFile->cd(); return; }
00088 
00089   
00090   TObject* obj = gsTFile->FindObject(dirname);
00091   if (obj==0) gsTFile->mkdir(dirname);
00092   gsTFile->cd(dirname);
00093 }
00094 
00095 //......................................................................
00096 
00097 void HistoFile::StepOut() 
00098 {
00099   if (gsCurrDir) gsCurrDir->cd();
00100 }
00101 

Generated on Thu Sep 4 02:05:27 2008 for NOvA Offline by doxygen 1.3.5