Skip to content
Snippets Groups Projects
FaserSCT_SpacePointContainerCnv_p0.cxx 3.43 KiB
Newer Older
   Copyright (C) 2021 CERN for the benefit of the FASER collaboration
   */

#include "TrackerEventTPCnv/FaserSCT_SpacePointContainerCnv_p0.h"

#include "TrackerEventTPCnv/FaserSCT_SpacePoint_p0.h"
#include "TrackerEventTPCnv/FaserSCT_SpacePointCollection_p0.h"
#include "TrackerEventTPCnv/FaserSCT_SpacePointCnv_p0.h"
#include "TrackerSpacePoint/FaserSCT_SpacePointContainer.h"
void FaserSCT_SpacePointContainerCnv_p0::persToTrans(const FaserSCT_SpacePointContainer_p0* persObj, FaserSCT_SpacePointContainer* transObj, MsgStream& log) {
  FaserSCT_SpacePointCollection* coll = 0;
  FaserSCT_SpacePointCnv_p0 chanCnv;
  unsigned int collBegin(0);
  for (unsigned int icoll = 0; icoll < persObj->m_spacepoint_collections.size(); ++icoll) {
    const FaserSCT_SpacePointCollection_p0& pcoll = persObj->m_spacepoint_collections[icoll];
    IdentifierHash collIDHash(IdentifierHash(pcoll.m_idHash));
    coll = new FaserSCT_SpacePointCollection(collIDHash);
    coll->setIdentifier(Identifier(pcoll.m_id));
    unsigned int nchans           = pcoll.m_end - pcoll.m_begin;
    coll->resize(nchans);
    for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
      const FaserSCT_SpacePoint_p0* pchan=&(persObj->m_spacepoints[ichan+collBegin]);
      Tracker::FaserSCT_SpacePoint* transSP=nullptr;
      chanCnv.persToTrans(pchan, transSP, log);
      if(transSP==nullptr)std::cout<<"did not found space"<<std::endl;
      (*coll)[ichan]=transSP;
    }
    collBegin +=nchans;
    StatusCode sc = transObj->addCollection(coll, collIDHash);
    if (sc.isFailure()) 
      throw std::runtime_error("Failed to add collection to ID Container");

  }

}

void FaserSCT_SpacePointContainerCnv_p0::transToPers(const FaserSCT_SpacePointContainer* transObj, FaserSCT_SpacePointContainer_p0* persObj, MsgStream& log) {
  log << MSG::INFO << "FaserSCT_SpacePointContainerCnv_p0::transToPers()" << endmsg;

  FaserSCT_SpacePointCnv_p0 spCnv;
  typedef FaserSCT_SpacePointContainer TRANS;

  TRANS::const_iterator spColl;
  TRANS::const_iterator spCollEnd = transObj->end();
  unsigned int spCollId;
  unsigned int spId = 0;
  unsigned int nextSpId = 0;
  //unsigned int lastIdHash = 0;

  // resize data vectors
  persObj->m_spacepoint_collections.resize(transObj->numberOfCollections());
  int n_spacepoints = 0; 
  for (spColl = transObj->begin(); spColl != spCollEnd; spColl++)  {
    n_spacepoints += (*spColl)->size();
  }
  persObj->m_spacepoints.resize(n_spacepoints);

  for (spColl = transObj->begin(), spCollId = 0; spColl != spCollEnd; ++spCollId, ++spColl)  {
    // create persitent representation of FaserSCT_SpacePointCollections
    const FaserSCT_SpacePointCollection& collection = **spColl;
    FaserSCT_SpacePointCollection_p0& pcollection = persObj->m_spacepoint_collections[spCollId];
    pcollection.m_size = collection.size();
    pcollection.m_idHash = (unsigned int)collection.identifyHash();
    pcollection.m_id = collection.identify().get_compact();
    //lastIdHash = collection.identifyHash();

    spId = nextSpId;
    nextSpId += collection.size();

    pcollection.m_begin=spId;
    pcollection.m_end=nextSpId;

    // create persitent representation of FaserSCT_SpacePoints
    for (std::size_t i = 0; i < collection.size(); ++i) {
      FaserSCT_SpacePoint_p0* persSP = &(persObj->m_spacepoints[i + spId]);
      const Tracker::FaserSCT_SpacePoint* transSP = dynamic_cast<const Tracker::FaserSCT_SpacePoint*>(collection[i]);
      spCnv.transToPers(transSP, persSP, log);
    }
  }
}