SFrame 3.6
core/src/STreeTypeDecoder.cxx
Go to the documentation of this file.
00001 // $Id$
00002 /***************************************************************************
00003  * @Project: SFrame - ROOT-based analysis framework for ATLAS
00004  * @Package: Core
00005  *
00006  * @author Stefan Ask       <Stefan.Ask@cern.ch>           - Manchester
00007  * @author David Berge      <David.Berge@cern.ch>          - CERN
00008  * @author Johannes Haller  <Johannes.Haller@cern.ch>      - Hamburg
00009  * @author A. Krasznahorkay <Attila.Krasznahorkay@cern.ch> - CERN/Debrecen
00010  *
00011  ***************************************************************************/
00012 
00013 // Local include(s):
00014 #include "../include/STreeTypeDecoder.h"
00015 #include "../include/STreeType.h"
00016 
00017 // Initialize the static variable(s):
00018 STreeTypeDecoder* STreeTypeDecoder::m_instance = 0;
00019 const TString STreeTypeDecoder::m_unknownName = "Unknown";
00020 const Int_t STreeTypeDecoder::m_unknownCode = -1;
00021 
00022 STreeTypeDecoder* STreeTypeDecoder::Instance() {
00023 
00024    if( ! m_instance ) {
00025       m_instance = new STreeTypeDecoder();
00026    }
00027    return m_instance;
00028 }
00029 
00030 void STreeTypeDecoder::AddType( const TString& xmlName, const TString& name,
00031                                 Int_t code ) {
00032 
00033    m_forwardMap[ name ] = code;
00034    m_reverseMap[ code ] = name;
00035 
00036    m_xmlForwardMap[ xmlName ] = code;
00037    m_xmlReverseMap[ code ] = xmlName;
00038 
00039    return;
00040 }
00041 
00042 const TString& STreeTypeDecoder::GetName( Int_t code ) const {
00043 
00044    std::map< Int_t, TString >::const_iterator itr;
00045    if( ( itr = m_reverseMap.find( code ) ) == m_reverseMap.end() ) {
00046       return m_unknownName;
00047    } else {
00048       return itr->second;
00049    }
00050 }
00051 
00052 Int_t STreeTypeDecoder::GetCode( const TString& name ) const {
00053 
00054    std::map< TString, Int_t >::const_iterator itr;
00055    if( ( itr = m_forwardMap.find( name ) ) == m_forwardMap.end() ) {
00056       return m_unknownCode;
00057    } else {
00058       return itr->second;
00059    }
00060 }
00061 
00062 const TString& STreeTypeDecoder::GetXMLName( Int_t code ) const {
00063 
00064    std::map< Int_t, TString >::const_iterator itr;
00065    if( ( itr = m_xmlReverseMap.find( code ) ) == m_xmlReverseMap.end() ) {
00066       return m_unknownName;
00067    } else {
00068       return itr->second;
00069    }
00070 }
00071 
00072 Int_t STreeTypeDecoder::GetXMLCode( const TString& name ) const {
00073 
00074    std::map< TString, Int_t >::const_iterator itr;
00075    if( ( itr = m_xmlForwardMap.find( name ) ) == m_xmlForwardMap.end() ) {
00076       return m_unknownCode;
00077    } else {
00078       return itr->second;
00079    }
00080 }
00081 
00082 STreeTypeDecoder::STreeTypeDecoder()
00083    : m_forwardMap(), m_reverseMap() {
00084 
00085    AddType( "InputTree",         "Flat input tree",
00086             STreeType::InputSimpleTree );
00087    AddType( "MetadataInputTree", "Metadata input tree",
00088             STreeType::InputMetaTree );
00089    AddType( "OutputTree",         "Flat output tree",
00090             STreeType::OutputSimpleTree );
00091    AddType( "MetadataOutputTree", "Metadata output tree",
00092             STreeType::OutputMetaTree );
00093 }