Anp::RunModule Class Reference

#include <RunModule.h>

Inheritance diagram for Anp::RunModule:
Anp::AlgSnarl Anp::Base

List of all members.

Public Member Functions

 RunModule ()
virtual ~RunModule ()
bool Run (Record &record)
void Config (const Registry &reg)
bool Init (const Header &header)
void End (const DataBlock &block)
void SetConfig (const Registry &reg)
void RunChain (int nrecords, const std::string chain_name="records")
bool AddFile (const std::string path, const std::string option="")
int Add (std::string type, std::string det, std::string reco, std::string run, std::string key)

Private Attributes

TFile * fFile
TTree * fTree
RecordfRecord
Handle< AlgSnarlfAlg
DataBlock fBlock
int fBranchBuf
int fFileCompr
int fTreeSplit
bool fInit
bool fEraseHep
bool fEraseStrip
bool fMakeFile
bool fPrintAdd
bool fPrintEnd
bool fPrintRun
bool fWriteTree
bool fEventOnly
std::string fAlgName
std::string fPrefix
std::string fPhysicsNtupleData
std::string fPhysicsNtupleFile
std::string fPhysicsNtupleOut
std::vector< std::string > fInput
StreamBuf fBuffer

Detailed Description

Definition at line 27 of file RunModule.h.


Constructor & Destructor Documentation

Anp::RunModule::RunModule (  ) 

Definition at line 33 of file RunModule.cxx.

00034    :fFile(0),
00035     fTree(0),
00036     fRecord(0),
00037     fAlg(),
00038     fBranchBuf(2000000),
00039     fFileCompr(1),
00040     fTreeSplit(99),
00041     fInit(false),
00042     fEraseHep(false),
00043     fEraseStrip(true),
00044     fMakeFile(true),
00045     fPrintAdd(false),
00046     fPrintRun(false),
00047     fWriteTree(false),
00048     fEventOnly(false),
00049     fAlgName(""),
00050     fPrefix(""),
00051     fPhysicsNtupleData(""),
00052     fPhysicsNtupleFile(""),
00053     fPhysicsNtupleOut(""),
00054     fBuffer()
00055 {
00056 }

Anp::RunModule::~RunModule (  )  [virtual]

Definition at line 59 of file RunModule.cxx.

00060 {
00061 }


Member Function Documentation

int Anp::RunModule::Add ( std::string  type,
std::string  det,
std::string  reco,
std::string  run,
std::string  key 
)
bool Anp::RunModule::AddFile ( const std::string  path,
const std::string  option = "" 
)
void Anp::RunModule::Config ( const Registry reg  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 121 of file RunModule.cxx.

References fAlg, fAlgName, fBranchBuf, fBuffer, fEraseHep, fEraseStrip, fEventOnly, fFileCompr, fMakeFile, fPhysicsNtupleData, fPhysicsNtupleFile, fPhysicsNtupleOut, fPrefix, fPrintAdd, fPrintRun, fTreeSplit, fWriteTree, Registry::Get(), Registry::KeyExists(), Anp::StreamBuf::Open(), Anp::Read(), and Anp::Handle< T >::valid().

Referenced by SetConfig().

00122 { 
00123    //
00124    // Configure self, create and configure child algorithm,
00125    // create output ROOT file.
00126    //
00127 
00128    //
00129    // Get write TTree flag, TFile compression factor and TTree split level
00130    //
00131    if(!reg.Get("RunModuleBuffr", fBranchBuf)) reg.Get("BranchBuf", fBranchBuf);
00132    if(!reg.Get("RunModuleCompr", fFileCompr)) reg.Get("FileCompr", fFileCompr);
00133    if(!reg.Get("RunModuleSplit", fTreeSplit)) reg.Get("TreeSplit", fTreeSplit);
00134 
00135    //
00136    // Read boolean flags using Anp::Read function from Default.h
00137    //
00138    const string prf = "RunModule";
00139    if(!Anp::Read(reg, prf + "EraseHep",   fEraseHep))   Anp::Read(reg, "EraseHep",   fEraseHep);
00140    if(!Anp::Read(reg, prf + "EraseStrip", fEraseStrip)) Anp::Read(reg, "EraseStrip", fEraseStrip);
00141    if(!Anp::Read(reg, prf + "MakeFile",   fMakeFile))   Anp::Read(reg, "MakeFile",   fMakeFile);
00142    if(!Anp::Read(reg, prf + "PrintAdd",   fPrintAdd))   Anp::Read(reg, "PrintAdd",   fPrintAdd);
00143    if(!Anp::Read(reg, prf + "PrintRun",   fPrintRun))   Anp::Read(reg, "PrintRun",   fPrintRun);
00144    if(!Anp::Read(reg, prf + "WriteTree",  fWriteTree))  Anp::Read(reg, "WriteTree",  fWriteTree);
00145    if(!Anp::Read(reg, prf + "EventOnly",  fEventOnly))  Anp::Read(reg, "EventOnly",  fEventOnly);
00146 
00147    //
00148    // Get prefix for PhysicsNtuple output file and child's AlgSnarl name
00149    //
00150    Anp::Read(reg, "RunModule",       fAlgName);
00151    Anp::Read(reg, "RunModulePrefix", fPrefix);
00152 
00153    //
00154    // Get output path string from Registry or enviromental variable
00155    //
00156    if(!Anp::Read(reg, "PhysicsNtupleFile", fPhysicsNtupleFile) && std::getenv("PHYSICS_NTUPLE_FILE"))
00157    {
00158       fPhysicsNtupleFile = std::getenv("PHYSICS_NTUPLE_FILE");
00159    }
00160 
00161    //
00162    // Get name for PhysicsNtuple data directory
00163    //
00164    if(!Anp::Read(reg, "PhysicsNtupleData", fPhysicsNtupleData) && std::getenv("PHYSICS_NTUPLE_DATA"))
00165    {
00166       fPhysicsNtupleData = std::getenv("PHYSICS_NTUPLE_DATA");
00167    }
00168 
00169    //
00170    // Get name for PhysicsNtuple cerr/cout redirect file
00171    //
00172    if(!Anp::Read(reg, "PhysicsNtupleOut", fPhysicsNtupleOut) && std::getenv("PHYSICS_NTUPLE_OUT"))
00173    {
00174       fPhysicsNtupleOut = std::getenv("PHYSICS_NTUPLE_OUT");
00175    }
00176 
00177    if(!fPhysicsNtupleOut.empty())
00178    {
00179       fBuffer.Open(fPhysicsNtupleOut.c_str());
00180    }
00181 
00182    if(reg.KeyExists("PrintConfig"))
00183    {
00184       cout << "RunModule::Config" << endl
00185            << "   BranchBuf = " << fBranchBuf << endl
00186            << "   FileCompr = " << fFileCompr << endl
00187            << "   TreeSplit = " << fTreeSplit << endl
00188            << "   EraseHep = " << fEraseHep << endl
00189            << "   EraseStrip = " << fEraseStrip << endl
00190            << "   MakeFile = " << fMakeFile << endl
00191            << "   PrintAdd = " << fPrintAdd << endl
00192            << "   PrintRun = " << fPrintRun << endl
00193            << "   WriteTree = " << fWriteTree << endl
00194            << "   EventOnly = " << fEventOnly << endl
00195            << "   AlgName = " << fAlgName << endl
00196            << "   Prefix = " << fPrefix << endl
00197            << "   PhysicsNtupleData = " << fPhysicsNtupleData << endl
00198            << "   PhysicsNtupleFile = " << fPhysicsNtupleFile << endl;
00199    }
00200 
00201    if(fAlg.valid())
00202    {
00203       cerr << "RunModule::Config - AlgSnarl child already exists" << endl;
00204    }
00205    else if(!fAlgName.empty() && fAlgName != "none")
00206    {
00207       fAlg = Factory<AlgSnarl>::Instance().Create(fAlgName);
00208       if(fAlg.valid())
00209       {
00210          Registry reg_(false);
00211          if(reg.Get(fAlgName.c_str(), reg_))
00212          {
00213             fAlg -> Config(reg_);
00214          }
00215          else
00216          {
00217             fAlg -> Config(reg);
00218          }
00219       }
00220    }
00221 }

void Anp::RunModule::End ( const DataBlock block  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 322 of file RunModule.cxx.

References fAlg, fFile, Anp::GetROOTMutex(), and Anp::Handle< T >::valid().

00323 {  
00324    //
00325    // Finish job, write out DataBlock and save/close ROOT file
00326    //
00327 
00328    if(fAlg.valid()) fAlg -> End(block);
00329 
00330    if(fFile)
00331    {
00332       Anp::Lock<Mutex> lock(Anp::GetROOTMutex());
00333       
00334       fFile -> WriteTObject(&block, "block", "Overwrite");
00335       fFile -> Write();
00336       fFile -> Close();
00337       fFile = 0;
00338    }
00339 }

bool Anp::RunModule::Init ( const Header header  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 224 of file RunModule.cxx.

References beamtype, cd(), fAlg, fBranchBuf, fFile, fFileCompr, fInit, fMakeFile, fPhysicsNtupleFile, fPrefix, fRecord, fTree, fTreeSplit, fWriteTree, Anp::Header::GetBEAMTYPE(), Anp::Header::GetDATATYPE(), Anp::Header::GetDETECTOR(), Anp::Header::GetRECOTYPE(), Anp::GetROOTMutex(), Anp::Header::GetRUNCYCLE(), Anp::Header::IsValid(), Anp::AlgSnarl::Set(), and Anp::Handle< T >::valid().

00225 {
00226    //
00227    // Initiliaze self and children algorithms
00228    //
00229    
00230    if(!header.IsValid())
00231    {
00232       cerr << "RunModule::Init - invalid header file" << endl;
00233       return false;
00234    }
00235    
00236    if(fInit)
00237    {
00238       return true;
00239    }
00240    else
00241    {
00242       fInit = true;
00243    }
00244 
00245    //
00246    // Do not make ROOT file?
00247    //
00248    if(!fMakeFile) return true;      
00249    
00250    if(!fFile)
00251    {
00252       Anp::Lock<Mutex> lock(Anp::GetROOTMutex());
00253       
00254       //
00255       // Create output file name, if it is not set explicitly
00256       //
00257       if(fPhysicsNtupleFile.empty())
00258       {            
00259          if(fPrefix.empty())
00260          {
00261             fPhysicsNtupleFile = header.GetDETECTOR() + ".";
00262          }
00263          else
00264          {
00265             fPhysicsNtupleFile = fPrefix + "." + header.GetDETECTOR() + ".";
00266          }
00267          
00268          fPhysicsNtupleFile += header.GetDATATYPE() + ".";
00269          fPhysicsNtupleFile += header.GetRECOTYPE() + ".";
00270          fPhysicsNtupleFile += header.GetRUNCYCLE();
00271          
00272          const string beamtype = header.GetBEAMTYPE();
00273          if(beamtype != "Unknown" && beamtype != "unknown")
00274          {
00275             fPhysicsNtupleFile += "." + beamtype;
00276          }
00277          
00278          fPhysicsNtupleFile += ".root";                      
00279       }
00280       
00281       fFile = new TFile(fPhysicsNtupleFile.c_str(), "RECREATE");      
00282       if(!fFile || !fFile -> IsOpen())
00283       {
00284          cerr << "RunModule::Init - failed to create file: \n" << fPhysicsNtupleFile << endl;
00285          delete fFile; fFile = 0;
00286          return false;
00287       }
00288       
00289       cout << "RunModule::Init - recreated ROOT file:\n   " << fPhysicsNtupleFile << endl;
00290       
00291       fFile -> cd();
00292       fFile -> SetCompressionLevel(fFileCompr);
00293    }
00294    else
00295    {
00296       cout << "RunModule::Init - ROOT file already exists:\n   " << fPhysicsNtupleFile << endl;
00297       return false;
00298    }
00299 
00300    //
00301    // Set TFile pointer to child algorithms
00302    //
00303    if(fAlg.valid())
00304    {
00305       fAlg -> Set(fFile);
00306       fAlg -> Init(header);
00307    }
00308    
00309    if(fWriteTree)
00310    {
00311       Anp::Lock<Mutex> lock(Anp::GetROOTMutex());
00312 
00313       fTree = new TTree("records", "records", fTreeSplit);
00314       fTree -> SetDirectory(fFile);         
00315       fTree -> Branch("record", "Anp::Record", &fRecord, fBranchBuf);
00316    }
00317 
00318    return true;
00319 }

bool Anp::RunModule::Run ( Record record  )  [virtual]

Implements Anp::AlgSnarl.

Definition at line 64 of file RunModule.cxx.

References DataBlock::Add(), fAlg, fBlock, fEraseHep, fEraseStrip, fEventOnly, fPrintRun, fRecord, fTree, fWriteTree, Anp::Record::GetHeader(), Anp::Record::GetNEvents(), Anp::GetROOTMutex(), Anp::GetStrip(), Anp::Header::IsValid(), Anp::Record::Print(), and Anp::Handle< T >::valid().

00065 {
00066    //
00067    // Call "Run(record)" for child algorithm, count pot and save record to TTree
00068    //
00069 
00070    if(!record.GetHeader().IsValid())
00071    {
00072       cerr << "RunModule::Run - header is invalid" << endl;
00073       return false;
00074    }
00075    
00076    //
00077    // Run child algorithm
00078    //
00079    if(fAlg.valid() && !fAlg -> Run(record))
00080    {
00081       return false;
00082    }
00083    
00084    //
00085    // Count output snarls, events and protons
00086    //
00087    fBlock.Add(record);
00088 
00089    //
00090    // Save record to TTree, if it exists
00091    //
00092    if(fWriteTree && fTree)
00093    {
00094       //
00095       // Copy current record, if fEraseHep is set then erase vector<StdHep>
00096       //
00097       if(!fEventOnly || (fEventOnly && record.GetNEvents() > 0))
00098       {
00099          Anp::Lock<Mutex> lock(Anp::GetROOTMutex());
00100          
00101          fRecord = new Anp::Record(record);
00102          
00103          if(fEraseHep)   fRecord -> GetStdHep().clear();
00104          if(fEraseStrip) fRecord -> GetStrip().clear();
00105          
00106          fTree -> Fill();
00107          
00108          delete fRecord; fRecord = 0;
00109       }
00110    }
00111 
00112    //
00113    // Print record content
00114    //
00115    if(fPrintRun) record.Print();
00116 
00117    return true;
00118 }

void Anp::RunModule::RunChain ( int  nrecords,
const std::string  chain_name = "records" 
)
void Anp::RunModule::SetConfig ( const Registry reg  ) 

Definition at line 342 of file RunModule.cxx.

References Config().

00343 {
00344    //
00345    // This function created to avoid CINT name resolution problem with ROOT v5.16.00
00346    //
00347 
00348    RunModule::Config(reg);
00349 }


Member Data Documentation

Definition at line 59 of file RunModule.h.

Referenced by Config(), End(), Init(), and Run().

std::string Anp::RunModule::fAlgName [private]

Definition at line 77 of file RunModule.h.

Referenced by Config().

Definition at line 61 of file RunModule.h.

Referenced by Run().

Definition at line 63 of file RunModule.h.

Referenced by Config(), and Init().

Definition at line 85 of file RunModule.h.

Referenced by Config().

bool Anp::RunModule::fEraseHep [private]

Definition at line 68 of file RunModule.h.

Referenced by Config(), and Run().

Definition at line 69 of file RunModule.h.

Referenced by Config(), and Run().

Definition at line 75 of file RunModule.h.

Referenced by Config(), and Run().

TFile* Anp::RunModule::fFile [private]

Definition at line 55 of file RunModule.h.

Referenced by End(), and Init().

Definition at line 64 of file RunModule.h.

Referenced by Config(), and Init().

bool Anp::RunModule::fInit [private]

Definition at line 67 of file RunModule.h.

Referenced by Init().

std::vector<std::string> Anp::RunModule::fInput [private]

Definition at line 83 of file RunModule.h.

bool Anp::RunModule::fMakeFile [private]

Definition at line 70 of file RunModule.h.

Referenced by Config(), and Init().

std::string Anp::RunModule::fPhysicsNtupleData [private]

Definition at line 79 of file RunModule.h.

Referenced by Config().

std::string Anp::RunModule::fPhysicsNtupleFile [private]

Definition at line 80 of file RunModule.h.

Referenced by Config(), and Init().

std::string Anp::RunModule::fPhysicsNtupleOut [private]

Definition at line 81 of file RunModule.h.

Referenced by Config().

std::string Anp::RunModule::fPrefix [private]

Definition at line 78 of file RunModule.h.

Referenced by Config(), and Init().

bool Anp::RunModule::fPrintAdd [private]

Definition at line 71 of file RunModule.h.

Referenced by Config().

bool Anp::RunModule::fPrintEnd [private]

Definition at line 72 of file RunModule.h.

bool Anp::RunModule::fPrintRun [private]

Definition at line 73 of file RunModule.h.

Referenced by Config(), and Run().

Definition at line 57 of file RunModule.h.

Referenced by Init(), and Run().

TTree* Anp::RunModule::fTree [private]

Definition at line 56 of file RunModule.h.

Referenced by Init(), and Run().

Definition at line 65 of file RunModule.h.

Referenced by Config(), and Init().

Definition at line 74 of file RunModule.h.

Referenced by Config(), Init(), and Run().


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

Generated on 17 Jun 2018 for loon by  doxygen 1.6.1