Anp::Interface Class Reference

#include <Interface.h>

List of all members.

Public Member Functions

 Interface ()
 ~Interface ()
bool FillSnarl (TObject *record)
float GetVar (const std::string &vname, TObject *object) const
void Config (const Registry &reg)
const std::map< short, float > GetData (TObject *object) const

Private Types

typedef std::map< std::string,
int > 
KeyMap

Private Attributes

RunAlgStorefAlgStore
RunAlgSnarlfAlgSnarl
DataBlockfBlock
RecordfRecord
bool fPrint
bool fQuiet
bool fValid
unsigned int fNSnarlPass
unsigned int fNSnarlFail
unsigned int fNEvent
unsigned int fNTrack
double fDefault
KeyMap fKeys

Detailed Description

Definition at line 43 of file PhysicsNtuple/HEAD/Store/Interface.h.


Member Typedef Documentation

typedef std::map<std::string, int> Anp::Interface::KeyMap [private]

Definition at line 60 of file PhysicsNtuple/HEAD/Store/Interface.h.


Constructor & Destructor Documentation

Anp::Interface::Interface (  ) 

Definition at line 26 of file PhysicsNtuple/HEAD/Store/Interface.cxx.

00027    :fAlgStore(new Anp::RunAlgStore()),
00028     fAlgSnarl(new Anp::RunAlgSnarl()),
00029     fBlock(new DataBlock()),
00030     fRecord(new Anp::Record()),
00031     fPrint(true),
00032     fQuiet(true),
00033     fValid(false),
00034     fNSnarlPass(0),
00035     fNSnarlFail(0),
00036     fNEvent(0),
00037     fNTrack(0),
00038     fDefault(-1.0e6),
00039     fKeys()
00040 {
00041 }

Anp::Interface::~Interface (  ) 

Definition at line 44 of file PhysicsNtuple/HEAD/Store/Interface.cxx.

References fAlgSnarl, fAlgStore, fBlock, fNEvent, fNSnarlFail, fNSnarlPass, fNTrack, fPrint, and fRecord.

00045 {   
00046    //
00047    // inform AlgSnarl algorithms that processing is completed
00048    //
00049    fAlgSnarl -> End(*fBlock);
00050    
00051    delete fAlgStore;
00052    delete fAlgSnarl;
00053 
00054    if(fPrint)
00055    {
00056       cout << "--------------------------------------------------------------------" << endl
00057            << "                    Printing Interface summary " << endl
00058            << "--------------------------------------------------------------------" << endl      
00059            << "Number of passed snarls: " << fNSnarlPass << endl
00060            << "Number of failed snarls: " << fNSnarlFail << endl
00061            << "Number of requested events: " << fNEvent << endl
00062            << "Number of requested tracks: " << fNTrack << endl
00063            << *fBlock
00064            << "--------------------------------------------------------------------" << endl
00065            << "                    End of Interface summary " << endl
00066            << "--------------------------------------------------------------------" << endl;
00067    }
00068 
00069    delete fBlock;
00070    delete fRecord;
00071 }


Member Function Documentation

void Anp::Interface::Config ( const Registry reg  ) 

Definition at line 238 of file PhysicsNtuple/HEAD/Store/Interface.cxx.

References fAlgSnarl, fAlgStore, fDefault, fKeys, fPrint, fQuiet, Registry::Get(), Registry::KeyExists(), Registry::Merge(), Registry::PrettyPrint(), Anp::Read(), Anp::ReadRegistry(), reg, Registry::RemoveKey(), Munits::second, UtilString::StringTok(), Registry::UnLockKeys(), and Registry::UnLockValues().

Referenced by MadPIDAnalysis::ConfigureRoID(), MadTVAnalysis::CreatePAN(), NuPIDInterface::InitialiseJmID(), NuPIDInterface::InitialiseRoID(), NuPIDInterface::InitialiseRoID2007(), NuPIDInterface::InitialiseRoIDNuMuBar(), ANtpInfoObjectFillerNC::InitializekNN(), and SetKNNModule::Reco().

00239 { 
00240    //
00241    // Configure RunAlgStore and RunAlgSnarl algorithms
00242    //
00243 
00244    Registry reg(reg_);
00245    
00246    //
00247    // Read Registry from a text file, if it exists, and then merge it with this Registry
00248    //
00249    const char *value_path = 0;
00250    if(reg.Get("InterfaceConfigPath", value_path) && value_path)
00251    {
00252       Registry nreg(false);
00253       if(Anp::ReadRegistry(std::string(value_path), nreg, fQuiet))
00254       {
00255          reg.UnLockKeys();
00256          reg.UnLockValues();
00257          reg.Merge(nreg);
00258          reg.RemoveKey("InterfaceConfigPath");
00259       }
00260       else
00261       {
00262          cerr << "Interface::Config - failed to read Registry:\n   " << value_path << endl;
00263       }
00264    }
00265 
00266    Anp::Read(reg, "InterfacePrint", fPrint);
00267    Anp::Read(reg, "InterfaceQuiet", fQuiet);
00268 
00269    reg.Get("InterfaceDefault", fDefault);
00270 
00271    //
00272    // Read (string, int) key pairs separated by "," or " "
00273    //
00274    unsigned int widthS = 0;
00275 
00276    const char *value_keys = 0;
00277    if(reg.Get("InterfaceKeys", value_keys) && value_keys)
00278    {
00279       vector<string> kvec;
00280       UtilString::StringTok(kvec, string(value_keys), ", ");
00281 
00282       //
00283       // Now iterate over keys and separate them by "="
00284       //
00285       for(vector<string>::const_iterator kit = kvec.begin(); kit != kvec.end(); ++kit)
00286       {
00287          vector<string> pvec;
00288          UtilString::StringTok(pvec, *kit, "=");
00289 
00290          if(pvec.size() != 2)
00291          {
00292             cerr << "Interface::Config - failed to parse key: " << *kit << endl;
00293             continue;
00294          }
00295 
00296          const string keyS = pvec.front();
00297          const int    keyI = std::atoi(pvec.back().c_str());
00298          
00299          if(!(keyI > 0))
00300          {
00301             cerr << "Interface::Config - failed to parse key: " << *kit << endl;
00302             continue;       
00303          }
00304 
00305          if(!fKeys.insert(KeyMap::value_type(keyS, keyI)).second)
00306          {
00307             cerr << "Interface::Config - key already exists: " << *kit << endl;
00308             continue;       
00309          }
00310          else
00311          {
00312             widthS = std::max<unsigned int>(widthS, keyS.size());
00313          }
00314       }
00315    }
00316 
00317    if(reg.KeyExists("PrintConfig"))
00318    {
00319       cout << "Interface::Config" << endl
00320            << "   Print = " << fPrint << endl
00321            << "   Quiet = " << fQuiet << endl
00322            << "   Default = " << fDefault << endl
00323            << "   Added " << fKeys.size() << " key(s)" << endl;
00324       
00325       for(KeyMap::const_iterator kit = fKeys.begin(); kit != fKeys.end(); ++kit)
00326       {
00327          cout << "   " << std::setw(widthS) << std::left << kit -> first 
00328               << " = " << kit -> second << endl;
00329       }
00330 
00331       if(reg.KeyExists("InterfacePrintConfig"))
00332       {
00333          reg.PrettyPrint(std::cout);
00334       }
00335    }
00336 
00337    //
00338    // Configure algorithms
00339    //
00340    fAlgStore -> Config(reg);
00341    fAlgSnarl -> Config(reg);
00342 }

bool Anp::Interface::FillSnarl ( TObject *  record  ) 

Definition at line 74 of file PhysicsNtuple/HEAD/Store/Interface.cxx.

References fAlgSnarl, fAlgStore, fBlock, fNSnarlFail, fNSnarlPass, fQuiet, fRecord, fValid, and Lit::Print().

Referenced by MadPIDAnalysis::CreatePAN(), MadTVAnalysis::CreatePAN(), NuPIDInterface::GetJmID(), NuPIDInterface::GetRoID(), NuPIDInterface::GetRoID2007(), NuPIDInterface::GetRoIDNuMuBar(), and ANtpInfoObjectFillerNC::InitializekNN().

00075 {
00076    if(!record)
00077    {
00078       ++fNSnarlFail;
00079       return false;
00080    }
00081 
00082    fRecord -> Clear();
00083 
00084    if(fAlgStore -> Run(*fRecord, record) && fAlgSnarl -> Run(*fRecord))
00085    {
00086       fBlock -> Add(*fRecord);
00087       ++fNSnarlPass;
00088       fValid = true;
00089    }
00090    else
00091    {
00092       fRecord -> Clear();
00093       ++fNSnarlFail;
00094       fValid = false;
00095    }
00096    
00097    if(!fQuiet)
00098    {
00099       if(fValid)
00100       {
00101          cout << "Interface::FillSnarl - filled new snarl" << endl;
00102          fRecord -> Print();
00103       }   
00104       else
00105       {
00106          cout << "Interface::FillSnarl - failed new snarl" << endl;
00107       }
00108    }
00109    return fValid;
00110 }

const map< short, float > Anp::Interface::GetData ( TObject *  object  )  const

Definition at line 113 of file PhysicsNtuple/HEAD/Store/Interface.cxx.

References find(), fNEvent, fNTrack, fPrint, fQuiet, fRecord, fValid, and Munits::second.

Referenced by NuPIDInterface::GetRoID2007(), and NuPIDInterface::GetRoIDNuMuBar().

00114 {
00115    //
00116    // Gather data map of data items
00117    //   from Track if object points to NtpSRTrack
00118    //   from Event if object points to NtpSREvent
00119    //
00120 
00121    map<short, float> dmap;
00122 
00123    if(!fValid)
00124    {
00125       cerr << "Interface::GetData - invalid current snarl state" << endl;
00126       return dmap;
00127    }
00128 
00129    NtpSREvent* ntpevt = dynamic_cast<NtpSREvent *>(object);   
00130    if(ntpevt)
00131    {
00132       const EventIter ievent = std::find(fRecord -> EventBeg(), fRecord -> EventEnd(), ntpevt -> index);
00133       if(ievent == fRecord -> EventEnd())
00134       {
00135          if(fPrint)
00136          {
00137             cerr << "Interface::GetData - failed to find event with index: " << ntpevt -> index << endl;
00138          }
00139          return dmap;
00140       }
00141 
00142       ++fNEvent;
00143 
00144       for(DataIter dit = ievent -> DataBeg(); dit != ievent -> DataEnd(); ++dit)
00145       {
00146          dmap[dit -> Key()] = dit -> Data();
00147       }
00148 
00149       if(!fQuiet)
00150       {
00151          cout << "Interface::GetData - " << dmap.size() 
00152               << " data elements for NtpSREvent with index: " << ntpevt -> index << endl;
00153       }
00154    }
00155 
00156    NtpSRTrack* ntptrk = dynamic_cast<NtpSRTrack *>(object);
00157    if(ntptrk)
00158    {
00159       const TrackIter itrack = std::find(fRecord -> TrackBeg(), fRecord -> TrackEnd(), ntptrk -> index);
00160       if(itrack == fRecord -> TrackEnd())
00161       {
00162          if(fPrint)
00163          {
00164             cerr << "Interface::GetData - failed to find track with index: " << ntptrk -> index << endl;
00165          }
00166          return dmap;    
00167       }
00168 
00169       ++fNTrack;
00170 
00171       for(DataIter dit = itrack -> DataBeg(); dit != itrack -> DataEnd(); ++dit)
00172       {
00173          dmap[dit -> Key()] = dit -> Data();
00174       }
00175 
00176       if(!fQuiet)
00177       {
00178          cout << "Interface::GetData - " << dmap.size() 
00179               << " data elements for NtpSRTrack with index: " << ntptrk -> index << endl;
00180       }
00181    }   
00182 
00183    if(!fQuiet)
00184    {
00185       for(map<short, float>::const_iterator dit = dmap.begin(); dit != dmap.end(); ++dit)
00186       {
00187          cout << "   (key, data) = (" << dit -> first << ", " << dit -> second << ")" << endl;
00188       }
00189    }
00190 
00191    return dmap;
00192 }

float Anp::Interface::GetVar ( const std::string &  vname,
TObject *  object 
) const

Member Data Documentation

Definition at line 65 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by Config(), FillSnarl(), and ~Interface().

Definition at line 64 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by Config(), FillSnarl(), and ~Interface().

Definition at line 66 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by FillSnarl(), and ~Interface().

double Anp::Interface::fDefault [private]

Definition at line 79 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by Config().

Definition at line 80 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by Config().

unsigned int Anp::Interface::fNEvent [mutable, private]

Definition at line 76 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by GetData(), and ~Interface().

unsigned int Anp::Interface::fNSnarlFail [private]

Definition at line 74 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by FillSnarl(), and ~Interface().

unsigned int Anp::Interface::fNSnarlPass [private]

Definition at line 73 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by FillSnarl(), and ~Interface().

unsigned int Anp::Interface::fNTrack [mutable, private]

Definition at line 77 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by GetData(), and ~Interface().

bool Anp::Interface::fPrint [private]

Definition at line 69 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by Config(), GetData(), and ~Interface().

bool Anp::Interface::fQuiet [private]

Definition at line 70 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by Config(), FillSnarl(), and GetData().

Definition at line 67 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by FillSnarl(), GetData(), and ~Interface().

bool Anp::Interface::fValid [private]

Definition at line 71 of file PhysicsNtuple/HEAD/Store/Interface.h.

Referenced by FillSnarl(), and GetData().


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

Generated on 21 Jun 2018 for loon by  doxygen 1.6.1