diff --git a/Examples/options/LCIO_read.py b/Examples/options/LCIO_read.py index 372754e269fd92a66bd47f1c6e51038f211c2ac1..8beafb9314a4fbf300b567ded81cecd3d8204715 100644 --- a/Examples/options/LCIO_read.py +++ b/Examples/options/LCIO_read.py @@ -2,8 +2,14 @@ from Gaudi.Configuration import * -from Configurables import LCIODataSvc -dsvc = LCIODataSvc("EventDataSvc", input="/cefs/data/FullSim/CEPC240/CEPC_v4/higgs/E240.Pe2e2h_bb.e0.p0.whizard195/e2e2h_bb.e0.p0.00001_000000_sim.slcio") +from Configurables import LCIODataSvc, CEPCDataSvc + +svcname = "LCIODataSvc" +rsvc = LCIODataSvc(svcname, inputs = [ +"/cefs/data/FullSim/CEPC240/CEPC_v4/higgs/smart_final_states/E240.Pffh_invi.e0.p0.whizard195//ffh_inv.e0.p0.00001_1000_sim.slcio" +]) + +wsvc = CEPCDataSvc("EventDataSvc") from Configurables import PlcioReadAlg alg = PlcioReadAlg("PlcioReadAlg") @@ -14,33 +20,42 @@ from Configurables import LCIOInput lcioinput = LCIOInput("LCIOReader", collections=[ "EventHeader", "MCParticle", - "COILCollection", - "EcalBarrelSiliconCollection", - "EcalBarrelSiliconPreShowerCollection", - "EcalEndcapRingCollection", - "EcalEndcapRingPreShowerCollection", - "EcalEndcapSiliconCollection", - "EcalEndcapSiliconPreShowerCollection", - "FTD_PIXELCollection", - "FTD_STRIPCollection", - "HcalBarrelCollection", - "HcalEndCapRingsCollection", - "HcalEndCapsCollection", - "LumiCalCollection", - "MuonBarrelCollection", - "MuonEndCapCollection", - "SETCollection", - "SITCollection", - "TPCCollection", - "TPCSpacePointCollection", - "VXDCollection" + "TPCCollection" + #"EventHeader", + #"MCParticle", + #"COILCollection", + #"EcalBarrelSiliconCollection", + #"EcalBarrelSiliconPreShowerCollection", + #"EcalEndcapRingCollection", + #"EcalEndcapRingPreShowerCollection", + #"EcalEndcapSiliconCollection", + #"EcalEndcapSiliconPreShowerCollection", + #"FTD_PIXELCollection", + #"FTD_STRIPCollection", + #"HcalBarrelCollection", + #"HcalEndCapRingsCollection", + #"HcalEndCapsCollection", + #"LumiCalCollection", + #"MuonBarrelCollection", + #"MuonEndCapCollection", + #"SETCollection", + #"SITCollection", + #"TPCCollection", + #"TPCSpacePointCollection", + #"VXDCollection" ]) +lcioinput.DataSvc = svcname + +from Configurables import PodioOutput +plcioout = PodioOutput("PlcioWriter") +plcioout.filename = "lcio2plcio.root" +plcioout.outputCommands = ["keep *"] # ApplicationMgr from Configurables import ApplicationMgr -ApplicationMgr( TopAlg = [lcioinput, alg], +ApplicationMgr( TopAlg = [lcioinput, alg, plcioout], EvtSel = 'NONE', EvtMax = 10, - ExtSvc = [dsvc], + ExtSvc = [rsvc, wsvc], OutputLevel=DEBUG ) diff --git a/FWCore/FWCore/LCIODataSvc.h b/FWCore/FWCore/LCIODataSvc.h index 9627a8b73462d52360908899cac5aacc39757a56..8bfa3261f7d4e6da0da9e4dc860aaa9a282f8f58 100644 --- a/FWCore/FWCore/LCIODataSvc.h +++ b/FWCore/FWCore/LCIODataSvc.h @@ -73,6 +73,8 @@ private: IO::LCReader* m_reader; /// LCIO reader for ROOT files plcio::EventHeaderCollection* pl_evtcol; + /// the handle of DataProvider + IDataProviderSvc* m_pIDP{nullptr}; /// podio::ROOTReader m_reader; /// LCIO EventStore, used to initialise collections /// podio::EventStore m_provider; @@ -80,6 +82,8 @@ private: int m_eventNum{0}; /// Number of events in the file / to process int m_eventMax{-1}; + /// the current file index in the m_filenames vector + int m_fileIndex{0}; SmartIF<IConversionSvc> m_cnvSvc; diff --git a/FWCore/src/components/LCIO2Plcio.cpp b/FWCore/src/components/LCIO2Plcio.cpp index ac853eaaa2f0c4ace3a84ef82fa8a45ea549ffca..26a2204091ede7017f67b41456a8c51df157ad8c 100644 --- a/FWCore/src/components/LCIO2Plcio.cpp +++ b/FWCore/src/components/LCIO2Plcio.cpp @@ -11,18 +11,47 @@ typedef std::vector<EVENT::MCParticle*> MCParticleVec ; -//std::map<std::string, fptr> LCIO2Plcio::map_cvt; CollectionsMap LCIO2Plcio::map_cols; +std::string LCIO2Plcio::CollName; void lp_info(std::string s){ printf("[LCIO2Plcio]:\t\t%s.\n", &s[0]); } +template<typename T> +static plcio::FloatThree FloatThreeFROMConstPtr(const T* vpos){ + float tmp[3]; + for(unsigned i=0; i<3; i++){ + tmp[i] = vpos[i]; + } + return plcio::FloatThree(tmp); +} + +template<typename T> +static plcio::FloatThree FloatThreeFROMFloatVec(std::vector<T> vec){ + float tmp[3]; + for(unsigned i=0; i<3; i++){ + tmp[i] = vec[i]; + } + return plcio::FloatThree(tmp); +} + +std::array<float, 6> vec6_2_arr6(std::vector<float> vec){ + std::array<float, 6> arr; + for(unsigned i=0; i<6; i++){ + arr[i] = vec[i]; + } + return arr; +} + LCIO2Plcio::LCIO2Plcio(){ map_cvt.insert(std::make_pair<std::string, fptr>("MCParticle", Convertor_MCParticle)); map_cvt.insert(std::make_pair<std::string, fptr>("LCRunHeader", Convertor_LCRunHeader)); map_cvt.insert(std::make_pair<std::string, fptr>("SimTrackerHit", Convertor_SimTrackerHit)); map_cvt.insert(std::make_pair<std::string, fptr>("SimCalorimeterHit", Convertor_SimCalorimeterHit)); + map_cvt.insert(std::make_pair<std::string, fptr>("Cluster", Convertor_Cluster)); + map_cvt.insert(std::make_pair<std::string, fptr>("Track", Convertor_Track)); + map_cvt.insert(std::make_pair<std::string, fptr>("TPCHit", Convertor_TPCHit)); } LCIO2Plcio::LCIO2Plcio(EVENT::LCCollection* collection){ LCIO2Plcio(); @@ -30,70 +59,67 @@ LCIO2Plcio::LCIO2Plcio(EVENT::LCCollection* collection){ podio::CollectionBase* LCIO2Plcio::Convertor_LCRunHeader(EVENT::LCCollection* lc_col){ plcio::LCRunHeaderCollection* pl_col = new plcio::LCRunHeaderCollection(); -// plcio::LCRunHeader pl_rh = (plcio::LCRunHeader) pl_col->create(); + + // Convert basic info from LCIO to plcio; + for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ + EVENT::LCRunHeader* lc_var = (EVENT::LCRunHeader*) lc_col->getElementAt(i) ; + plcio::LCRunHeader pl_var = (plcio::LCRunHeader) pl_col->create(); + pl_var.setRunNumber( lc_var->getRunNumber() ); + pl_var.setDetectorName( lc_var->getDetectorName() ); + pl_var.setDescription( lc_var->getDescription() ); + + std::vector<std::string> vec_dct = *(lc_var->getActiveSubdetectors()); + for( unsigned j=0,N=vec_dct.size(); j<N; j++){ + pl_var.addActiveSubdetector( vec_dct[j] ); + } + } return pl_col; } -void LCIO2Plcio::void_Core_MCParticle(EVENT::MCParticle* lc_mcp, plcio::MCParticle& pl_mcp){ - - pl_mcp.setPDG( lc_mcp->getPDG() ); - pl_mcp.setGeneratorStatus( lc_mcp->getGeneratorStatus() ); - pl_mcp.setSimulatorStatus( lc_mcp->getSimulatorStatus() ); - pl_mcp.setCharge( lc_mcp->getCharge() ); - pl_mcp.setTime( lc_mcp->getTime() ); - pl_mcp.setMass( lc_mcp->getMass() ); - pl_mcp.setStopped( lc_mcp->isStopped() ); - pl_mcp.setOverlay( lc_mcp->isOverlay() ); - pl_mcp.setBackscatter( lc_mcp->isBackscatter() ); - pl_mcp.setDecayedInTracker( lc_mcp->isDecayedInTracker() ); - pl_mcp.setDecayedInCalorimeter( lc_mcp->isDecayedInCalorimeter() ); - pl_mcp.setCreatedInSimulation( lc_mcp->isCreatedInSimulation() ); - pl_mcp.setVertexIsNotEndpointOfParent( lc_mcp->vertexIsNotEndpointOfParent() ); - pl_mcp.setHasLeftDetector( lc_mcp->hasLeftDetector() ); - - pl_mcp.setSpin( plcio::FloatThree( lc_mcp->getSpin() ) ); - pl_mcp.setColorFlow( plcio::IntTwo( lc_mcp->getColorFlow() ) ); - pl_mcp.setVertex( plcio::DoubleThree( lc_mcp->getVertex())); - pl_mcp.setEndpoint( plcio::DoubleThree( lc_mcp->getEndpoint() ) ); - - // send float ptr as parameter to FloatThree. - float plcio_m[3]; - const double* lcio_m = lc_mcp->getMomentum(); - plcio_m[0] = lcio_m[0]; - plcio_m[1] = lcio_m[1]; - plcio_m[2] = lcio_m[2]; - pl_mcp.setMomentum( plcio::FloatThree( plcio_m ) ); - - lcio_m = lc_mcp->getMomentumAtEndpoint(); - plcio_m[0] = lcio_m[0]; - plcio_m[1] = lcio_m[1]; - plcio_m[2] = lcio_m[2]; - pl_mcp.setMomentumAtEndpoint( plcio::FloatThree( plcio_m ) ); +void LCIO2Plcio::setMCParticle(EVENT::MCParticle* lc_var, plcio::MCParticle& pl_var){ + + pl_var.setPDG( lc_var->getPDG() ); + pl_var.setGeneratorStatus( lc_var->getGeneratorStatus() ); + pl_var.setSimulatorStatus( lc_var->getSimulatorStatus() ); + pl_var.setCharge( lc_var->getCharge() ); + pl_var.setTime( lc_var->getTime() ); + pl_var.setMass( lc_var->getMass() ); + pl_var.setStopped( lc_var->isStopped() ); + pl_var.setOverlay( lc_var->isOverlay() ); + pl_var.setBackscatter( lc_var->isBackscatter() ); + pl_var.setDecayedInTracker( lc_var->isDecayedInTracker() ); + pl_var.setDecayedInCalorimeter( lc_var->isDecayedInCalorimeter() ); + pl_var.setCreatedInSimulation( lc_var->isCreatedInSimulation() ); + pl_var.setVertexIsNotEndpointOfParent( lc_var->vertexIsNotEndpointOfParent() ); + pl_var.setHasLeftDetector( lc_var->hasLeftDetector() ); + + pl_var.setSpin( plcio::FloatThree( lc_var->getSpin() ) ); + pl_var.setColorFlow( plcio::IntTwo( lc_var->getColorFlow() ) ); + pl_var.setVertex( plcio::DoubleThree( lc_var->getVertex())); + pl_var.setEndpoint( plcio::DoubleThree( lc_var->getEndpoint() ) ); + pl_var.setMomentum( FloatThreeFROMConstPtr(lc_var->getMomentum()) ); + pl_var.setMomentumAtEndpoint( FloatThreeFROMConstPtr(lc_var->getMomentumAtEndpoint()) ); } podio::CollectionBase* LCIO2Plcio::Convertor_MCParticle(EVENT::LCCollection* lc_col){ - return Core_MCParticle(lc_col); -} - -plcio::MCParticleCollection* LCIO2Plcio::Core_MCParticle(EVENT::LCCollection* lc_col){ plcio::MCParticleCollection* pl_col = new plcio::MCParticleCollection(); // Convert basic info from LCIO to plcio; for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::MCParticle* lc_mcp = (EVENT::MCParticle*) lc_col->getElementAt(i) ; - plcio::MCParticle pl_mcp = (plcio::MCParticle) pl_col->create(); + EVENT::MCParticle* lc_var = (EVENT::MCParticle*) lc_col->getElementAt(i) ; + plcio::MCParticle pl_var = (plcio::MCParticle) pl_col->create(); - void_Core_MCParticle(lc_mcp, pl_mcp); + setMCParticle(lc_var, pl_var); // dealing each of 'Parents' of lcio::MCParticle ; - const MCParticleVec& veclc = lc_mcp->getParents(); + const MCParticleVec& veclc = lc_var->getParents(); for(unsigned j=0; j<veclc.size(); j++){ EVENT::MCParticle* vlcreg = veclc[j]; for(unsigned k=0; k<i; ++k){ if(((EVENT::MCParticle*) lc_col->getElementAt(k)) == vlcreg){ // A loop for plcio's MCParticleCollection to recover plcio's relationship; - plcio::MCParticle plprt = pl_col->at(k); - pl_mcp.addParent(plprt); - plprt.addDaughter(pl_mcp); + plcio::MCParticle mcprt = pl_col->at(k); + pl_var.addParent(mcprt); + mcprt.addDaughter(pl_var); } } } @@ -101,32 +127,23 @@ plcio::MCParticleCollection* LCIO2Plcio::Core_MCParticle(EVENT::LCCollection* lc return pl_col; } -//void LCIO2Plcio::setPlcioMCParticleCollection(plcio::MCParticleCollection* pl_col){ -// hitcol_pl = pl_col; -//} - -//void LCIO2Plcio::setLCIOMCParticleCollection(EVENT::LCCollection* lc_col){ -// hitcol_lc = lc_col; -//} - - podio::CollectionBase* LCIO2Plcio::Convertor_SimTrackerHit(EVENT::LCCollection* lc_col){ plcio::SimTrackerHitCollection* pl_col = new plcio::SimTrackerHitCollection(); for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::SimTrackerHit* lc_sth = (EVENT::SimTrackerHit*) lc_col->getElementAt(i) ; - plcio::SimTrackerHit pl_sth = (plcio::SimTrackerHit) pl_col->create(); - - pl_sth.setCellID0( lc_sth->getCellID0() ); - pl_sth.setCellID1( lc_sth->getCellID1() ); - pl_sth.setEDep( lc_sth->getEDep() ); - pl_sth.setTime( lc_sth->getTime() ); - pl_sth.setPathLength( lc_sth->getPathLength() ); - pl_sth.setQuality( lc_sth->getQuality() ); - pl_sth.setPosition( lc_sth->getPosition() ); - pl_sth.setMomentum( lc_sth->getMomentum() ); - pl_sth.setOverlay( lc_sth->isOverlay() ); - pl_sth.setProducedBySecondary( lc_sth->isProducedBySecondary() ); + EVENT::SimTrackerHit* lc_var = (EVENT::SimTrackerHit*) lc_col->getElementAt(i) ; + plcio::SimTrackerHit pl_var = (plcio::SimTrackerHit) pl_col->create(); + + pl_var.setCellID0( lc_var->getCellID0() ); + pl_var.setCellID1( lc_var->getCellID1() ); + pl_var.setEDep( lc_var->getEDep() ); + pl_var.setTime( lc_var->getTime() ); + pl_var.setPathLength( lc_var->getPathLength() ); + pl_var.setQuality( lc_var->getQuality() ); + pl_var.setPosition( lc_var->getPosition() ); + pl_var.setMomentum( lc_var->getMomentum() ); + pl_var.setOverlay( lc_var->isOverlay() ); + pl_var.setProducedBySecondary( lc_var->isProducedBySecondary() ); // Looping the LCIO::MCParticleCollection to pick Particle for Hits; CollectionsVec vec_mcp; @@ -136,7 +153,7 @@ podio::CollectionBase* LCIO2Plcio::Convertor_SimTrackerHit(EVENT::LCCollection* int index = -1; // search corresponding MCParticleCollection*; - EVENT::MCParticle* mcptr_reg = lc_sth->getMCParticle(); + EVENT::MCParticle* mcptr_reg = lc_var->getMCParticle(); for( unsigned j=0, M=hitcol_lc->getNumberOfElements(); j<M; ++j){ EVENT::MCParticle* mcpin_lc = (EVENT::MCParticle*) hitcol_lc->getElementAt(j); if( mcpin_lc == mcptr_reg ){ @@ -153,7 +170,7 @@ podio::CollectionBase* LCIO2Plcio::Convertor_SimTrackerHit(EVENT::LCCollection* // printf("Index: %d\n", index); } if( is_empty == false ) - pl_sth.setMCParticle( hitcol_pl->at(index) ); + pl_var.setMCParticle( hitcol_pl->at(index) ); } return pl_col; @@ -163,34 +180,316 @@ podio::CollectionBase* LCIO2Plcio::Convertor_SimCalorimeterHit(EVENT::LCCollecti plcio::SimCalorimeterHitCollection* pl_col = new plcio::SimCalorimeterHitCollection(); for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ - EVENT::SimCalorimeterHit* lc_sch = (EVENT::SimCalorimeterHit*) lc_col->getElementAt(i); - plcio::SimCalorimeterHit pl_sch = (plcio::SimCalorimeterHit) pl_col->create(); - - pl_sch.setCellID0( lc_sch->getCellID0() ); - pl_sch.setCellID1( lc_sch->getCellID1() ); - pl_sch.setEnergy( lc_sch->getEnergy() ); - - float plcio_p[3]; - const float* lcio_p = lc_sch->getPosition(); - plcio_p[0] = lcio_p[0]; - plcio_p[1] = lcio_p[1]; - plcio_p[2] = lcio_p[2]; - pl_sch.setPosition( plcio::FloatThree( plcio_p ) ); - - // converting from lc_sch to pl_sch on the contribution variables; - for( unsigned j=0, N=lc_sch->getNMCContributions(); j<N; j++){ - plcio_p[0] = lc_sch->getStepPosition(j)[0]; - plcio_p[1] = lc_sch->getStepPosition(j)[1]; - plcio_p[2] = lc_sch->getStepPosition(j)[2]; + EVENT::SimCalorimeterHit* lc_var = (EVENT::SimCalorimeterHit*) lc_col->getElementAt(i); + plcio::SimCalorimeterHit pl_var = (plcio::SimCalorimeterHit) pl_col->create(); + + pl_var.setCellID0( lc_var->getCellID0() ); + pl_var.setCellID1( lc_var->getCellID1() ); + pl_var.setEnergy( lc_var->getEnergy() ); + pl_var.setPosition( FloatThreeFROMConstPtr(lc_var->getPosition()) ); + // converting from lc_var to pl_var on the contribution variables; + for( unsigned j=0, N=lc_var->getNMCContributions(); j<N; j++){ plcio::ConstCaloHitContribution tmp( - lc_sch->getPDGCont(j), lc_sch->getEnergyCont(j), - lc_sch->getTimeCont(j), plcio::FloatThree(plcio_p) + lc_var->getPDGCont(j), lc_var->getEnergyCont(j), + lc_var->getTimeCont(j), FloatThreeFROMConstPtr(lc_var->getStepPosition(j)) ); - pl_sch.addContribution( tmp ); + pl_var.addContribution( tmp ); + } + } + return pl_col; +} + +podio::CollectionBase* LCIO2Plcio::Convertor_Cluster(EVENT::LCCollection* lc_col){ + plcio::ClusterCollection* pl_col = new plcio::ClusterCollection(); + + for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ + EVENT::Cluster* lc_var = (EVENT::Cluster*) lc_col->getElementAt(i); + plcio::Cluster pl_var = (plcio::Cluster) pl_col->create(); + + pl_var.setType(lc_var->getType()); + pl_var.setEnergy(lc_var->getEnergy()); + pl_var.setEnergyError(lc_var->getEnergyError()); + pl_var.setPhi(lc_var->getIPhi()); + pl_var.setITheta(lc_var->getITheta()); + pl_var.setPosition( FloatThreeFROMConstPtr(lc_var->getPosition()) ); + pl_var.setPositionError( vec6_2_arr6(lc_var->getPositionError()) ); + pl_var.setDirectionError( FloatThreeFROMFloatVec(lc_var->getDirectionError()) ); + + std::vector<float> lcio_seq0 = lc_var->getShape(); + for(unsigned j=0; j<lcio_seq0.size(); j++){ + pl_var.addShap( lcio_seq0[j] ); + } + + lcio_seq0 = lc_var->getHitContributions(); + for(unsigned j=0; j<lcio_seq0.size(); j++){ + pl_var.addHitContribution( lcio_seq0[j] ); + } + + lcio_seq0 = lc_var->getSubdetectorEnergies(); + for(unsigned j=0; j<lcio_seq0.size(); j++){ + pl_var.addSubdetectorEnergie( lcio_seq0[j] ); + } + + EVENT::ParticleIDVec lcio_seq1 = lc_var->getParticleIDs(); + for(unsigned j=0; j<lcio_seq1.size(); j++){ + EVENT::ParticleID* lc_locx = lcio_seq1[j]; + + pl_var.addParticleID( plcio::ConstParticleID( + lc_locx->getType(), + lc_locx->getPDG(), + lc_locx->getAlgorithmType(), + lc_locx->getLikelihood() + ) ); + } + + EVENT::CalorimeterHitVec lcio_seq2 = lc_var->getCalorimeterHits(); + for(unsigned j=0; j<lcio_seq2.size(); j++){ + EVENT::CalorimeterHit* lc_locx = lcio_seq2[j]; + + podio::CollectionIDTable col2id; + plcio::ObjectID tmp; + tmp.index = i; + tmp.collectionID = col2id.collectionID(CollName); + + pl_var.addHit( plcio::ConstCalorimeterHit( + lc_locx->getCellID0(), + lc_locx->getCellID1(), + lc_locx->getEnergy(), + lc_locx->getEnergyError(), + lc_locx->getTime(), + FloatThreeFROMConstPtr(lc_locx->getPosition()), + lc_locx->getType(), + tmp + ) ); + } + } + + for(unsigned i=0,N=lc_col->getNumberOfElements(); i<N; i++){ + EVENT::Cluster* lc_var = (EVENT::Cluster*) lc_col->getElementAt(i); + plcio::Cluster pl_var = pl_col->at(i); + EVENT::ClusterVec lcio_seq3 = lc_var->getClusters(); + + for(unsigned j=0; j<lcio_seq3.size(); j++){ + for(unsigned k=0,K=lc_col->getNumberOfElements(); k<K; k++){ + if(lcio_seq3[j] == lc_col->getElementAt(k)){ + pl_var.addCluster(pl_col->at(k)); + } + } + } + } + + return pl_col; +} + +podio::CollectionBase* LCIO2Plcio::Convertor_ReconstructedParticle(EVENT::LCCollection* lc_col){ + plcio::ReconstructedParticleCollection* pl_col = new plcio::ReconstructedParticleCollection(); + + for(unsigned i=0,N=lc_col->getNumberOfElements(); i<N; i++){ + EVENT::ReconstructedParticle* lc_var = (EVENT::ReconstructedParticle*) lc_col->getElementAt(i); + plcio::ReconstructedParticle pl_var = (plcio::ReconstructedParticle) pl_col->create(); + + pl_var.setType( lc_var->getType() ); + pl_var.setEnergy( lc_var->getEnergy() ); + pl_var.setCharge( lc_var->getCharge() ); + pl_var.setMass( lc_var->getMass() ); + pl_var.setGoodnessOfPID( lc_var->getGoodnessOfPID() ); + + pl_var.setMomentum( FloatThreeFROMConstPtr(lc_var->getMomentum()) ); + pl_var.setReferencePoint( FloatThreeFROMConstPtr(lc_var->getReferencePoint()) ); + + std::vector<float> vec = lc_var->getCovMatrix(); + for(unsigned j=0,N=vec.size(); j<N; j++){ + pl_var.setCovMatrix( j, vec[j] ); + } + + // QUEST: boolean to int: isPrimary, str2int: getAlgorithmType; + // pl_var.setStartVertex( lc_var->getStartVertex() ) + std::array<float, 6> arr_6; + EVENT::FloatVec fvec = lc_var->getStartVertex()->getCovMatrix(); + for(unsigned j=0; j<6; j++){ + arr_6[j] = fvec[j]; + } + pl_var.setStartVertex( plcio::ConstVertex( + lc_var->getStartVertex()->isPrimary(), + lc_var->getStartVertex()->getChi2(), + lc_var->getStartVertex()->getProbability(), + FloatThreeFROMConstPtr( lc_var->getStartVertex()->getPosition() ), + arr_6, + 0 + //lc_var->getStartVertex()->getAlgorithmType() + ) ); + + // QUEST: LCIO/ParticleID has a int algType; + //pl_var.setParticleIDUsed( lc_var->igetParticleIDUsed() ); + pl_var.setParticleIDUsed( plcio::ConstParticleID( + lc_var->getParticleIDUsed()->getType(), + lc_var->getParticleIDUsed()->getPDG(), + lc_var->getParticleIDUsed()->getAlgorithmType(), + lc_var->getParticleIDUsed()->getLikelihood() + ) ); + + //pl_var.addCluster(); + // QUEST: set value directly; + + std::vector<EVENT::Cluster*> vec_clust = lc_var->getClusters(); + for(unsigned j=0; j<vec_clust.size(); j++){ + for(unsigned k=0; k<6; k++){ + arr_6[k] = vec_clust[j]->getPositionError()[k]; + } + + pl_var.addCluster( plcio::ConstCluster( + vec_clust[j]->getType(), + vec_clust[j]->getEnergy(), + vec_clust[j]->getEnergyError(), + FloatThreeFROMConstPtr( vec_clust[j]->getPosition() ), + arr_6, + vec_clust[j]->getITheta(), + vec_clust[j]->getIPhi(), + FloatThreeFROMFloatVec( vec_clust[j]->getDirectionError() ) + ) ); } + + //pl_var.addTrack(); + // QUEST: set value directly; + EVENT::TrackVec vec_track = lc_var->getTracks(); + for(unsigned j=0; j<vec_track.size(); j++){ + pl_var.addTrack(plcio::ConstTrack( + // plcio/include/plcio/TrackConst.h + // LCIO/include/EVENT/Track.h + )); + } + + //pl_var.addParticle(); + //pl_var.addParticleID(); } + return pl_col; +} + +podio::CollectionBase* LCIO2Plcio::Convertor_Track(EVENT::LCCollection* lc_col){ + plcio::TrackCollection* pl_col = new plcio::TrackCollection(); + + for(unsigned i=0,N=lc_col->getNumberOfElements(); i<N; i++){ + EVENT::Track* lc_var = (EVENT::Track*) lc_col->getElementAt(i); + plcio::Track pl_var = (plcio::Track) pl_col->create(); + + pl_var.setType( lc_var->getType() ); + pl_var.setChi2( lc_var->getChi2() ); + pl_var.setNdf( lc_var->getNdf() ); + pl_var.setDEdx( lc_var->getdEdx() ); + pl_var.setDEdxError( lc_var->getdEdxError() ); + pl_var.setRadiusOfInnermostHit( lc_var->getRadiusOfInnermostHit() ); + + //pl_var.addTrackerHit( lc_var->getTrackerHits() ); + EVENT::TrackerHitVec lcio_seq1 = lc_var->getTrackerHits(); + for(unsigned j=0; j<lcio_seq1.size(); j++){ + EVENT::TrackerHit* lc_locx = lcio_seq1[j]; + + const double* lcio_v = lc_locx->getPosition(); + double plcio_v[3]; + plcio_v[0] = lcio_v[0]; + plcio_v[1] = lcio_v[1]; + plcio_v[2] = lcio_v[2]; + + std::array<float, 6> plcio_arr6; + for(unsigned k=0; k<6; k++){ + plcio_arr6[k] = lc_locx->getCovMatrix()[k]; + } + + pl_var.addTrackerHit(plcio::ConstTrackerHit( + lc_locx->getCellID0(), + lc_locx->getCellID1(), + lc_locx->getType(), + lc_locx->getQuality(), + lc_locx->getTime(), + lc_locx->getEDep(), + lc_locx->getEDepError(), + lc_locx->getdEdx(), + plcio::DoubleThree(plcio_v), + plcio_arr6 + )); + } + + //pl_var.( lc_var->getSubdetectorHitNumbers() ); + std::vector<int> lcio_IntVec1 = lc_var->getSubdetectorHitNumbers(); + for(unsigned j=0; j<lcio_IntVec1.size(); j++){ + pl_var.addSubDetectorHitNumber(lcio_IntVec1[j]); + } + //pl_var.( lc_var->getTracks() ); + EVENT::TrackVec lcio_seq2 = lc_var->getTracks(); + for(unsigned j=0; j<lcio_seq2.size(); j++){ + EVENT::Track* lc_locx = lcio_seq2[j]; + + pl_var.addTrack(plcio::ConstTrack( + lc_locx->getType(), + lc_locx->getChi2(), + lc_locx->getNdf(), + lc_locx->getdEdx(), + lc_locx->getdEdxError(), + lc_locx->getRadiusOfInnermostHit() + )); + } + + //pl_var.( lc_var->getTrackStates() ); + EVENT::TrackStateVec lcio_seq3 = lc_var->getTrackStates(); + for(unsigned j=0; j<lcio_seq3.size(); j++){ + EVENT::TrackState* lc_locx = lcio_seq3[j]; + + //pl_var.addTrackState(plcio::TrackState()); + } + } + return pl_col; +} + +podio::CollectionBase* LCIO2Plcio::Convertor_Vertex(EVENT::LCCollection* lc_col){ + plcio::VertexCollection* pl_col = new plcio::VertexCollection(); + + for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ + EVENT::Vertex* lc_var = (EVENT::Vertex*) lc_col->getElementAt(i); + plcio::Vertex pl_var = (plcio::Vertex) pl_col->create(); + + // Quest: data.primary is an int value, set by boolean number; + pl_var.setPrimary( lc_var->isPrimary() ); + pl_var.setChi2( lc_var->getChi2() ); + pl_var.setProbability( lc_var->getProbability() ); + + float plcio_v[3]; + const float* lcio_v = lc_var->getPosition(); + plcio_v[0] = lcio_v[0]; + plcio_v[1] = lcio_v[1]; + plcio_v[2] = lcio_v[2]; + pl_var.setPosition( plcio::FloatThree(plcio_v) ); + + std::vector<float> vec_pra = lc_var->getParameters(); + for( unsigned j=0,M=vec_pra.size(); j<M; j++){ + pl_var.addParameter(vec_pra[j]); + } + + // convert string into int(type code); +// pl_var.setAlgorithmType( lc_var->getAlgorithmType() ); +// pl_var.setCovMatrix( lc_var->() ); +// pl_var.setAssociatedParticle( lc_var->() ); + } + return pl_col; +} + +podio::CollectionBase* LCIO2Plcio::Convertor_TPCHit(EVENT::LCCollection* lc_col){ + plcio::TPCHitCollection* pl_col = new plcio::TPCHitCollection(); + + for( unsigned i=0,N=lc_col->getNumberOfElements() ; i< N ; ++i){ + EVENT::TPCHit* lc_var = (EVENT::TPCHit*) lc_col->getElementAt(i); + plcio::TPCHit pl_var = (plcio::TPCHit) pl_col->create(); + + pl_var.setCellID(lc_var->getCellID()); + pl_var.setTime(lc_var->getTime()); + pl_var.setCharge(lc_var->getCharge()); + pl_var.setQuality(lc_var->getQuality()); + + for( unsigned j=0,M=lc_var->getNRawDataWords(); j<M; j++){ + pl_var.addRawDataWord(lc_var->getRawDataWord(j)); + } + } return pl_col; } diff --git a/FWCore/src/components/LCIO2Plcio.h b/FWCore/src/components/LCIO2Plcio.h index 799f864ecadd85f810cd839f178411e46dd33b45..a49ab30e97866255b2a666aaf572171cbbf42e13 100644 --- a/FWCore/src/components/LCIO2Plcio.h +++ b/FWCore/src/components/LCIO2Plcio.h @@ -9,15 +9,35 @@ #include "lcio.h" // #include "IO/LCReader.h" // #include "EVENT/LCCollection.h" -#include "EVENT/MCParticle.h" +#include "EVENT/Vertex.h" #include "EVENT/SimTrackerHit.h" -#include "EVENT/SimCalorimeterHit.h" #include "plcio/SimTrackerHit.h" #include "plcio/SimTrackerHitCollection.h" +#include "EVENT/SimCalorimeterHit.h" #include "plcio/SimCalorimeterHit.h" #include "plcio/SimCalorimeterHitCollection.h" +#include "EVENT/MCParticle.h" #include "plcio/MCParticle.h" #include "plcio/MCParticleCollection.h" +#include "plcio/VertexCollection.h" +#include "EVENT/TPCHit.h" +#include "plcio/TPCHit.h" +#include "plcio/TPCHitCollection.h" +#include "EVENT/Cluster.h" +#include "plcio/Cluster.h" +#include "plcio/ClusterCollection.h" +#include "EVENT/ParticleID.h" +#include "EVENT/CalorimeterHit.h" +#include "plcio/CalorimeterHit.h" +#include "podio/CollectionIDTable.h" +#include "EVENT/Track.h" +#include "EVENT/TrackerHit.h" +#include "EVENT/TrackState.h" +#include "plcio/Track.h" +#include "plcio/TrackCollection.h" +#include "EVENT/ReconstructedParticle.h" +#include "plcio/ReconstructedParticle.h" +#include "plcio/ReconstructedParticleCollection.h" #include <utility> // Forward declarations @@ -53,16 +73,21 @@ public: static podio::CollectionBase* Convertor_LCRunHeader(EVENT::LCCollection*); static podio::CollectionBase* Convertor_SimTrackerHit(EVENT::LCCollection*); static podio::CollectionBase* Convertor_SimCalorimeterHit(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_Cluster(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_Track(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_ReconstructedParticle(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_LCRelation(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_Vertex(EVENT::LCCollection*); + static podio::CollectionBase* Convertor_TPCHit(EVENT::LCCollection*); - static void void_Core_MCParticle(EVENT::MCParticle*, plcio::MCParticle&); - static plcio::MCParticleCollection* Core_MCParticle(EVENT::LCCollection*); + static void setMCParticle(EVENT::MCParticle*, plcio::MCParticle&); + void setCollName(const std::string &collName){ CollName = collName; }; bool isReady(const std::string&); - void setPlcioMCParticleCollection(plcio::MCParticleCollection*); - void setLCIOMCParticleCollection(EVENT::LCCollection*); private: std::string TypeName; + static std::string CollName; // maintain a log vec about data read; std::vector<std::string> vec_Types; diff --git a/FWCore/src/components/LCIODataSvc.cpp b/FWCore/src/components/LCIODataSvc.cpp index f31e13615870afd7e2a815e732de0fc21809f341..3656f3ffc0770552333da606856a02209242921f 100644 --- a/FWCore/src/components/LCIODataSvc.cpp +++ b/FWCore/src/components/LCIODataSvc.cpp @@ -27,6 +27,14 @@ StatusCode LCIODataSvc::initialize() { m_cnvSvc = svc_loc->service("EventPersistencySvc"); status = setDataLoader(m_cnvSvc); + if ( name() != "EventDataSvc" ) { + service("EventDataSvc", m_pIDP, true); + if ( m_pIDP == nullptr ) { + error() << "Could not get the EventDataSvc instance" << endmsg; + return StatusCode::FAILURE; + } + } + m_reader = IOIMPL::LCFactory::getInstance()->createLCReader(); if (m_filename != "") { @@ -34,11 +42,10 @@ StatusCode LCIODataSvc::initialize() { } if (m_filenames.size() > 0) { - if (m_filenames[0] != "") { - m_reader->open(m_filenames); - m_eventMax = m_reader->getNumberOfEvents(); - } + m_reader->open(m_filenames[0]); + m_eventMax = m_reader->getNumberOfEvents(); } + return status; } /// Service reinitialisation @@ -48,6 +55,9 @@ StatusCode LCIODataSvc::reinitialize() { } /// Service finalization StatusCode LCIODataSvc::finalize() { + m_reader->close(); + delete m_reader; + m_reader = nullptr; m_cnvSvc = 0; // release DataSvc::finalize().ignore(); return StatusCode::SUCCESS; @@ -75,10 +85,17 @@ void LCIODataSvc::endOfRead() { // m_provider.clearCaches(); // m_reader.endOfEvent(); if ( ++m_eventNum >= m_eventMax ) { - info() << "Reached end of file with event " << m_eventMax << endmsg; - IEventProcessor* eventProcessor; - service("ApplicationMgr", eventProcessor); - eventProcessor->stopRun(); + if ( ++m_fileIndex < m_filenames.size() ) { // move to next file + m_reader->close(); + m_reader->open( m_filenames[m_fileIndex] ); + m_eventMax += m_reader->getNumberOfEvents(); + } + else { // reach to the end of the file list + info() << "Reached end of file with event " << m_eventMax << endmsg; + IEventProcessor* eventProcessor; + service("ApplicationMgr", eventProcessor); + eventProcessor->stopRun(); + } } } evt = nullptr; @@ -106,6 +123,8 @@ LCIODataSvc::~LCIODataSvc() {} StatusCode LCIODataSvc::readCollection(const std::string& collName, int collectionID) { + + StatusCode stat = StatusCode::SUCCESS; podio::CollectionBase* collection(nullptr); if( evt == nullptr ){ @@ -126,9 +145,14 @@ StatusCode LCIODataSvc::readCollection(const std::string& collName, int collecti int id = m_collectionIDs->add("EventHeader"); pl_evtcol->setID(id); wrapper->setData(pl_evtcol); - m_readCollections.emplace_back(std::make_pair("EventHeader", pl_evtcol)); - DataSvc::registerObject("EventHeader", wrapper); + if ( m_pIDP ) { + m_pIDP->registerObject("EventHeader", wrapper); + } + else { + m_readCollections.emplace_back(std::make_pair("EventHeader", pl_evtcol)); + DataSvc::registerObject("EventHeader", wrapper); + } } debug() << "reading collection name: " << collName << "." << endmsg; @@ -138,7 +162,8 @@ StatusCode LCIODataSvc::readCollection(const std::string& collName, int collecti if( it != vec_colns.end() ){ lc_col = evt->getCollection(collName); } - else return StatusCode::SUCCESS; + else + return stat; // debug() << "Got collection: " << collName << "." << endmsg; std::string TypeName = lc_col->getTypeName(); @@ -149,6 +174,7 @@ StatusCode LCIODataSvc::readCollection(const std::string& collName, int collecti // LCIO2Plcio::setLCIOMCParticleCollection(mcpcol_lc); // LCIO2Plcio::setPlcioMCParticleCollection(mcpcol_pl); // } + cvtor.setCollName(collName); collection = cvtor.Convertor_getPlcio( lc_col ); pl_evtcol->at(0)->addCollectionName(collName); pl_evtcol->at(0)->addCollectionType(TypeName); @@ -157,11 +183,17 @@ StatusCode LCIODataSvc::readCollection(const std::string& collName, int collecti int id = m_collectionIDs->add(collName); collection->setID(id); wrapper->setData(collection); - m_readCollections.emplace_back(std::make_pair(collName, collection)); // info() << "readCollection completed." << endmsg; - return DataSvc::registerObject(collName, wrapper); + if ( m_pIDP ) { + stat = m_pIDP->registerObject(collName, wrapper); + } + else { + m_readCollections.emplace_back(std::make_pair(collName, collection)); + stat = DataSvc::registerObject(collName, wrapper); + } + return stat; } StatusCode LCIODataSvc::registerObject(const std::string& fullPath, DataObject* pObject) { diff --git a/FWCore/src/components/LCIOInput.cpp b/FWCore/src/components/LCIOInput.cpp index c6a810708e26c94a8eb1677cb23b27f85e9620ce..dab645881d2f0afce2407416e5a581bb76ae7c0a 100644 --- a/FWCore/src/components/LCIOInput.cpp +++ b/FWCore/src/components/LCIOInput.cpp @@ -14,7 +14,8 @@ StatusCode LCIOInput::initialize() { if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE; // check whether we have the LCIOEvtSvc active - m_LCIODataSvc = dynamic_cast<LCIODataSvc*>(evtSvc().get()); + auto pSvc = service( m_dataSvc ); + m_LCIODataSvc = dynamic_cast<LCIODataSvc*>(pSvc.get()); if (nullptr == m_LCIODataSvc) return StatusCode::FAILURE; auto idTable = m_LCIODataSvc->getCollectionIDs(); diff --git a/FWCore/src/components/LCIOInput.h b/FWCore/src/components/LCIOInput.h index f84922797e085677dcbd2759f433006b5c53cc0e..1ede535f1bd62a54e565a20e9abf005d85825603 100644 --- a/FWCore/src/components/LCIOInput.h +++ b/FWCore/src/components/LCIOInput.h @@ -33,6 +33,7 @@ public: private: /// Name of collections to read. Set by option collections (this is temporary) + Gaudi::Property<std::string> m_dataSvc{ this, "DataSvc", "LCIOInputSvc" }; Gaudi::Property<std::vector<std::string>> m_collectionNames{this, "collections", {}, "Places of collections to read"}; /// Collection IDs (retrieved with CollectionIDTable from ROOT file, using collection names) std::vector<int> m_collectionIDs;