diff --git a/Examples/options/plcio_read.py b/Examples/options/plcio_read.py index 1ba37f81b99e83b4802b79b605f027cbcb2eab1e..3d639dca744a65976e928dbf537888c0db0039ae 100644 --- a/Examples/options/plcio_read.py +++ b/Examples/options/plcio_read.py @@ -7,9 +7,11 @@ dsvc = CEPCDataSvc("EventDataSvc", input="test.root") from Configurables import PlcioReadAlg alg = PlcioReadAlg("PlcioReadAlg") +alg.InputCol.Path = "MCParticleCol" from Configurables import PodioInput podioinput = PodioInput("PodioReader", collections=[ + "EventHeaderCol", "MCParticleCol" ]) diff --git a/Examples/options/plcio_write.py b/Examples/options/plcio_write.py index 49c02d77882edc85300a9d138ab1f44a7fc889f7..e2619218625bf9d1f7e4835e47ba1a22f5defac0 100644 --- a/Examples/options/plcio_write.py +++ b/Examples/options/plcio_write.py @@ -7,6 +7,7 @@ dsvc = CEPCDataSvc("EventDataSvc") from Configurables import PlcioWriteAlg alg = PlcioWriteAlg("PlcioWriteAlg") +alg.OutputCol.Path = "MCParticleCol" from Configurables import PodioOutput out = PodioOutput("out") diff --git a/Examples/src/PlcioTest/PlcioReadAlg.cpp b/Examples/src/PlcioTest/PlcioReadAlg.cpp index 224c7722d6fbf02a8a3931884d4320c6ccca9c16..5921731c34e09bae568c93124ec786b76fc109a3 100644 --- a/Examples/src/PlcioTest/PlcioReadAlg.cpp +++ b/Examples/src/PlcioTest/PlcioReadAlg.cpp @@ -1,4 +1,5 @@ #include "PlcioReadAlg.h" +#include "plcio/EventHeaderCollection.h" #include "plcio/MCParticleCollection.h" DECLARE_COMPONENT(PlcioReadAlg) @@ -6,7 +7,8 @@ DECLARE_COMPONENT(PlcioReadAlg) PlcioReadAlg::PlcioReadAlg(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) { - declareProperty("MCParticleCol", m_hdl, "MCParticle collection (input)"); + declareProperty("HeaderCol", m_headerCol); + declareProperty("InputCol", m_mcParCol, "MCParticle collection (input)"); } StatusCode PlcioReadAlg::initialize() @@ -18,16 +20,20 @@ StatusCode PlcioReadAlg::initialize() StatusCode PlcioReadAlg::execute() { debug() << "begin execute PlcioReadAlg" << endmsg; - auto mcCol = m_hdl.get(); + auto headers = m_headerCol.get(); + auto header = headers->at(0); + auto mcCol = m_mcParCol.get(); + + info() << "Run " << header.getRunNumber() << " Event " << header.getEventNumber() << " { "; for ( auto p : *mcCol ) { - debug() << p.getObjectID().index << " : ["; + info() << p.getObjectID().index << " : ["; for ( auto it = p.daughters_begin(), end = p.daughters_end(); it != end; ++it ) { - debug() << " " << it->getObjectID().index; + info() << " " << it->getObjectID().index; } - debug() << " ]; "; + info() << " ]; "; } - debug() << endmsg; + info() << "}" << endmsg; return StatusCode::SUCCESS; } diff --git a/Examples/src/PlcioTest/PlcioReadAlg.h b/Examples/src/PlcioTest/PlcioReadAlg.h index b4d58c29c77c3c8aa4c715f19275f3fd5c8e4736..5b9ec8152abd5d3808d9158cd3930bd9ad240a6f 100644 --- a/Examples/src/PlcioTest/PlcioReadAlg.h +++ b/Examples/src/PlcioTest/PlcioReadAlg.h @@ -5,6 +5,7 @@ #include "GaudiAlg/GaudiAlgorithm.h" namespace plcio { + class EventHeaderCollection; class MCParticleCollection; } @@ -22,7 +23,8 @@ class PlcioReadAlg : public GaudiAlgorithm private : - DataHandle<plcio::MCParticleCollection> m_hdl{"MCParticleCol", Gaudi::DataHandle::Reader, this}; + DataHandle<plcio::EventHeaderCollection> m_headerCol{"EventHeaderCol", Gaudi::DataHandle::Reader, this}; + DataHandle<plcio::MCParticleCollection> m_mcParCol{"MCParticleCol", Gaudi::DataHandle::Reader, this}; }; diff --git a/Examples/src/PlcioTest/PlcioWriteAlg.cpp b/Examples/src/PlcioTest/PlcioWriteAlg.cpp index 91b54a87fb36a9bd50915f943124f5a9b0fbfde7..cfba374f581e0c86c0cace7e0c68bb0bdee45cd4 100644 --- a/Examples/src/PlcioTest/PlcioWriteAlg.cpp +++ b/Examples/src/PlcioTest/PlcioWriteAlg.cpp @@ -1,4 +1,5 @@ #include "PlcioWriteAlg.h" +#include "plcio/EventHeaderCollection.h" #include "plcio/MCParticleCollection.h" DECLARE_COMPONENT(PlcioWriteAlg) @@ -6,7 +7,8 @@ DECLARE_COMPONENT(PlcioWriteAlg) PlcioWriteAlg::PlcioWriteAlg(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) { - declareProperty("MCParticleCol", m_hdl, "MCParticle collection (output)"); + declareProperty("HeaderCol", m_headerCol); + declareProperty("OutputCol", m_mcParCol, "MCParticle collection (output)"); } StatusCode PlcioWriteAlg::initialize() @@ -19,7 +21,17 @@ StatusCode PlcioWriteAlg::execute() { debug() << "begin execute PlcioWriteAlg" << endmsg; - auto mcCol = new plcio::MCParticleCollection; + static int evtNo = 0; + + auto headers = m_headerCol.createAndPut(); + auto header = headers->create(); + header->setRunNumber(-999); + header->setEventNumber(evtNo++); + header->setDetectorName("TEST"); + + //auto mcCol = new plcio::MCParticleCollection; + //m_mcParCol.put(mcCol); + auto mcCol = m_mcParCol.createAndPut(); auto p1 = mcCol->create(); auto p2 = mcCol->create(); @@ -32,8 +44,6 @@ StatusCode PlcioWriteAlg::execute() p2.addDaughter(d); } - m_hdl.put(mcCol); - return StatusCode::SUCCESS; } diff --git a/Examples/src/PlcioTest/PlcioWriteAlg.h b/Examples/src/PlcioTest/PlcioWriteAlg.h index 053e49c986242acefbfcac943239505e69e2ffac..4ecb770ca0a23705f63c7ca0df34b20ebf0b54d3 100644 --- a/Examples/src/PlcioTest/PlcioWriteAlg.h +++ b/Examples/src/PlcioTest/PlcioWriteAlg.h @@ -5,6 +5,7 @@ #include "GaudiAlg/GaudiAlgorithm.h" namespace plcio { + class EventHeaderCollection; class MCParticleCollection; } @@ -22,7 +23,8 @@ class PlcioWriteAlg : public GaudiAlgorithm private : - DataHandle<plcio::MCParticleCollection> m_hdl{"MCParticleCol", Gaudi::DataHandle::Writer, this}; + DataHandle<plcio::EventHeaderCollection> m_headerCol{"EventHeaderCol", Gaudi::DataHandle::Writer, this}; + DataHandle<plcio::MCParticleCollection> m_mcParCol{"MCParticleCol", Gaudi::DataHandle::Writer, this}; }; diff --git a/FWCore/src/components/PodioOutput.cpp b/FWCore/src/components/PodioOutput.cpp index 6c531ad6e95ff410ed408ba3482fcaf6aef38047..26e6e37f6c367ec2a494b01a5606c578678e5de3 100644 --- a/FWCore/src/components/PodioOutput.cpp +++ b/FWCore/src/components/PodioOutput.cpp @@ -39,6 +39,15 @@ void PodioOutput::resetBranches(const std::vector<std::pair<std::string, podio:: ++j; } } + // vector members + auto vminfo = collNamePair.second->vectorMembers(); + if ( vminfo != nullptr ) { + int j = 0; + for ( auto& c : (*vminfo) ) { + m_datatree->SetBranchAddress((collName+"_"+std::to_string(j)).c_str(), c.second); + ++j; + } + } } if (prepare) { collNamePair.second->prepareForWrite(); @@ -81,6 +90,17 @@ void PodioOutput::createBranches(const std::vector<std::pair<std::string, podio: ++j; } } + // vector members + auto vminfo = collNamePair.second->vectorMembers(); + if ( vminfo != nullptr ) { + int j = 0; + for ( auto& c : (*vminfo) ) { + std::string typeName = "vector<" + c.first + ">"; + void* add = c.second; + m_datatree->Branch((collName+"_"+std::to_string(j)).c_str(), typeName.c_str(), add); + ++j; + } + } } debug() << isOn << " Registering collection " << collClassName << " " << collName.c_str() << " containing type " << className << endmsg;