/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 | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
SimHeaderCnv Class Reference

Converter between SimHeader and PerSimHeader. More...

#include <SimHeaderCnv.h>

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

List of all members.

Public Member Functions

 SimHeaderCnv (ISvcLocator *svc)
virtual ~SimHeaderCnv ()
StatusCode PerToTran (const PerSimHeader &tobj, DayaBay::SimHeader &dobj)
 Copy data from TObject based class of type TType to DataObject based class of type DOType.
StatusCode TranToPer (const DayaBay::SimHeader &dobj, PerSimHeader &tobj)
 Copy data from DataObject based class of type DOType to TObject based class of type TType.
StatusCode fillRepRefs (IOpaqueAddress *addr, DataObject *dobj)
StatusCode fillObjRefs (IOpaqueAddress *addr, DataObject *dobj)
PerType & getPerInputObject ()
PerType & getPerOutputObject ()
const RootIOBaseObjectgetBaseInputObject ()
const RootIOBaseObjectgetBaseOutputObject ()
virtual StatusCode PerToTran (const PerType &pobj, TranType &tobj)=0
virtual StatusCode TranToPer (const TranType &tobj, PerType &pobj)=0
virtual StatusCode TranObjectToPerObject (DataObject &dat, const RootOutputAddress &)
virtual StatusCode PerObjectToTranObject (DataObject *&dat)
virtual RootInputStreammakeInputStream (const RootInputAddress &ria)
virtual RootOutputStreammakeOutputStream (const RootOutputAddress &ria)
virtual long repSvcType () const
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode createObj (IOpaqueAddress *addr, DataObject *&dat)
virtual StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress)
int commit (const RootOutputAddress &roa)
RootIOBaseCnvotherConverter (int clID)

Static Public Member Functions

static const CLID & classID ()
static unsigned char storageType ()
static const InterfaceID & interfaceID ()

Protected Attributes

std::string m_perclassName
PerType * m_perInObj
PerType * m_perOutObj
IRootIOSvcm_rioSvc
IConversionSvc * m_cnvSvc
RootInputStreamm_ris

Private Member Functions

DayaBay::SimParticleHistoryconvert (std::vector< DayaBay::SimTrack * > &timap, DayaBay::SimHeader &sh, const PerSimParticleHistory &pph)
PerSimParticleHistoryconvert (std::map< const DayaBay::SimTrack *, int > &trackMap, const DayaBay::SimParticleHistory &ph)
DayaBay::SimHitCollectionconvert (std::vector< DayaBay::SimTrack * > &timap, const PerSimHitCollection &phc)
PerSimHitCollectionconvert (std::map< const DayaBay::SimTrack *, int > &trackMap, const DayaBay::SimHitCollection &hc)
DayaBay::SimUnobservableStatisticsHeaderconvert (const PerSimUnobservableStatistics &pstat)
PerSimUnobservableStatisticsconvert (const DayaBay::SimUnobservableStatisticsHeader &stat)
void relate (DayaBay::SimHeader &sh)

Private Attributes

int m_maxNoPHtoS
int m_NoPHtoSmsgs
bool m_pruneSimHits

Detailed Description

Converter between SimHeader and PerSimHeader.

bv@bnl.gov Thu Aug 14 17:04:08 2008

Definition at line 29 of file SimHeaderCnv.h.


Constructor & Destructor Documentation

SimHeaderCnv::SimHeaderCnv ( ISvcLocator *  svc)

Definition at line 13 of file SimHeaderCnv.cc.

    : RootIOTypedCnv<PerSimHeader,SimHeader>("PerSimHeader",
                                             classID(),svc)
{
    // set maximum number of warnings of "no particle history to save"
    m_maxNoPHtoS = 10;
    m_NoPHtoSmsgs=  0;

    m_pruneSimHits = false;
    char* foo = getenv("NUWA_PRUNESIMHITS");
    if (foo) {
        m_pruneSimHits = true;
    }
}
SimHeaderCnv::~SimHeaderCnv ( ) [virtual]

Definition at line 28 of file SimHeaderCnv.cc.

{
}

Member Function Documentation

static const CLID& SimHeaderCnv::classID ( ) [inline, static]

Definition at line 33 of file SimHeaderCnv.h.

                                 {
        return DayaBay::CLID_SimHeader;
    }
StatusCode SimHeaderCnv::PerToTran ( const PerSimHeader tobj,
DayaBay::SimHeader dobj 
)

Copy data from TObject based class of type TType to DataObject based class of type DOType.

Definition at line 33 of file SimHeaderCnv.cc.

{
    StatusCode sc = HeaderObjectCnv::toTran(perobj,tranobj);
    if (sc.isFailure()) return sc;

    MsgStream log(msgSvc(), "SimHeaderCnv::PerToTran");

    // Convert the historian part
    vector<SimTrack*> timap;
    const PerSimParticleHistory* pph = perobj.history;
    if (!pph) {
        log << MSG::DEBUG
            << "No particle history in persistent object." << endreq;
        tranobj.setParticleHistory(0);
    }
    else {
        SimParticleHistory* ph = convert(timap,tranobj,*pph);
        if (ph) {
            tranobj.setParticleHistory(ph);
        }
        else {
            log << MSG::ERROR
                << "Failed to convert the SimParticleHistory" << endreq;
        }
    }

    if (perobj.hits) { // Convert the Hits part
        const PerSimHitHeader::phc_map& pcolmap = perobj.hits->hitCollections;

        log << MSG::DEBUG << "Reading " << pcolmap.size() << " hit collections" << endreq;

        SimHitHeader* shit_header = new SimHitHeader;
        shit_header->setHeader(&tranobj);
        tranobj.setHits(shit_header);

        PerSimHitHeader::phc_map::const_iterator it, done = pcolmap.end();
        for (it = pcolmap.begin(); it != done; ++it) {
            int detectorID = it->first;
            const PerSimHitCollection* phc = it->second;
            SimHitCollection* hc = convert(timap,*phc);
            hc->setHeader(shit_header);
            shit_header->addHitCollection(hc);

            DayaBay::Detector det((short)detectorID);
            log << MSG::DEBUG << "Reading " << phc->hits.size() 
                << " hits for detector " << det.detName()
                << " ("
                << detectorID 
                << ")"
                << endreq;
        }
    }
    else {
        log << MSG::DEBUG << "No persistent hits to convert" << endreq;
    }

    { // Convert the stats part
        const PerSimUnobservableStatistics* pstat = perobj.stats;
        if (!pstat) {
            log << MSG::DEBUG
                << "No unobservable statistics in persistent object." << endreq;
            tranobj.setUnobservableStatistics(0);
        }
        else {
            SimUnobservableStatisticsHeader* stat = convert(*pstat);
            tranobj.setUnobservableStatistics(stat);
        }
    }

    return StatusCode::SUCCESS;
}
StatusCode SimHeaderCnv::TranToPer ( const DayaBay::SimHeader dobj,
PerSimHeader tobj 
)

Copy data from DataObject based class of type DOType to TObject based class of type TType.

Definition at line 106 of file SimHeaderCnv.cc.

{
    StatusCode sc = HeaderObjectCnv::toPer(tranobj,perobj);
    if (sc.isFailure()) return sc;

    MsgStream log(msgSvc(), "SimHeaderCnv::TranToPer");

    map<const SimTrack*,int> trackMap;

    { // Convert the historian part
        const SimParticleHistory* ph = tranobj.particleHistory();
        delete perobj.history;
        if (!ph) {
          m_NoPHtoSmsgs += 1;
          if ( m_NoPHtoSmsgs < m_maxNoPHtoS ) {
            log << MSG::WARNING
                << "No Particle history to save" << endreq;
          }
          if ( m_NoPHtoSmsgs == m_maxNoPHtoS ) {
            log << MSG::WARNING
                << "No Particle history to save. Additional warnings will be suppressed. " << endreq;
          }
          
            perobj.history = 0;
        }
        else {
            PerSimParticleHistory* pph = convert(trackMap,*ph);
            perobj.history = pph;
        }
    }

    { // Convert the Hits part
        if (perobj.hits) {
            delete perobj.hits;
            perobj.hits = 0;
        }
        perobj.hits = new PerSimHitHeader();
        PerSimHitHeader::phc_map& phcolmap = perobj.hits->hitCollections;
        if (m_pruneSimHits) {
            static int count = 0; 
            ++count;
            if (count<10) {
                log << MSG::INFO << "Not saving SimHits, will say " << 10-count << " more times" << endreq;
            }
        }
        else {
            const SimHitHeader* header = tranobj.hits();
            if (!header) {
                static int count = 0; 
                if (count++ < 10) {
                    log << MSG::WARNING << "No Hit Header (I will say it " 
                        << 10 - count << " times again)" << endreq;
                }
            }
            else {
                const SimHitHeader::hc_map& colmap = header->hitCollection();
                
                log << MSG::DEBUG << "Saving " << colmap.size() << " hit collections" << endreq;
                
                SimHitHeader::hc_map::const_iterator it, done = colmap.end();
                for (it = colmap.begin(); it != done; ++it) {
                    int detectorID = it->first;
                    static int nUnknownDet = 0;
                    if( detectorID == DetectorId::kUnknown ) {
                        nUnknownDet++;
                        if( nUnknownDet<10 ) {
                            log << MSG::WARNING << "No hit should be from unknown detector (I will say it "
                                << 10 - nUnknownDet << " times again)" << endreq;
                        }
                    } 
                    else {
                        const SimHitCollection* hc = it->second;
                        PerSimHitCollection* phc = convert(trackMap,*hc);
                        phcolmap[detectorID] = phc;
                        DayaBay::Detector det((short)detectorID);
                        log << MSG::DEBUG << "Saving " << phc->hits.size() 
                            << " hits for detector " << det.detName()
                            << " ("
                            << detectorID 
                            << ")"
                            << endreq;
                    }
                }
            }
        }
        log << MSG::DEBUG << "Saving " << phcolmap.size() << " hit collections" << endreq;
    }    

    { // Convert the stats part
        const SimUnobservableStatisticsHeader* stat = tranobj.unobservableStatistics();
        if (!stat) {
            log << MSG::DEBUG
                << "No unobservable statistics" << endreq;
        }
        else {
            PerSimUnobservableStatistics* pstat = convert(*stat);
            delete perobj.stats;
            perobj.stats = pstat;
        }
    }

    return StatusCode::SUCCESS;
}
StatusCode SimHeaderCnv::fillRepRefs ( IOpaqueAddress *  addr,
DataObject *  dobj 
) [virtual]

Reimplemented from RootIOTypedCnv< PerSimHeader, DayaBay::SimHeader >.

Definition at line 213 of file SimHeaderCnv.cc.

{
    MsgStream log(msgSvc(), "SimHeaderCnv::fillRepRefs");
    SimHeader* sh = dynamic_cast<SimHeader*>(dobj);

    log << MSG::DEBUG
        << "Saving links to " << sh->inputHeaders().size() 
        << " input headers" << endreq;

    StatusCode sc = HeaderObjectCnv::fillPer(m_rioSvc,*sh,*m_perOutObj);
    if (sc.isFailure()) {
        log << MSG::ERROR << "Failed to fill HeaderObject part" << endreq;
        return sc;
    }

    // ... fill SimHeader part...
    return sc;
}
StatusCode SimHeaderCnv::fillObjRefs ( IOpaqueAddress *  addr,
DataObject *  dobj 
) [virtual]

Reimplemented from RootIOTypedCnv< PerSimHeader, DayaBay::SimHeader >.

Definition at line 232 of file SimHeaderCnv.cc.

{
    MsgStream log(msgSvc(), "SimHeaderCnv::fillObjRefs");
    HeaderObject* hobj = dynamic_cast<HeaderObject*>(dobj);
    StatusCode sc = HeaderObjectCnv::fillTran(m_rioSvc,*m_perInObj,*hobj);
    if (sc.isFailure()) {
        log << MSG::ERROR << "Failed to fill HeaderObject part" << endreq;
        return sc;
    }

    log << MSG::DEBUG
        << "Restored links to " << hobj->inputHeaders().size() 
        << " input headers" << endreq;

    // ... fill SimHeader part...

    DayaBay::SimHeader* sh = dynamic_cast<DayaBay::SimHeader*>(hobj);
    relate(*sh);

    return sc;
}
DayaBay::SimParticleHistory* SimHeaderCnv::convert ( std::vector< DayaBay::SimTrack * > &  timap,
DayaBay::SimHeader sh,
const PerSimParticleHistory pph 
) [private]
PerSimParticleHistory* SimHeaderCnv::convert ( std::map< const DayaBay::SimTrack *, int > &  trackMap,
const DayaBay::SimParticleHistory ph 
) [private]
DayaBay::SimHitCollection* SimHeaderCnv::convert ( std::vector< DayaBay::SimTrack * > &  timap,
const PerSimHitCollection phc 
) [private]
PerSimHitCollection* SimHeaderCnv::convert ( std::map< const DayaBay::SimTrack *, int > &  trackMap,
const DayaBay::SimHitCollection hc 
) [private]
DayaBay::SimUnobservableStatisticsHeader * SimHeaderCnv::convert ( const PerSimUnobservableStatistics pstat) [private]

Definition at line 13 of file SimHeaderCnvStats.cc.

{
    SimUnobservableStatisticsHeader* stat = new SimUnobservableStatisticsHeader;
    SimUnobservableStatisticsHeader::stat_map& stats = stat->stats();

    std::map<string,PerSimStat>::const_iterator it, done = pstat.stats.end();
    for (it = pstat.stats.begin(); it != done; ++it) {
        SimStatistic ss;
        ss.setCount(it->second.count);
        ss.setSum(it->second.sum);
        ss.setSquaredsum(it->second.squaredsum);
        stats[it->first] = ss;
    }

    return stat;
}
PerSimUnobservableStatistics * SimHeaderCnv::convert ( const DayaBay::SimUnobservableStatisticsHeader stat) [private]

Definition at line 31 of file SimHeaderCnvStats.cc.

{
    PerSimUnobservableStatistics* pstat = new PerSimUnobservableStatistics;
    std::map<std::string,PerSimStat>& pstats = pstat->stats;
    
    const SimUnobservableStatisticsHeader::stat_map& stats = stat.stats();
    SimUnobservableStatisticsHeader::stat_map::const_iterator it, done = stats.end();
    for (it = stats.begin(); it != done; ++it) {
        pstats[it->first] = 
            PerSimStat(it->second.count(),it->second.sum(),it->second.squaredsum());
    }
    return pstat;
}
void SimHeaderCnv::relate ( DayaBay::SimHeader sh) [private]

Definition at line 261 of file SimHeaderCnvHistory.cc.

{
    MsgStream log(msgSvc(), "SimHeaderCnvHistory::relate(p2t)");
    const HepMC::GenEvent* genEvent = 0;
    const std::vector<const DayaBay::IHeader*>& inputHeaders = sh.inputHeaders();
    log << MSG::DEBUG 
        << "Checking for GenHeader in " 
        << inputHeaders.size() << " input headers" 
        << endreq;
    for (size_t ind=0; ind<inputHeaders.size(); ++ind) {
        const GenHeader* genHeader = dynamic_cast<const GenHeader*>(inputHeaders[ind]);
        if (1) {
            const HeaderObject* ho = dynamic_cast<const HeaderObject*>(inputHeaders[ind]);
            log << MSG::DEBUG
                << "checking " << ind << "/" << inputHeaders.size() 
                << ": " << ho->name()
                << endreq;
        }
        if (!genHeader) continue;
        genEvent = genHeader->event();
    }
    if (!genEvent) {
        log << MSG::DEBUG
            << "Could not find the HepMC::GenEvent used to create me." 
            << endreq;
        return;
    }
    

    if (!m_perInObj->history) {
        log << MSG::DEBUG
            << "No persistent particle history"
            << endreq;
        return;
    }
    const PerSimParticleHistory& pph = *(m_perInObj->history);
    if (!sh.particleHistory()) {
        log << MSG::ERROR
            << "No transient particle history"
            << endreq;
        return;
    }

    // Sometimes the genEvent barcodes for particles and vertices has been pruned
    // in the production of the original file. Report this here and
    // suppress issuing an ERROR for every particle that does not have a barcodes.
    bool empty = genEvent->particles_empty() && genEvent->vertices_empty() ;
    if (empty) log << MSG::INFO << "No GenEvent particles or vertices exist"<< endreq;


    const list<SimTrack*>& tracks = sh.particleHistory()->tracks();
    list<SimTrack*>::const_iterator it, done = tracks.end();
    size_t ind=0;
    for (it=tracks.begin(); it !=done && ind < pph.tracks.size(); ++ind, ++it) {
        PerSimTrack* ptrack = pph.tracks[ind];
        SimTrack* track = *it;

        if (genEvent) {
            int barcode = ptrack->primaryParticle;

            if (barcode < 0) {
                track->setPrimaryParticle(0);
            }
            else {
                const HepMC::GenParticle* part = genEvent->barcode_to_particle(barcode);
                if (part) {
                    track->setPrimaryParticle(part);
                }
                else {
                  if (!empty){
                    log << MSG::ERROR
                        << "Failed to get a primary particle for barcode " << barcode << endreq;
                  }
                }
            }
        }
    }
}
PerType & RootIOTypedCnv< class, class >::getPerInputObject ( ) [inherited]
PerType & RootIOTypedCnv< class, class >::getPerOutputObject ( ) [inherited]
const RootIOBaseObject * RootIOTypedCnv< class, class >::getBaseInputObject ( ) [virtual, inherited]

Implements RootIOBaseCnv.

const RootIOBaseObject * RootIOTypedCnv< class, class >::getBaseOutputObject ( ) [virtual, inherited]

Implements RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::PerToTran ( const PerType &  pobj,
TranType &  tobj 
) [pure virtual, inherited]
virtual StatusCode RootIOTypedCnv< class, class >::TranToPer ( const TranType &  tobj,
PerType &  pobj 
) [pure virtual, inherited]
virtual StatusCode RootIOTypedCnv< class, class >::TranObjectToPerObject ( DataObject &  dat,
const RootOutputAddress  
) [virtual, inherited]

Implements RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::PerObjectToTranObject ( DataObject *&  dat) [virtual, inherited]

Implements RootIOBaseCnv.

virtual RootInputStream * RootIOTypedCnv< class, class >::makeInputStream ( const RootInputAddress ria) [virtual, inherited]

Implements RootIOBaseCnv.

virtual RootOutputStream * RootIOTypedCnv< class, class >::makeOutputStream ( const RootOutputAddress ria) [virtual, inherited]

Implements RootIOBaseCnv.

virtual long RootIOTypedCnv< class, class >::repSvcType ( ) const [virtual, inherited]

Reimplemented from RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::initialize ( ) [virtual, inherited]

Reimplemented from RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::finalize ( ) [virtual, inherited]

Reimplemented from RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::createObj ( IOpaqueAddress *  addr,
DataObject *&  dat 
) [virtual, inherited]

Reimplemented from RootIOBaseCnv.

virtual StatusCode RootIOTypedCnv< class, class >::createRep ( DataObject *  pObject,
IOpaqueAddress *&  refpAddress 
) [virtual, inherited]

Reimplemented from RootIOBaseCnv.

int RootIOTypedCnv< class, class >::commit ( const RootOutputAddress roa) [inherited]

Reimplemented from RootIOBaseCnv.

RootIOBaseCnv * RootIOTypedCnv< class, class >::otherConverter ( int  clID) [inherited]

Reimplemented from RootIOBaseCnv.

static unsigned char RootIOTypedCnv< class, class >::storageType ( ) [static, inherited]

Reimplemented from RootIOBaseCnv.

static const InterfaceID & RootIOTypedCnv< class, class >::interfaceID ( ) [static, inherited]

Reimplemented from RootIOBaseCnv.


Member Data Documentation

Definition at line 80 of file SimHeaderCnv.h.

Definition at line 80 of file SimHeaderCnv.h.

Definition at line 83 of file SimHeaderCnv.h.

std::string RootIOTypedCnv< class, class >::m_perclassName [protected, inherited]
PerType * RootIOTypedCnv< class, class >::m_perInObj [protected, inherited]
PerType * RootIOTypedCnv< class, class >::m_perOutObj [protected, inherited]
IRootIOSvc * RootIOTypedCnv< class, class >::m_rioSvc [protected, inherited]

Reimplemented from RootIOBaseCnv.

IConversionSvc * RootIOTypedCnv< class, class >::m_cnvSvc [protected, inherited]

Reimplemented from RootIOBaseCnv.

RootInputStream * RootIOTypedCnv< class, class >::m_ris [protected, inherited]

Reimplemented from RootIOBaseCnv.


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 10:07:23 for PerSimEvent by doxygen 1.7.4