PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
PythonEventStore.cc
Go to the documentation of this file.
2
3#include "podio/ROOTReader.h"
5
6#include <fstream>
7#include <iostream>
8#include <string>
9
10podio::PythonEventStore::PythonEventStore(const char* name) : m_reader(podio::createReader(name)), m_store() {
11 std::ifstream inputfile(name);
12 m_isZombie = inputfile.good() ? false : true;
13
14 if (m_reader) {
15 if (m_isZombie && dynamic_cast<podio::ROOTReader*>(m_reader.get())) {
16 // the file could be a remote file that we cannot access but root
17 // knows how to handle via the xrootd protocol.
18 // if that is the case we ignore m_isZombie.
19 if (!std::string("root:/").compare(0, 6, name, 6)) {
20 m_isZombie = false;
21 }
22 }
23 }
24
25 if (!m_isZombie) {
26 // at this point we have a combination of file and reader that should work
27 m_reader->openFile(name);
28 m_store.setReader(m_reader.get());
29 }
30}
31
33 const podio::CollectionBase* coll(nullptr);
34 m_store.get(name, coll);
35 return coll;
36}
37
39 m_store.clear();
40 m_reader->endOfEvent();
41}
42
44 m_store.clear();
45 m_reader->goToEvent(ievent);
46}
47
49 return m_reader->getEntries();
50}
51
52const std::vector<std::string>& podio::PythonEventStore::getCollectionNames() const {
53 return m_store.getCollectionIDTable()->names();
54}
void setReader(IReader *reader)
set the reader
Definition: EventStore.cc:149
PythonEventStore(const char *filename)
constructor from filename
void goToEvent(unsigned ievent)
go to a given event
unsigned getEntries() const
get number of entries in the tree
const podio::CollectionBase * get(const char *name)
access a collection.
const std::vector< std::string > & getCollectionNames() const
list available collections
void endOfEvent()
signify end of event
std::unique_ptr< podio::IReader > createReader(const std::string &filename)
Definition: IOHelpers.cc:10