diff --git a/Examples/options/LCIO_read.py b/Examples/options/LCIO_read.py index 07b4b0eef1c928fc27379f30de558d9dc2c240c8..8beafb9314a4fbf300b567ded81cecd3d8204715 100644 --- a/Examples/options/LCIO_read.py +++ b/Examples/options/LCIO_read.py @@ -2,9 +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") -dsvc = LCIODataSvc("EventDataSvc", input="/cefs/data/DstData/CEPC240/CEPC_v4/higgs/E240.Pe2e2h_X.e0.p0.whizard195/e2e2h_X.e0.p0.00001_001000_dst.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") @@ -15,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 180f7b8d250db0b579212960fa99f06ed4834d8f..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; diff --git a/FWCore/src/components/LCIODataSvc.cpp b/FWCore/src/components/LCIODataSvc.cpp index 4901b1cea2362900f45fe8c105a50a66a1ae68d0..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 != "") { @@ -115,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 ){ @@ -135,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; @@ -147,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(); @@ -167,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;