|
//____________________________________________________________________ // // Histogram file module. // // This is an extremly simple module. All it does, is to open a ROOT // file and stay in that directory. This means, that it is ideal to // use for booking histograms in a BrModuleContainer pipeline. // // To use it, have something like // // BrModuleContainer* container = // new BrModuleContainer("container", "A Module Container"); // BrHistIOModule* histModule = // new BrHistIOModule("histModule", "A hsitogram module"); // histModule->AddFile("myhistograms.root"); // container->AddModule(histModule); // ... the remaining modules should be defined and added to the // ... container AFTER this // // With BrMainModule, you can do something like // // if (histOption->GetValue()[0] != '\0') { // BrHistIOModule* histModule = // new BrHistIOModule("histModule", "A hsitogram module"); // histModule->AddFile("myhistograms.root"); // mainModule->AddModule(histModule); // mainModule->SetHistOn() // } // // and all histograms will be booked in BrMainModule::Main // // //____________________________________________________________________ // $Id: BrHistIOModule.cxx,v 1.3 2001/12/14 15:37:47 cholm Exp $ // $Author: cholm $ // $Date: 2001/12/14 15:37:47 $ // $Copyright: 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov> // #ifndef BRAT_BrHistIOModule #include "BrHistIOModule.h" #endif #ifndef ROOT_TDirectory #include "TDirectory.h" #endif #ifndef BRAT_BrMainModule #include "BrMainModule.h" #endif #ifndef WIN32 #include <cstring> #include <iostream> #else #include <string.h> #include <iostream.h> #endif //____________________________________________________________________ ClassImp(BrHistIOModule); //____________________________________________________________________ BrHistIOModule::BrHistIOModule() { // Default constructor. DO NOT USE SetState(kSetup); fFile = 0; fIOMode = kBrJobFile|kBrRecreateFile; } //____________________________________________________________________ BrHistIOModule::BrHistIOModule(const Char_t* name, const Char_t* title) : BrIOModule(const_cast<char*>(name), const_cast<char*>(title)) { // Named constructor // Default IO mode (see BrIOModule) is: JOB & RECREATE SetState(kSetup); fFile = 0; fIOMode = kBrJobFile|kBrRecreateFile; } //____________________________________________________________________ BrHistIOModule::~BrHistIOModule() { // Destructor Warning("DTOR", "DTOR called"); if (fFile) Close(); } //____________________________________________________________________ void BrHistIOModule::Finish() { // This method differs from BrIOModule::Finish, cause modules may // manipulate histograms in Finish method. SetState(kFinish); // Count how many times this method is called. static Int_t once = 0; if (DebugLevel() > 5) cout << "Entering BrHistIOModule::Finish (" << once << ")" << endl; // If this is not a job file, do the normal BrIOModule stuff. if (!TESTBIT(fIOMode, BR_IO_JOB_BIT)) { BrMainModule::Instance(); return; } // Hack to put this module at the end of the BrMainModule pipeline // again, so that modules may do what they want. if (once++ == 0 && BrMainModule::Instance()) BrMainModule::Instance()->AddModule(this); else BrIOModule::Finish(); } //____________________________________________________________________ Bool_t BrHistIOModule::Open(const Char_t* fileName, const Option_t* option) { // Open the histogram file fFileName = fileName; TString opt(option); if (!opt.CompareTo("read", TString::kIgnoreCase)) { Failure("Open", "Cowardly refusing to read histogram files"); return kFALSE; } //First check to see if fFile already exists, if so see if open if(fFile) { if(fFile->IsOpen()) { Stop("Open","file %s is already opened, " "please close before trying to open", fFileName.Data()); return kFALSE; } delete fFile; fFile = 0; } fFile = new TFile(fileName, option, GetName()); if (!fFile) { Failure("Open", "failed to open file "%s"", fFileName.Data()); return kFALSE; } fFile->cd(); // save the file name fFileName = fileName; return kTRUE; } //____________________________________________________________________ Bool_t BrHistIOModule::Close() { // Close the histogram file if (!fFile) { Failure("Close", "no file opened"); return kFALSE; } if(!fFile->IsOpen()) { Failure("Close", "file not opened"); return kFALSE; } Info(5 ,"Close", " Closing/Writting file "); if(Verbose() > 10) fFile->ls(); if (DebugLevel() > 9) fFile->ls(); fFile->Write(); fFile->Close(); delete fFile; fFile = 0; return kTRUE; } //____________________________________________________________________ void BrHistIOModule::Print(Option_t* option) const { // Module Information method // // Options: (see also BrModule::Print) // TString opt(option); opt.ToLower(); BrModule::Print(option); if (opt.Contains("d")) cout << endl << " File name: " << (fFile ? fFileName.Data() : "none") << endl << endl << " Original author: Christian Holm Christensen" << endl << " Modifications: " << endl << " $Author: cholm $" << endl << " $Date: 2001/12/14 15:37:47 $" << endl << " $Revision: 1.3 $ " << endl << endl << "-------------------------------------------------" << endl; } //____________________________________________________________________ // // $Log: BrHistIOModule.cxx,v $ // Revision 1.3 2001/12/14 15:37:47 cholm // Modified the classes to allow the concept of file set, introduced via // BrIOModule. Also use new Info method rather than explicit // if (Verbose() > 4) // cout << "Opening file ladida" << endl; // // Revision 1.2 2001/11/21 19:14:11 cholm // Some more output in case of high debug level. // // Revision 1.1.1.1 2001/06/21 14:55:07 hagel // Initial revision of brat2 // // Revision 1.5 2001/05/31 13:12:52 cholm // Minor fixes // // Revision 1.4 2001/05/31 01:38:38 cholm // Clean up of the module // // Revision 1.3 2001/03/12 18:46:38 cholm // Fixed a few mistakes. Added a hack to histogram module, to make // sure it's file is closed as the very last thing in Finish. // // Revision 1.2 2001/03/05 14:45:05 cholm // Fixed print message // // Revision 1.1 2001/03/05 14:43:10 cholm // Added module to manage histogram file(s) // // |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|