/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 | Private Types | Private Member Functions | Private Attributes
EvtSkimmer Class Reference

#include <EvtSkimmer.h>

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

List of all members.

Public Member Functions

 EvtSkimmer (const std::string &name)
virtual ~EvtSkimmer ()
virtual bool write (PhyEvent *evt)
const std::string & name ()

Private Types

typedef std::map< std::string,
std::pair< TTree *, TTree * > > 
TreeMap

Private Member Functions

bool updateTrees (PhyEvent *evt)
TDirectory * getDir (const std::string &fullPath)

Private Attributes

TFile * m_file
TFile * m_ifile
int m_fNum
TreeMap m_treeMap
ReconInputSvcm_svc

Detailed Description

Definition at line 13 of file EvtSkimmer.h.


Member Typedef Documentation

typedef std::map<std::string, std::pair<TTree*, TTree*> > EvtSkimmer::TreeMap [private]

Definition at line 27 of file EvtSkimmer.h.


Constructor & Destructor Documentation

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

Definition at line 11 of file EvtSkimmer.cc.

    : ISkimmer(name),
      m_file(0),
      m_ifile(0),
      m_fNum(-1)
{
    std::vector<std::string> treeNames;
    OptionParser::setOption(this->name(), "OutputTrees", treeNames);
    if ( treeNames.empty() ) {
        LogWarn << "No OutputTrees in EvtFilterSvc!" << std::endl;
    }
    for ( std::vector<std::string>::iterator it = treeNames.begin(); it != treeNames.end(); ++it ) {
        m_treeMap[*it] = std::make_pair<TTree*, TTree*>(0, 0);
    }

    std::string fname;
    OptionParser::setOption(this->name(), "OutputFile", fname);
    if ( fname.empty() ) {
        throw LafException(this->name() + ".OutputFile is not set properly!");
    }

    const char* preDir = gDirectory->GetPath();
    m_file = new TFile(fname.c_str(), "RECREATE");
    gDirectory->cd(preDir);

    m_svc = SvcMgr::get<ReconInputSvc>("InputSvc");
    if ( m_svc == 0 ) {
        throw LafException(this->name() + ": Failed to get ReconInputSvc!");
    }
}
EvtSkimmer::~EvtSkimmer ( ) [virtual]

Definition at line 42 of file EvtSkimmer.cc.

{
    m_file->Write();
    delete m_file;
    delete m_ifile;
}

Member Function Documentation

bool EvtSkimmer::write ( PhyEvent evt) [virtual]

Implements ISkimmer.

Definition at line 49 of file EvtSkimmer.cc.

{
    if ( m_fNum == evt->m_fileNum || updateTrees(evt) ) {
        for ( TreeMap::iterator it = m_treeMap.begin(); it != m_treeMap.end(); ++it ) {
            it->second.first->GetEntry(evt->m_localEntry);
            it->second.second->Fill();
        }
        return true;
    }

    return false;
}
bool EvtSkimmer::updateTrees ( PhyEvent evt) [private]

Definition at line 62 of file EvtSkimmer.cc.

                                          {
    m_fNum = evt->m_fileNum;
    if ( m_ifile != 0 ) {
        m_ifile->Close();
        delete m_ifile;
    }

    const char* preDir = gDirectory->GetPath();
    m_ifile = new TFile(m_svc->fname(m_fNum).c_str());
    for ( TreeMap::iterator it = m_treeMap.begin(); it != m_treeMap.end(); ++it ) {
        TTree* tree = (TTree*)m_ifile->Get(it->first.c_str());
        if( tree == 0 ) {
            LogError << "Can't find tree \"" << it->first << "\" in file " << m_svc->fname(m_fNum) << std::endl;
            return false;
        }
        if ( it->second.second == 0 ) {  //first input file
            TDirectory* dir = getDir(it->first);
            dir->cd();
            it->second = std::make_pair(tree, tree->CloneTree(0) );
        }
        else {
            it->second.first = tree;
            tree->CopyAddresses(it->second.second);
        }
    }
    gDirectory->cd(preDir);

    return true;
}
TDirectory * EvtSkimmer::getDir ( const std::string &  fullPath) [private]

Definition at line 92 of file EvtSkimmer.cc.

{
    TDirectory* result = m_file;

    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;
    }

    vPath.pop_back();

    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& ISkimmer::name ( void  ) [inline, inherited]

Definition at line 17 of file ISkimmer.h.

{ return m_name; }

Member Data Documentation

TFile* EvtSkimmer::m_file [private]

Definition at line 29 of file EvtSkimmer.h.

TFile* EvtSkimmer::m_ifile [private]

Definition at line 30 of file EvtSkimmer.h.

int EvtSkimmer::m_fNum [private]

Definition at line 31 of file EvtSkimmer.h.

Definition at line 32 of file EvtSkimmer.h.

Definition at line 34 of file EvtSkimmer.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:51:14 for EvtFilterSvc by doxygen 1.7.4