WriteStdHepFileModule Class Reference

Write binary /HEPEVT/ file from StdHep found in SimSnarlRecord. More...

#include <WriteStdHepFileModule.h>

Inheritance diagram for WriteStdHepFileModule:
JobCModule

List of all members.

Public Member Functions

 WriteStdHepFileModule ()
JobCResult Ana (const MomNavigator *mom)
const RegistryDefaultConfig () const
void Config (const Registry &r)
void Report ()
void EndJob ()

Private Member Functions

void OpenFile ()
void CloseFile ()

Private Attributes

std::string fStdHepFilename
Int_t fD
Int_t fIonScheme
Int_t fRecordSets

Detailed Description

Write binary /HEPEVT/ file from StdHep found in SimSnarlRecord.

Author:
(last to touch it)
Author
rhatcher
Version:
Revision
1.1
Date:
Date
2007/07/16 19:10:37

Contact: R. Hatcher <rhatcher@fnal.gov>

Created on: Sat Jul 7 17:02:36 2007

Author: R. Hatcher 2007.07.07

Id
WriteStdHepFileModule.h,v 1.1 2007/07/16 19:10:37 rhatcher Exp

Definition at line 31 of file WriteStdHepFileModule.h.


Constructor & Destructor Documentation

WriteStdHepFileModule::WriteStdHepFileModule (  ) 

Definition at line 34 of file WriteStdHepFileModule.cxx.

00035   : fStdHepFilename("blah.dat"), fD(-1), fIonScheme(UtilPDG::kIonUnchanged), 
00036     fRecordSets(0)
00037 {
00038 
00039 }


Member Function Documentation

JobCResult WriteStdHepFileModule::Ana ( const MomNavigator mom  )  [virtual]

Implement this for read only access to the MomNavigator

Reimplemented from JobCModule.

Definition at line 143 of file WriteStdHepFileModule.cxx.

References fD, UtilHepevt::fillCommon(), RecDataRecord< T >::FindComponent(), fIonScheme, MomNavigator::FragmentIter(), fRecordSets, UtilPDG::getDfltStdIonScheme(), JobCModule::GetName(), SimSnarlRecord::GetSimSnarlHeader(), RecPhysicsHeader::GetSnarl(), JobCResult::kFailed, JobCResult::kPassed, Msg::kWarning, MSG, OpenFile(), UtilPDG::setDfltStdIonScheme(), UtilHepevt::setNevHep(), and UtilHepevt::writeBinary().

00144 {
00145 
00146   JobCResult result = JobCResult::kFailed;
00147   int snarlsInRecSet = 0;
00148 
00149   TObject* recObj = 0;
00150 
00151   // find the SimSnarlRecord
00152   TIter recItr = mom->FragmentIter();
00153   while ( ( recObj = recItr.Next() ) ) {
00154     SimSnarlRecord* simrec = dynamic_cast<SimSnarlRecord*>(recObj);
00155     if (!simrec) continue;  // skip things in mom that aren't SimSnarlRecords
00156 
00157     const SimSnarlHeader* simhead = simrec->GetSimSnarlHeader();
00158     int evtnum = simhead->GetSnarl();
00159 
00160     const TObject* obj = simrec->FindComponent("TClonesArray","StdHep");
00161     const TClonesArray* stdhep = dynamic_cast<const TClonesArray*>(obj);
00162 
00163     if (stdhep) {
00164       if ( fD < 0 ) OpenFile();  // if first time open the file
00165       // record current scheme for translating ion codes
00166       UtilPDG::ionscheme_t ionsave = UtilPDG::getDfltStdIonScheme();
00167       // set requested scheme
00168       UtilPDG::setDfltStdIonScheme((UtilPDG::ionscheme_t)fIonScheme);
00169       // fill the /HEPEVT/ common from the TClonesArray of TParticles
00170       UtilHepevt::fillCommon(stdhep);
00171       // set the event # in /HEPEVT/ common
00172       UtilHepevt::setNevHep(evtnum);
00173       // write the binary file from the /HEPEVT/ common
00174       if ( UtilHepevt::writeBinary(fD) ) {
00175         // count record that have been processed
00176         fRecordSets++;
00177         snarlsInRecSet++;
00178         result = JobCResult::kPassed;
00179       }
00180       // restore the ion translation scheme
00181       UtilPDG::setDfltStdIonScheme(ionsave);
00182     }
00183     
00184   }
00185 
00186   if ( snarlsInRecSet > 1 ) {
00187       MSG("Exodus",Msg::kWarning )
00188           << GetName() 
00189           << " RecordSet contained more than one StdHep "
00190           << endl;
00191   }
00192   return result;
00193 }

void WriteStdHepFileModule::CloseFile ( void   )  [private]

Definition at line 129 of file WriteStdHepFileModule.cxx.

References UtilHepevt::closeBinary(), fD, fStdHepFilename, Msg::kInfo, and MSG.

Referenced by Config(), and EndJob().

00130 {
00131   if ( fD < 0 ) return;  // nothing open
00132 
00133   MSG("Exodus",Msg::kInfo) 
00134     << "Closing file: " << fStdHepFilename << endl;
00135 
00136   UtilHepevt::closeBinary(fD);
00137   fD = -1;
00138 
00139 }

void WriteStdHepFileModule::Config ( const Registry r  )  [virtual]

Return the actual configuration. If your module directly pulls its configuration from the fConfig Registry, you don't need to override this. Override if you have local config variables.

Reimplemented from JobCModule.

Definition at line 66 of file WriteStdHepFileModule.cxx.

References CloseFile(), fIonScheme, fStdHepFilename, Registry::Get(), JobCModule::GetName(), UtilPDG::ionSchemeName(), Msg::kInfo, and MSG.

00067 {
00068 //======================================================================
00069 // Configure the module given the registry r
00070 //======================================================================
00071     const char*   tmpc;
00072     int           tmpi;
00073 
00074     std::string oldname(fStdHepFilename);
00075     if (r.Get("OutputFilename",tmpc)) fStdHepFilename = std::string(tmpc);
00076 
00077     if (fStdHepFilename != oldname) CloseFile();
00078 
00079     if (r.Get("ConvertIonPDG",tmpi)) {
00080       if (fIonScheme != tmpi) {
00081         MSG("Exodus",Msg::kInfo) 
00082           << GetName() << " will convert ions using "
00083           << UtilPDG::ionSchemeName((UtilPDG::ionscheme_t)tmpi)
00084           << "." << endl;
00085       }
00086       fIonScheme = tmpi;
00087     }
00088 }

const Registry & WriteStdHepFileModule::DefaultConfig ( void   )  const [virtual]

Get the default configuration registry. This should normally be overridden. One useful idiom is to implement it like:

const Registry& MyModule::DefaultConfig() const { static Registry cfg; // never is destroyed if (cfg.Size()) return cfg; // already filled it // set defaults: cfg.Set("TheAnswer",42); cfg.Set("Units","unknown"); return cfg; }

Reimplemented from JobCModule.

Definition at line 43 of file WriteStdHepFileModule.cxx.

References JobCModule::GetName(), UtilPDG::kIonUnchanged, Registry::LockValues(), Registry::Set(), and Registry::UnLockValues().

00044 {
00045 //======================================================================
00046 // Create a registry which holds the default configuration and return it
00047 //======================================================================
00048   static Registry r;
00049 
00050   // Set name of config
00051   std::string name = this->GetName();
00052   name += ".config.default";
00053   r.SetName(name.c_str());
00054 
00055   // Set values of config
00056   r.UnLockValues();
00057   r.Set("OutputFilename","hepevt.dat");
00058   r.Set("ConvertIonPDG",(int)UtilPDG::kIonUnchanged);
00059   r.LockValues();
00060 
00061   return r;
00062 }

void WriteStdHepFileModule::EndJob (  )  [virtual]

Implement for notification of end of job

Reimplemented from JobCModule.

Definition at line 104 of file WriteStdHepFileModule.cxx.

References CloseFile(), and Report().

00105 {
00106     Report();
00107     CloseFile();
00108 }

void WriteStdHepFileModule::OpenFile (  )  [private]

Definition at line 112 of file WriteStdHepFileModule.cxx.

References fD, fStdHepFilename, JobCModule::GetName(), Msg::kInfo, MSG, and UtilHepevt::openBinary().

Referenced by Ana().

00113 {
00114   MSG("Exodus",Msg::kInfo) 
00115     << "Open file: " << fStdHepFilename << endl;
00116 
00117   fD = UtilHepevt::openBinary(fStdHepFilename.c_str(),true);
00118 
00119   if (fD < 0) {
00120     MSG("Exodus",Msg::kInfo) 
00121       << GetName() << " failed to open file: " 
00122       << fStdHepFilename << "." << endl;
00123   }
00124 
00125 }

void WriteStdHepFileModule::Report (  )  [virtual]

Implement to spew end of running report

Reimplemented from JobCModule.

Definition at line 92 of file WriteStdHepFileModule.cxx.

References fRecordSets, fStdHepFilename, Msg::kInfo, and MSG.

Referenced by EndJob().

00093 {
00094   MSG("Exodus",Msg::kInfo) 
00095     << "Report for WriteStdHepFileModule Module:" << endl;
00096 
00097   MSG("Exodus",Msg::kInfo) 
00098     << "   Processed " << fRecordSets << " records written to " 
00099     << fStdHepFilename << "." << endl;
00100 }


Member Data Documentation

Int_t WriteStdHepFileModule::fD [private]

Definition at line 49 of file WriteStdHepFileModule.h.

Referenced by Ana(), CloseFile(), and OpenFile().

Definition at line 50 of file WriteStdHepFileModule.h.

Referenced by Ana(), and Config().

Definition at line 52 of file WriteStdHepFileModule.h.

Referenced by Ana(), and Report().

Definition at line 48 of file WriteStdHepFileModule.h.

Referenced by CloseFile(), Config(), OpenFile(), and Report().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1