CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Attributes
lhef::H5Handler Class Reference

#include <LH5Reader.h>

Public Member Functions

void counter (int, int)
 
std::vector< lheh5::ParticlegetEvent ()
 
std::pair< lheh5::EventHeader, std::vector< lheh5::Particle > > getEventProperties ()
 
lheh5::EventHeader getHeader ()
 
 H5Handler (const std::string &fileNameIn)
 
void readBlock ()
 
virtual ~H5Handler ()
 

Public Attributes

HighFive::Group _event
 
lheh5::Events _events1
 
lheh5::Events2 _events2
 
unsigned int long _eventsRead
 
HighFive::Group _index
 
HighFive::Group _init
 
HighFive::Group _particle
 
HighFive::Group _procInfo
 
std::unique_ptr< HighFive::File > h5file
 
bool indexStatus
 
int npLO
 
int npNLO
 

Private Attributes

int _blocksRead
 
int _eventsInBlock
 
unsigned int long _eventsTotal
 
int _formatType
 

Detailed Description

Definition at line 16 of file LH5Reader.h.

Constructor & Destructor Documentation

◆ H5Handler()

lhef::H5Handler::H5Handler ( const std::string &  fileNameIn)

Definition at line 70 of file LH5Reader.cc.

References _blocksRead, _eventsInBlock, _eventsRead, _eventsTotal, _formatType, _index, _procInfo, Exception, h5file, indexStatus, npLO, npNLO, and mps_update::status.

71  : h5file(new HighFive::File(fileNameIn)),
72  indexStatus(h5file->exist("/index")),
73  _index(h5file->getGroup(indexStatus ? "index" : "event")),
74  _particle(h5file->getGroup("particle")),
75  _event(h5file->getGroup("event")),
76  _init(h5file->getGroup("init")),
77  _procInfo(h5file->getGroup("procInfo")) {
78  hid_t dspace;
79  _formatType = 1;
80 
81  if (indexStatus) {
82  dspace = H5Dget_space(h5file->getDataSet("index/start").getId());
83  _formatType = 2;
84  } else {
85  _index = h5file->getGroup("event");
86  dspace = H5Dget_space(h5file->getDataSet("event/start").getId());
87  _formatType = 1;
88  }
89 
90  _eventsTotal = H5Sget_simple_extent_npoints(dspace);
91  _eventsRead = 0;
92  _eventsInBlock = 6400 / 4; // configurable parameter??
93  if (_eventsTotal % _eventsInBlock != 0)
94  throw cms::Exception("ReadError") << "block size does not match HDF5 file" << std::endl;
95  _blocksRead = 0;
96 
97  // Check if the file contains the npLO, npNLO information
98  bool status = h5file->exist("/procInfo/npLO");
99  if (status) {
100  HighFive::DataSet _npLO = _procInfo.getDataSet("npLO");
101  _npLO.read(npLO);
102  HighFive::DataSet _npNLO = _procInfo.getDataSet("npNLO");
103  _npNLO.read(npNLO);
104  } else {
105  npLO = 1;
106  npNLO = 0;
107  }
108  };
unsigned int long _eventsTotal
Definition: LH5Reader.h:34
HighFive::Group _particle
Definition: LH5Reader.h:24
int _eventsInBlock
Definition: LH5Reader.h:35
bool indexStatus
Definition: LH5Reader.h:23
HighFive::Group _init
Definition: LH5Reader.h:24
HighFive::Group _procInfo
Definition: LH5Reader.h:24
HighFive::Group _event
Definition: LH5Reader.h:24
HighFive::Group _index
Definition: LH5Reader.h:24
std::unique_ptr< HighFive::File > h5file
Definition: LH5Reader.h:22
unsigned int long _eventsRead
Definition: LH5Reader.h:26

◆ ~H5Handler()

virtual lhef::H5Handler::~H5Handler ( )
inlinevirtual

Definition at line 19 of file LH5Reader.h.

19 {}

Member Function Documentation

◆ counter()

void lhef::H5Handler::counter ( int  firstEventIn,
int  maxEventsIn 
)

Definition at line 110 of file LH5Reader.cc.

References _blocksRead, _eventsInBlock, _eventsRead, _eventsTotal, Exception, and createfilelist::int.

Referenced by counter.Counters::__getitem__().

110  {
111  if (maxEventsIn > 0 && firstEventIn > maxEventsIn)
112  throw cms::Exception("ConfigurationError") << "\" firstEvent > maxEvents \"" << std::endl;
113  // Reset maximum number of events to read
114  if (_blocksRead == 0 && maxEventsIn >= 0 && (unsigned long int)maxEventsIn < _eventsTotal)
115  _eventsTotal = (unsigned long int)maxEventsIn;
116  // If there are multiple files, assume you only want to jump through the first file
117  if (firstEventIn > 0 && _blocksRead > 0)
118  _eventsRead = firstEventIn - 1;
119  // Set blocks read to be in the correct place
121  }
unsigned int long _eventsTotal
Definition: LH5Reader.h:34
int _eventsInBlock
Definition: LH5Reader.h:35
unsigned int long _eventsRead
Definition: LH5Reader.h:26

◆ getEvent()

std::vector< lheh5::Particle > lhef::H5Handler::getEvent ( )

Definition at line 133 of file LH5Reader.cc.

References _blocksRead, _events1, _eventsInBlock, _eventsRead, _eventsTotal, lheh5::Events::mkEvent(), and readBlock().

133  {
134  std::vector<lheh5::Particle> _vE;
135  if (_eventsRead > _eventsTotal - 1)
136  return std::vector<lheh5::Particle>();
137  int checkEvents = (_blocksRead)*_eventsInBlock - 1;
139  _eventsRead++;
140  if (checkEvents >= 0 && _eventsRead > (unsigned long int)checkEvents)
141  readBlock();
142  return _vE;
143  }
unsigned int long _eventsTotal
Definition: LH5Reader.h:34
int _eventsInBlock
Definition: LH5Reader.h:35
unsigned int long _eventsRead
Definition: LH5Reader.h:26
void readBlock()
Definition: LH5Reader.cc:123
std::vector< Particle > mkEvent(size_t ievent) const
Definition: lheh5.cc:35
lheh5::Events _events1
Definition: LH5Reader.h:28

◆ getEventProperties()

std::pair< lheh5::EventHeader, std::vector< lheh5::Particle > > lhef::H5Handler::getEventProperties ( )

Definition at line 150 of file LH5Reader.cc.

References _blocksRead, _events1, _eventsInBlock, _eventsRead, _eventsTotal, lheh5::Events::mkEvent(), lheh5::Events::mkEventHeader(), lheh5::EventHeader::nparticles, and readBlock().

150  {
151  std::vector<lheh5::Particle> _vE;
153  _h.nparticles = -1;
154  if (_eventsRead > _eventsTotal - 1)
155  return std::make_pair(_h, _vE);
156  int checkEvents = (_blocksRead)*_eventsInBlock - 1;
159  _eventsRead++;
160  if (checkEvents >= 0 && _eventsRead > (unsigned long int)checkEvents)
161  readBlock();
162  return std::make_pair(_h, _vE);
163  }
unsigned int long _eventsTotal
Definition: LH5Reader.h:34
int _eventsInBlock
Definition: LH5Reader.h:35
EventHeader mkEventHeader(int ievent) const
Definition: lheh5.cc:51
unsigned int long _eventsRead
Definition: LH5Reader.h:26
void readBlock()
Definition: LH5Reader.cc:123
std::vector< Particle > mkEvent(size_t ievent) const
Definition: lheh5.cc:35
lheh5::Events _events1
Definition: LH5Reader.h:28

◆ getHeader()

lheh5::EventHeader lhef::H5Handler::getHeader ( )

Definition at line 145 of file LH5Reader.cc.

References _events1, _eventsRead, and lheh5::Events::mkEventHeader().

145  {
146  // fragile, must be called before getEvent
148  }
EventHeader mkEventHeader(int ievent) const
Definition: lheh5.cc:51
unsigned int long _eventsRead
Definition: LH5Reader.h:26
lheh5::Events _events1
Definition: LH5Reader.h:28

◆ readBlock()

void lhef::H5Handler::readBlock ( )

Definition at line 123 of file LH5Reader.cc.

References _blocksRead, _event, _events1, _eventsInBlock, _eventsTotal, _index, _particle, submitPVValidationJobs::nEvents, and lheh5::readEvents().

Referenced by getEvent(), and getEventProperties().

123  {
124  // Start counting at 0
125  size_t iStart = _blocksRead * _eventsInBlock;
126  size_t nEvents = _eventsInBlock;
127  if ((unsigned long int)(iStart + nEvents) > _eventsTotal)
128  return;
130  _blocksRead++;
131  }
unsigned int long _eventsTotal
Definition: LH5Reader.h:34
HighFive::Group _particle
Definition: LH5Reader.h:24
Events readEvents(HighFive::Group &g_index, HighFive::Group &g_particle, HighFive::Group &g_event, size_t first_event, size_t n_events)
Definition: lheh5.cc:68
int _eventsInBlock
Definition: LH5Reader.h:35
HighFive::Group _event
Definition: LH5Reader.h:24
HighFive::Group _index
Definition: LH5Reader.h:24
lheh5::Events _events1
Definition: LH5Reader.h:28

Member Data Documentation

◆ _blocksRead

int lhef::H5Handler::_blocksRead
private

Definition at line 37 of file LH5Reader.h.

Referenced by counter(), getEvent(), getEventProperties(), H5Handler(), and readBlock().

◆ _event

HighFive::Group lhef::H5Handler::_event

Definition at line 24 of file LH5Reader.h.

Referenced by readBlock().

◆ _events1

lheh5::Events lhef::H5Handler::_events1

Definition at line 28 of file LH5Reader.h.

Referenced by getEvent(), getEventProperties(), getHeader(), and readBlock().

◆ _events2

lheh5::Events2 lhef::H5Handler::_events2

Definition at line 27 of file LH5Reader.h.

◆ _eventsInBlock

int lhef::H5Handler::_eventsInBlock
private

Definition at line 35 of file LH5Reader.h.

Referenced by counter(), getEvent(), getEventProperties(), H5Handler(), and readBlock().

◆ _eventsRead

unsigned int long lhef::H5Handler::_eventsRead

Definition at line 26 of file LH5Reader.h.

Referenced by counter(), getEvent(), getEventProperties(), getHeader(), and H5Handler().

◆ _eventsTotal

unsigned int long lhef::H5Handler::_eventsTotal
private

Definition at line 34 of file LH5Reader.h.

Referenced by counter(), getEvent(), getEventProperties(), H5Handler(), and readBlock().

◆ _formatType

int lhef::H5Handler::_formatType
private

Definition at line 36 of file LH5Reader.h.

Referenced by H5Handler().

◆ _index

HighFive::Group lhef::H5Handler::_index

Definition at line 24 of file LH5Reader.h.

Referenced by ntupleDataFormat._Object::__getattr__(), python.cmstools.EventTree::__getitem__(), python.cmstools.EventTree::__iter__(), python.cmstools.EventBranch::__readData(), python.cmstools.EventTree::__setBranchIndicies(), ntupleDataFormat.TrackingParticle::_nMatchedSeeds(), ntupleDataFormat._SimHitMatchAdaptor::_nMatchedSimHits(), ntupleDataFormat._TrackingParticleMatchAdaptor::_nMatchedTrackingParticles(), ntupleDataFormat.TrackingParticle::_nMatchedTracks(), html.HtmlReport::addNote(), ntupleDataFormat.TrackingVertex::daughterTrackingParticles(), ntupleDataFormat.TrackingParticle::decayVertices(), ntupleDataFormat._DetIdStrAdaptor::detIdStr(), H5Handler(), ntupleDataFormat._Object::index(), python.cmstools.EventTree::index(), ntupleDataFormat.Seed::indexWithinAlgo(), ntupleDataFormat._Object::isValid(), ntupleDataFormat._DetIdStrAdaptor::layerStr(), ntupleDataFormat.InvalidHit::layerStr(), ntupleDataFormat.TrackingParticle::matchedSeedInfos(), ntupleDataFormat._SimHitMatchAdaptor::matchedSimHitInfos(), ntupleDataFormat.TrackingParticle::matchedTrackInfos(), ntupleDataFormat._TrackingParticleMatchAdaptor::matchedTrackingParticleInfos(), ntupleDataFormat.GluedHit::monoHit(), ntupleDataFormat.TrackingVertex::nDaughterTrackingParticles(), ntupleDataFormat.SimHit::nRecHits(), ntupleDataFormat._HitObject::nseeds(), ntupleDataFormat.GluedHit::nseeds(), ntupleDataFormat.TrackingVertex::nSourceTrackingParticles(), ntupleDataFormat._HitObject::ntracks(), ntupleDataFormat.Vertex::nTracks(), ntupleDataFormat.TrackingParticle::parentVertex(), readBlock(), ntupleDataFormat.SeedMatchInfo::seed(), ntupleDataFormat.Track::seed(), ntupleDataFormat._HitObject::seeds(), ntupleDataFormat.GluedHit::seeds(), python.cmstools.EventBranch::setIndex(), ntupleDataFormat.SimHitMatchInfo::simHit(), ntupleDataFormat.TrackingVertex::sourceTrackingParticles(), ntupleDataFormat.GluedHit::stereoHit(), ntupleDataFormat.Seed::track(), ntupleDataFormat.SimHit::trackingParticle(), ntupleDataFormat._HitObject::tracks(), ntupleDataFormat.Vertex::tracks(), ntupleDataFormat.Track::vertex(), and html.HtmlReport::write().

◆ _init

HighFive::Group lhef::H5Handler::_init

◆ _particle

HighFive::Group lhef::H5Handler::_particle

Definition at line 24 of file LH5Reader.h.

Referenced by readBlock().

◆ _procInfo

HighFive::Group lhef::H5Handler::_procInfo

Definition at line 24 of file LH5Reader.h.

Referenced by H5Handler().

◆ h5file

std::unique_ptr<HighFive::File> lhef::H5Handler::h5file

Definition at line 22 of file LH5Reader.h.

Referenced by H5Handler().

◆ indexStatus

bool lhef::H5Handler::indexStatus

Definition at line 23 of file LH5Reader.h.

Referenced by H5Handler().

◆ npLO

int lhef::H5Handler::npLO

Definition at line 25 of file LH5Reader.h.

Referenced by H5Handler().

◆ npNLO

int lhef::H5Handler::npNLO

Definition at line 25 of file LH5Reader.h.

Referenced by H5Handler().