/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
TOutputSvc Class Reference

#include <TOutputSvc.h>

Inheritance diagram for TOutputSvc:
Inheritance graph
[legend]
Collaboration diagram for TOutputSvc:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TOutputSvc (const std::string &name)
virtual ~TOutputSvc ()
bool initialize ()
bool finalize ()
TTree * bookTree (const std::string &fullPath, const std::string &title)
TNtuple * bookNtuple (const std::string &fullPath, const std::string &title, const std::string &leafs)
template<class Type >
bool attach (const std::string &fullDirs, Type *obj)
const std::string & name ()
template<typename Type >
bool setOption (const std::string &option, Type &var)

Protected Attributes

std::string m_name

Private Member Functions

bool addFile (const std::string &fKey, const std::string &fname)
TDirectory * getDir (const std::string &fullDirs)

Private Attributes

std::map< std::string, TFile * > m_key2file

Detailed Description

Definition at line 26 of file TOutputSvc.h.


Constructor & Destructor Documentation

TOutputSvc::TOutputSvc ( const std::string &  name)

Definition at line 8 of file TOutputSvc.cc.

    : SvcBase(name)
{
}
TOutputSvc::~TOutputSvc ( ) [virtual]

Definition at line 13 of file TOutputSvc.cc.

{
}

Member Function Documentation

bool TOutputSvc::initialize ( ) [virtual]

Implements SvcBase.

Definition at line 17 of file TOutputSvc.cc.

{
    std::map<std::string, std::string> fmap;
    OptionParser::setOption(name(), "Output", fmap);

    for ( std::map<std::string, std::string>::iterator it = fmap.begin(); it != fmap.end(); ++it ) {
        addFile(it->first, it->second);
    }

    return true;
}
bool TOutputSvc::finalize ( ) [virtual]

Implements SvcBase.

Definition at line 29 of file TOutputSvc.cc.

{
    std::map<std::string, TFile*>::iterator it = m_key2file.begin();
    while ( it != m_key2file.end() ) {
        it->second->Write();
        delete it->second;
        ++it;
    }
    m_key2file.clear();
    return true;
}
TTree * TOutputSvc::bookTree ( const std::string &  fullPath,
const std::string &  title 
)

Definition at line 41 of file TOutputSvc.cc.

{
    std::string::size_type lSeg = fullPath.rfind('/');
    std::string name = fullPath.substr(lSeg+1, std::string::npos);
    std::string fullDirs = fullPath.substr(0, lSeg);

    TTree* result = new TTree(name.c_str(), title.c_str());
    attach(fullDirs, result);
    return result;
}
TNtuple * TOutputSvc::bookNtuple ( const std::string &  fullPath,
const std::string &  title,
const std::string &  leafs 
)

Definition at line 52 of file TOutputSvc.cc.

{
    std::string::size_type lSeg = fullPath.rfind('/');
    std::string name = fullPath.substr(lSeg+1, std::string::npos);
    std::string fullDirs = fullPath.substr(0, lSeg);

    TNtuple* result = new TNtuple(name.c_str(), title.c_str(), leafs.c_str());
    attach(fullDirs, result);
    return result;
}
template<class Type >
bool TOutputSvc::attach ( const std::string &  fullDirs,
Type *  obj 
)

Definition at line 55 of file TOutputSvc.h.

{
    TDirectory* pDir = getDir(fullDirs);
    obj->SetDirectory(pDir);

    return (pDir!=0);
}
bool TOutputSvc::addFile ( const std::string &  fKey,
const std::string &  fname 
) [private]

Definition at line 63 of file TOutputSvc.cc.

{
    std::map<std::string, TFile*>::iterator it = m_key2file.find(fKey);
    if ( it == m_key2file.end() ) {
        const char* preDir = gDirectory->GetPath();
        m_key2file[fKey] = new TFile(fname.c_str(), "RECREATE");
        gDirectory->cd(preDir);
        return true;
    }
    return false;
}
TDirectory * TOutputSvc::getDir ( const std::string &  fullDirs) [private]

Definition at line 75 of file TOutputSvc.cc.

{
    TDirectory* result = 0;

    std::list<std::string> vPath;
    std::string::size_type iSeg = 0;
    while ( iSeg != std::string::npos ) {
        std::string::size_type nSeg = fullPath.find('/', iSeg);
        std::string::size_type count = nSeg-iSeg;
        std::string path = fullPath.substr(iSeg, count);
        if ( ! path.empty() ) {
            vPath.push_back(fullPath.substr(iSeg, count));
        }
        iSeg = (nSeg == std::string::npos) ? nSeg : nSeg + 1;
    }

    if ( vPath.empty() ) vPath.push_back(fullPath);

    const std::string& fKey = vPath.front();
    std::map<std::string, TFile*>::iterator it = m_key2file.find(fKey);
    if ( it == m_key2file.end() ) {
        return result;
    }
    result = it->second;

    vPath.pop_front();
    while ( ! vPath.empty() ) {
        const std::string& path = vPath.front();
        TDirectory* pDir = result->GetDirectory( path.c_str() );
        if ( pDir == 0 ) {
            pDir = result->mkdir( path.c_str() );
        }
        result = pDir;
        vPath.pop_front();
    }

    return result;
}
const std::string& SvcBase::name ( void  ) [inline, inherited]

Definition at line 15 of file SvcBase.h.

{ return m_name; }
template<typename Type >
bool SvcBase::setOption ( const std::string &  option,
Type &  var 
) [inherited]

Definition at line 34 of file SvcBase.h.

{
    return OptionParser::setOption(m_name, option, var);
}

Member Data Documentation

std::map<std::string, TFile*> TOutputSvc::m_key2file [private]

Definition at line 51 of file TOutputSvc.h.

std::string SvcBase::m_name [protected, inherited]

Definition at line 25 of file SvcBase.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:50:18 for LafKernel by doxygen 1.7.4