Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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


Member Typedef Documentation

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

Definition at line 60 of file Interface.h.


Constructor & Destructor Documentation

Anp::Interface::Interface  ) 
 

Definition at line 27 of file Interface.cxx.

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

Anp::Interface::~Interface  ) 
 

Definition at line 45 of file Interface.cxx.

References fAlgSnarl, fBlock, fNEvent, fNSnarlFail, fNSnarlPass, and fNTrack.

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


Member Function Documentation

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

Definition at line 238 of file Interface.cxx.

References fAlgSnarl, fAlgStore, fDefault, fKeys, fPrint, fQuiet, Registry::Get(), Registry::KeyExists(), Registry::Merge(), Registry::PrettyPrint(), Anp::Read(), Anp::ReadRegistry(), reg, Registry::RemoveKey(), 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 75 of file Interface.cxx.

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

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

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

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

Definition at line 114 of file Interface.cxx.

References Anp::Data, Anp::DataIter, NtpSRTrack::end, Anp::EventIter, find(), fRecord, Anp::Corr::Key, and Anp::TrackIter.

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

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

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

Definition at line 197 of file Interface.cxx.

References fKeys.

Referenced by MadTVAnalysis::CreatePAN(), MadPIDAnalysis::CreatePAN(), ANtpInfoObjectFillerNC::FillTrackInformation(), NuPIDInterface::GetJmIDEvt(), NuPIDInterface::GetJmIDPrimaryTrk(), NuPIDInterface::GetJmIDSecondTrk(), NuPIDInterface::GetJmIDThirdTrk(), NuPIDInterface::GetRoIDEvt(), NuPIDInterface::GetRoIDPrimaryTrk(), NuPIDInterface::GetRoIDSecondTrk(), and NuPIDInterface::GetRoIDThirdTrk().

00198 {
00199    //
00200    // Find and fill variable named "vname"
00201    //    from Track if TObject inherits from NtpSRTrack
00202    //    from Event if TObject inherits from NtpSREvent
00203    //
00204 
00205    if(!fValid)
00206    {
00207       cerr << "Interface::GetVar - invalid current snarl state" << endl;
00208       return fDefault;
00209    }
00210 
00211    const KeyMap::const_iterator kit = fKeys.find(vname);
00212    if(kit == fKeys.end())
00213    {
00214       cerr << "Interface::GetVar - unknown variable: " << vname << endl;
00215       return fDefault;      
00216    }
00217 
00218    //
00219    // Collect variables for this object
00220    //
00221    const map<short, float> dmap = Interface::GetData(object);
00222 
00223    if(dmap.empty())
00224    {
00225       return fDefault;
00226    }
00227 
00228    const map<short, float>::const_iterator dit = dmap.find(kit -> second);
00229    if(dit != dmap.end())
00230    {
00231       return dit -> second;
00232    }
00233 
00234    return fDefault;
00235 }


Member Data Documentation

RunAlgSnarl* Anp::Interface::fAlgSnarl [private]
 

Definition at line 65 of file Interface.h.

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

RunAlgStore* Anp::Interface::fAlgStore [private]
 

Definition at line 64 of file Interface.h.

Referenced by Config(), and FillSnarl().

DataBlock* Anp::Interface::fBlock [private]
 

Definition at line 66 of file Interface.h.

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

double Anp::Interface::fDefault [private]
 

Definition at line 79 of file Interface.h.

Referenced by Config().

KeyMap Anp::Interface::fKeys [private]
 

Definition at line 80 of file Interface.h.

Referenced by Config(), and GetVar().

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

Definition at line 76 of file Interface.h.

Referenced by ~Interface().

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

Definition at line 74 of file Interface.h.

Referenced by ~Interface().

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

Definition at line 73 of file Interface.h.

Referenced by ~Interface().

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

Definition at line 77 of file Interface.h.

Referenced by ~Interface().

bool Anp::Interface::fPrint [private]
 

Definition at line 69 of file Interface.h.

Referenced by Config().

bool Anp::Interface::fQuiet [private]
 

Definition at line 70 of file Interface.h.

Referenced by Config().

Record* Anp::Interface::fRecord [private]
 

Definition at line 67 of file Interface.h.

Referenced by FillSnarl(), and GetData().

bool Anp::Interface::fValid [private]
 

Definition at line 71 of file Interface.h.

Referenced by FillSnarl().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:10:36 2010 for loon by  doxygen 1.3.9.1