pick up behavior without slice after setting parameters
manually
#818
-
I'm working on a awkward-array integration with This is useful exercise for building up peharps a more complete event data model for ATLAS as well (@nikoladze @matthewfeickert @kratsg @gordonwatts @alexander-held @henryiii ) The raw arry (ignoring references/links that come layer is this (filtering for briefness) >>> events = ak.from_iter({
'particles': [
{k if k!= 'e' else 'E':getattr(p,k) for k in pylhe.LHEParticle.fieldnames if k in ['px','py','pz','e']} for p in e.particles
],
'eventinfo': {k:getattr(e.eventinfo,k) for k in pylhe.LHEEventInfo.fieldnames if k in ['nparticles','weight']}
}
for e in pylhe.readLHEWithAttributes(skhep_testdata.data_path('pylhe-testfile-pr29.lhe'))
)
>>> ak.type(events)
791 * {"particles": var * {"px": float64, "py": float64, "pz": float64, "E": float64}, "eventinfo": {"nparticles": float64, "weight": float64}} and layout >>> events.layout.contents[0].content.setparameter('__record__','Particle')
... events.layout.contents[1].setparameter('__record__','EventInfo')
... events.layout.setparameter('__record__','Event')
... ak.type(events)
791 * Event["particles": var * Particle["px": float64, "py": float64], "eventinfo": EventInfo["nparticles": float64]] I can now give names to the records via
registering the following dummy behaviors class Particle(ak.Record):
pass
class ParticleArray(ak.Array):
pass
class Event(ak.Record):
pass
class EventArray(ak.Array):
pass
class EventInfo(ak.Record):
pass
class EventInfoArray(ak.Array):
pass
ak.behavior['Particle'] = Particle
ak.behavior['*','Particle'] = ParticleArray
ak.behavior['Event'] = Event
ak.behavior['*','Event'] = EventArray
ak.behavior['EventInfo'] = EventInfo
ak.behavior['*','EventInfo'] = EventInfoArray I can get any slice into the array to instantiate >>> events[:].particles
<ParticleArray [[{px: -0.315, py: -0.63, ... E: 9.35}]] type='791 * var * Partic...'> >>> events[0]
<Event ... nparticles: 9, weight: 0.0751}} type='Event["particles": var * Partic...'> and the trivial slice gives me an >>> events[:]
<EventArray [{particles: [, ... weight: 1.29e-05}}] type='791 * Event["particles...'> ** but ** printing out >>> events
<Array [{particles: [, ... weight: 1.29e-05}}] type='791 * Event["particles": va...'> is there a way to "re-instantiate" the toplevel object so that it also becomes an |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
the solution seems to be to either do
|
Beta Was this translation helpful? Give feedback.
the solution seems to be to either do
ak.Array(events)
which should be zero-copy or toevents[:]
as above