Skip to content
Snippets Groups Projects
Commit a33f372c authored by zoujh@ihep.ac.cn's avatar zoujh@ihep.ac.cn
Browse files

examples to read/write EventHeader

parent 2d8cfbbc
No related branches found
No related tags found
No related merge requests found
......@@ -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"
])
......
......@@ -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")
......
#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;
}
......
......@@ -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};
};
......
#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;
}
......
......@@ -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};
};
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment