/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 Attributes
GenHeaderCnv Class Reference

Convert a GenHeader and its subobjects. More...

#include <GenHeaderCnv.h>

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

List of all members.

Public Member Functions

 GenHeaderCnv (ISvcLocator *svc)
virtual ~GenHeaderCnv ()
StatusCode PerToTran (const PerGenHeader &tobj, DayaBay::GenHeader &dobj)
 Copy data from TObject based class of type TType to DataObject based class of type DOType.
StatusCode TranToPer (const DayaBay::GenHeader &dobj, PerGenHeader &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 Attributes

int m_maxVertices

Detailed Description

Convert a GenHeader and its subobjects.

bv@bnl.gov Wed Aug 6 16:10:24 2008

Definition at line 19 of file GenHeaderCnv.h.


Constructor & Destructor Documentation

GenHeaderCnv::GenHeaderCnv ( ISvcLocator *  svc)

Definition at line 7 of file GenHeaderCnv.cc.

    : RootIOTypedCnv<PerGenHeader,GenHeader>("PerGenHeader",
                                             classID(),svc)
{
  // Set threshold for maximum number of vertices.
  // GenHeaders with more vertices will not be written out 
  // This is temporary for MDC10a
  // wangzhe
  // Raise it to 50 for safe. When adding muon spallation background, it is ofter above 10.
  m_maxVertices = 50;  
  // Wz 
  MsgStream log(msgSvc(), "GenHeaderCnv");

  log << MSG::INFO 
      << "Only minimal GenHeader info will be persisted for GenHeaders with > " 
      << m_maxVertices 
      << " vertices. THIS IS TEMPORARY FOR MDC10a."<<endreq;
}
GenHeaderCnv::~GenHeaderCnv ( ) [virtual]

Definition at line 26 of file GenHeaderCnv.cc.

{
}

Member Function Documentation

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

Definition at line 23 of file GenHeaderCnv.h.

                                 {
        return DayaBay::CLID_GenHeader;
    }
StatusCode GenHeaderCnv::PerToTran ( const PerGenHeader tobj,
DayaBay::GenHeader dobj 
)

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

Definition at line 32 of file GenHeaderCnv.cc.

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

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

  tranobj.setGeneratorName(perobj.name);

  PerGenEvent* pgevt = perobj.event;
  if (!pgevt) {
    tranobj.setEvent(0);
    log << MSG::WARNING
        << "Null PerGenEvent pointer"
        << endreq;
    return StatusCode::SUCCESS;
  }

  HepMC::GenEvent* gevt = new HepMC::GenEvent(pgevt->signalProcessId, 
                                              pgevt->eventNumber,
                                              0,
                                              pgevt->weights);

  // Map from persistent to transient particles
  std::map<PerGenParticle*,HepMC::GenParticle*> particleMap;
  for (size_t ind=0; ind<pgevt->particles.size(); ++ind) {
    PerGenParticle* pgpart = pgevt->particles[ind];
    HepMC::GenParticle* gpart = 
      new HepMC::GenParticle(pgpart->momentum,
                             pgpart->pdgId,
                             pgpart->status,
                             HepMC::Flow(),
                             HepMC::Polarization(pgpart->polTheta,
                                                 pgpart->polPhi));

    particleMap[pgpart] = gpart;
  }

  // Convert vertices and add in/out particles
  std::map<PerGenVertex*,HepMC::GenVertex*> vertexMap;
  for (size_t ind=0; ind<pgevt->vertices.size(); ++ind) {
    PerGenVertex* pgvtx = pgevt->vertices[ind];
    HepMC::GenVertex* gvtx = new HepMC::GenVertex(pgvtx->position,
                                                  pgvtx->id,
                                                  pgvtx->weights);
    gevt->add_vertex(gvtx);
    for (size_t pi_ind=0; pi_ind < pgvtx->particlesIn.size(); ++pi_ind) {
      PerGenParticle* pgpart = pgevt->particles[pgvtx->particlesIn[pi_ind]];
      HepMC::GenParticle* gpart = particleMap[pgpart];
      gvtx->add_particle_in(gpart);
    }
    for (size_t po_ind=0; po_ind < pgvtx->particlesOut.size(); ++po_ind) {
      PerGenParticle* pgpart = pgevt->particles[pgvtx->particlesOut[po_ind]];
      HepMC::GenParticle* gpart = particleMap[pgpart];
      gvtx->add_particle_out(gpart);
    }

    if ((int)ind == pgevt->signalProcessIndex) {
      gevt->set_signal_process_vertex(gvtx);
    }
  }

  tranobj.setEvent(gevt);

  return StatusCode::SUCCESS;
}
StatusCode GenHeaderCnv::TranToPer ( const DayaBay::GenHeader dobj,
PerGenHeader tobj 
)

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

Definition at line 101 of file GenHeaderCnv.cc.

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

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

  perobj.name = tranobj.generatorName();

  const HepMC::GenEvent* genevt = tranobj.event();

  if (!genevt) {
    perobj.event = 0;
    log << MSG::WARNING
        << "Null HepMC::GenEvent pointer"
        << endreq;
    return StatusCode::SUCCESS;
  }

  PerGenEvent* pgevt = new PerGenEvent();

  // Fill the event

  // Basic stuff
  pgevt->eventNumber = genevt->event_number();
  pgevt->signalProcessId = genevt->signal_process_id();


  // Only save vertices when there are a few. 
  // This is temporary for MDC10a
  log << MSG::DEBUG << "# vertices = " << genevt->vertices_size() << endreq;
  if (genevt->vertices_size() <= m_maxVertices ){
    log << MSG::DEBUG << "Saving all vertices " << endreq;

    // Weights
    const HepMC::WeightContainer& weights = genevt->weights();
    pgevt->weights.clear();
    pgevt->weights.insert(pgevt->weights.begin(),
                          weights.begin(), weights.end());
    
    // Particles - first pass
    std::map<HepMC::GenParticle*,int> particleIndexMap;
    pgevt->particles.clear();
    HepMC::GenEvent::particle_const_iterator pit, 
      pdone = genevt->particles_end();
    for (pit = genevt->particles_begin(); pit != pdone; ++pit) {
      HepMC::GenParticle* gpart = *pit;
      particleIndexMap[gpart] = pgevt->particles.size(); // for later lookup
      CLHEP::HepLorentzVector momentum(gpart->momentum().x(),
                                       gpart->momentum().y(),
                                       gpart->momentum().z(),
                                       gpart->momentum().t());
      PerGenParticle* pgpart = 
        new PerGenParticle(momentum,
                           gpart->pdg_id(),
                           gpart->status(),
                           gpart->polarization().theta(),
                           gpart->polarization().phi(),
                           gpart->barcode());
      pgevt->particles.push_back(pgpart);
    }

    // Vertices
    pgevt->vertices.clear();
    HepMC::GenVertex* signal_process_vertex = genevt->signal_process_vertex();
    HepMC::GenEvent::vertex_const_iterator vit,
      vdone = genevt->vertices_end();
    for (vit = genevt->vertices_begin(); vit != vdone; ++vit) {
      HepMC::GenVertex* gvtx = *vit;
      CLHEP::HepLorentzVector position(gvtx->position().x(),
                                       gvtx->position().y(),
                                       gvtx->position().z(),
                                       gvtx->position().t());
      PerGenVertex* pgvtx = 
        new PerGenVertex(position,
                         gvtx->id(),
                         gvtx->barcode(),
                         gvtx->weights());
      
      // Fill in particle info
      HepMC::GenVertex::particles_in_const_iterator piit, 
        pidone = gvtx->particles_in_const_end();
      for (piit = gvtx->particles_in_const_begin(); piit != pidone; ++piit) {
        std::map<HepMC::GenParticle*,int>::iterator pimit = 
          particleIndexMap.find(*piit);
        if (pimit != particleIndexMap.end()) {
          pgvtx->particlesIn.push_back(pimit->second);
        }
      }
      // Fill out particle info
      HepMC::GenVertex::particles_out_const_iterator poit, 
        podone = gvtx->particles_out_const_end();
      for (poit = gvtx->particles_out_const_begin(); poit != podone; ++poit) {
        std::map<HepMC::GenParticle*,int>::iterator pomit = 
          particleIndexMap.find(*poit);
        if (pomit != particleIndexMap.end()) {
          pgvtx->particlesOut.push_back(pomit->second);
        }
      }
      
      if (signal_process_vertex == gvtx) {
        pgevt->signalProcessIndex = pgevt->vertices.size();
      }
      pgevt->vertices.push_back(pgvtx);
    }
  }
  else {
    log << MSG::DEBUG << "Not saving any vertices " << endreq;
  } //(genevt->vertices_size() <= m_maxVertices )
  
  delete perobj.event;
  perobj.event = pgevt;
  return StatusCode::SUCCESS;
}
StatusCode GenHeaderCnv::fillRepRefs ( IOpaqueAddress *  addr,
DataObject *  dobj 
) [virtual]

Reimplemented from RootIOTypedCnv< PerGenHeader, DayaBay::GenHeader >.

Definition at line 217 of file GenHeaderCnv.cc.

{
    MsgStream log(msgSvc(), "GenHeaderCnv::fillRepRefs");
    GenHeader* gh = dynamic_cast<GenHeader*>(dobj);

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

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

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

Reimplemented from RootIOTypedCnv< PerGenHeader, DayaBay::GenHeader >.

Definition at line 236 of file GenHeaderCnv.cc.

{
    MsgStream log(msgSvc(), "GenHeaderCnv::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 GenHeader part...
    return sc;
}
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 48 of file GenHeaderCnv.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:16 for PerGenEvent by doxygen 1.7.4