Anp::RunAlgEvent Class Reference

#include <RunAlgEvent.h>

Inheritance diagram for Anp::RunAlgEvent:
Anp::AlgSnarl Anp::AlgEvent Anp::Base Anp::Base

List of all members.

Public Member Functions

 RunAlgEvent ()
virtual ~RunAlgEvent ()
bool Run (Record &record)
bool Run (Event &event, const Record &record, bool pass)
void Config (const Registry &reg)
void Set (TDirectory *dir)
void End (const DataBlock &block)

Private Types

typedef std::vector
< Anp::AlgCaddy< Anp::AlgEvent > > 
EventVec

Private Attributes

TDirectory * fDir
std::string fDirName
EventVec fAlgVec
AlgCaddy< AlgEventfCount
bool fEraseEvent
bool fPrintEnd

Detailed Description

Definition at line 25 of file RunAlgEvent.h.


Member Typedef Documentation

typedef std::vector<Anp::AlgCaddy<Anp::AlgEvent> > Anp::RunAlgEvent::EventVec [private]

Definition at line 44 of file RunAlgEvent.h.


Constructor & Destructor Documentation

Anp::RunAlgEvent::RunAlgEvent (  ) 

Definition at line 27 of file RunAlgEvent.cxx.

00028    :fDir(0),
00029     fDirName(),
00030     fEraseEvent(true),
00031     fPrintEnd(true)   
00032 {
00033 }

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

Definition at line 36 of file RunAlgEvent.cxx.

00037 {
00038 }


Member Function Documentation

void Anp::RunAlgEvent::Config ( const Registry reg  )  [virtual]

Reimplemented from Anp::AlgEvent.

Definition at line 86 of file RunAlgEvent.cxx.

References fAlgVec, fDir, fDirName, fEraseEvent, fPrintEnd, it, Anp::AlgEvent::Name(), quiet, Anp::Read(), Set(), and Anp::Handle< T >::valid().

00087 { 
00088    //
00089    // get algorithm list
00090    //
00091    const vector<string> namelist = Anp::ReadList<std::string>(reg, "AlgEventList", ", ");
00092 
00093    bool quiet = false;
00094    Anp::Read(reg, "RunAlgEventQuiet", quiet);
00095 
00096    if(!namelist.empty() && !quiet)
00097    {
00098       cout << "Creating " << namelist.size() << " AlgEvent algorithm(s)" << endl;
00099    }
00100 
00101    for(vector<string>::const_iterator it = namelist.begin(); it != namelist.end(); ++it)
00102    {
00103       const string &name = *it;
00104       string algname = name;
00105 
00106       // search for "-" that counts identical algorithms
00107       if(name.find("-") != string::npos)
00108       {
00109          algname = name.substr(0, name.find("-"));
00110       }
00111 
00112       AlgEventPtr alg = Factory<AlgEvent>::Instance().Create(algname);
00113 
00114       if(alg.valid())
00115       {
00116          if(!quiet)
00117          {
00118             cout << "   " << name << endl;
00119          }
00120 
00121          alg -> Name(name);
00122 
00123          fAlgVec.push_back(AlgCaddy<AlgEvent>(alg, name));       
00124       }
00125       else
00126       {
00127          cerr << "RunAlgEvent::Config() - failed to create algorithm " << algname << endl;
00128       }
00129    }
00130    
00131    for(EventVec::iterator it = fAlgVec.begin(); it != fAlgVec.end(); ++it)
00132    {
00133       Registry newreg(false);
00134       
00135       if(reg.Get((it -> alg -> Name()).c_str(), newreg))
00136       {
00137          it -> alg -> Config(newreg);
00138       }
00139       else
00140       {
00141          it -> alg -> Config(reg);
00142       }
00143 
00144       if(fDir)
00145       {
00146          it -> alg -> Set(fDir);
00147       }
00148    }
00149    
00150    // set flag if events that failed an algorithm should be erases
00151    // default is to erase such events
00152    // flag for printing end of the job summary to the screen
00153    Anp::Read(reg, "RunAlgEventErase",   fEraseEvent);
00154    Anp::Read(reg, "RunAlgEventPrint",   fPrintEnd);
00155    Anp::Read(reg, "RunAlgEventDirName", fDirName);
00156 
00157    if(reg.KeyExists("PrintConfig"))
00158    {
00159      const char *value_char = 0;
00160      reg.Get("RunAlgEventPrintConfig", value_char);
00161      
00162      if(!value_char || strcmp(value_char, "yes") == 0)
00163      {
00164        cout << "RunAlgEvent::Config" << endl
00165             << "   DirName = " << fDirName << endl
00166             << "   EraseEvent = " << fEraseEvent << endl
00167             << "   PrintEnd = " << fPrintEnd << endl;
00168      }
00169    }
00170 }

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

Reimplemented from Anp::AlgEvent.

Definition at line 194 of file RunAlgEvent.cxx.

References fAlgVec, fCount, fPrintEnd, it, Anp::AlgEvent::Name(), Lit::Print(), and Anp::AlgCaddy< T >::Print().

00195 {
00196    if(!fPrintEnd)
00197    {
00198       EventVec::iterator ialg = fAlgVec.begin();
00199       while(ialg != fAlgVec.end())
00200       {
00201          ialg -> alg -> End(block); // inform algorithms that data processing is completed   
00202          
00203          ialg = fAlgVec.erase(ialg); // remove local reference to algorithm
00204       }
00205       return;
00206    }
00207    
00208    cout << "====================================================================" << endl;
00209    cout << "                    Printing RunAlgEvent summary " << endl;
00210    cout << "====================================================================" << endl;
00211 
00212    fCount.Print(0, 0, "event", cout);
00213    cout << endl;
00214 
00215    const unsigned int name_width = Anp::NameWidth<AlgEvent>(fAlgVec);
00216    const unsigned int numb_width = Anp::NumbWidth<AlgEvent>(fAlgVec);
00217 
00218    for(EventVec::iterator it = fAlgVec.begin(); it != fAlgVec.end(); ++it)
00219    {
00220       it -> Print(name_width, numb_width, "event", cout);
00221    }
00222    if(!fAlgVec.empty())
00223    {
00224       cout << endl;
00225    }
00226 
00227    cout << "RunAlgEvent: erasing all stored algorithms..." << endl;
00228    EventVec::iterator it = fAlgVec.begin();
00229    while(it != fAlgVec.end())
00230    {
00231       AlgEventPtr alg = it -> alg;
00232 
00233       cout << "====================================================================" << endl;
00234       cout << alg -> Name() << endl;
00235 
00236       alg -> End(block); // inform algorithms that data processing is completed   
00237       
00238       it = fAlgVec.erase(it); // remove local reference to algorithm
00239    }
00240 
00241    cout << "====================================================================" << endl;
00242    cout << "                    End of RunAlgEvent summary " << endl;
00243    cout << "====================================================================" << endl;
00244 }

bool Anp::RunAlgEvent::Run ( Event event,
const Record record,
bool  pass 
) [virtual]

Implements Anp::AlgEvent.

Definition at line 64 of file RunAlgEvent.cxx.

References fAlgVec, it, Run(), and Anp::Event::Weight().

00065 {
00066    for(EventVec::iterator it = fAlgVec.begin(); it != fAlgVec.end(); ++it)
00067    {
00068       AlgEventPtr alg = it -> alg;
00069       
00070       it -> AllEvent(event.Weight());
00071       
00072       if(alg -> Run(event, record, pass))
00073       {  
00074          it -> OutEvent(event.Weight());
00075       }
00076       else
00077       {
00078          pass = false;
00079       }
00080    }
00081       
00082    return pass;
00083 }

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

Implements Anp::AlgSnarl.

Definition at line 41 of file RunAlgEvent.cxx.

References Anp::AlgCaddy< T >::AllSnarl(), Anp::Record::Erase(), Anp::Record::EventBegIterator(), Anp::Record::EventEndIterator(), fCount, fEraseEvent, and Anp::AlgCaddy< T >::OutSnarl().

Referenced by Run().

00042 {
00043    fCount.AllSnarl(record);
00044    
00045    EventIterator ievent = record.EventBegIterator();   
00046    while(ievent != record.EventEndIterator())
00047    {
00048       if(!Run(*ievent, record, true) && fEraseEvent)
00049       {
00050          ievent = record.Erase(ievent);
00051       }
00052       else
00053       {
00054          ++ievent;
00055       }
00056    }      
00057 
00058    fCount.OutSnarl(record);  
00059 
00060    return true;
00061 }

void Anp::RunAlgEvent::Set ( TDirectory *  dir  )  [virtual]

Reimplemented from Anp::AlgEvent.

Definition at line 173 of file RunAlgEvent.cxx.

References fAlgVec, fDir, fDirName, Anp::GetDir(), and it.

Referenced by Config().

00174 {
00175    if(!dir)
00176    {
00177       return;
00178    }   
00179    else if(fDir)
00180    {
00181       cerr << "RunAlgEvent::Set - TDirectory pointer is already set" << endl;
00182       return;
00183    }
00184 
00185    fDir = Anp::GetDir(fDirName, dir);
00186    
00187    for(EventVec::iterator it = fAlgVec.begin(); it != fAlgVec.end(); ++it)
00188    {
00189       it -> alg -> Set(fDir);
00190    }
00191 }


Member Data Documentation

Definition at line 52 of file RunAlgEvent.h.

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

Reimplemented from Anp::Base.

Definition at line 54 of file RunAlgEvent.h.

Referenced by End(), and Run().

TDirectory* Anp::RunAlgEvent::fDir [private]

Definition at line 48 of file RunAlgEvent.h.

Referenced by Config(), and Set().

std::string Anp::RunAlgEvent::fDirName [private]

Definition at line 50 of file RunAlgEvent.h.

Referenced by Config(), and Set().

Definition at line 56 of file RunAlgEvent.h.

Referenced by Config(), and Run().

Definition at line 57 of file RunAlgEvent.h.

Referenced by Config(), and End().


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

Generated on 3 Oct 2018 for loon by  doxygen 1.6.1