def extract_sn_cand(self, sncand, sncandrow): """ Extract sncand tree from file SNDAQ/ROOT querk: ROOT does not understand the SNDAQ ROOT files. The CINT dicts that are needed are not written into the file. SNDAQ creates normal ROOT trees, branches, leaves, but does not write the structure of these into the file. Hence ROOT will not understand them without the proper definitions. You have to tell ROOT what the structure is supposed and where in memory to address it. Thanks to Lutz for the inspiration. :param sncand: Pointer to supernova candidate object (sncand) in ROOT file :param snroutrow: Pointer to HDF5 row object that referes to a row in the table we are writing to """ # Allocating memory sncandstreaming = ROOT.streaming_t() sncandroutvar = ROOT.rout_t() sncandvar = ROOT.cand_t() # Setting pointers in to right memory locations sncand.SetMakeClass(1) set_branches(sncand, sncandstreaming, ["base_time", "gps_time_high", "gps_time_low"]) set_branches(sncand, sncandroutvar, ["NMAvBins", "NRebins", "Signal", "SignalError", "Chi2", "ActiveChannels", "RebinIndex", "NNewActOMs", "NewActOMs", "NNewInactOMs", "NewInactOMs"]) set_branches(sncand, sncandvar, ["NCandidate", "NChannels", "NEvent", "ChannelRate", "ChannelMean", "ChannelSigmaSquare", "ChannelWeighedDev"]) # General description for the loops: # Since we dont know the structure of the file, ROOT does not allow us to loop # through the records directly. We have to tell it which record to look at by # number. Not sure how this works internally, lets just say the desired result happens. for i in range(sncand.GetEntries()): # Getting data by index sncand.GetEntry(i) time = get_daq_time_as_long(sncandstreaming.gps_time_high, sncandstreaming.gps_time_low) sncandrow["gps_time"] = time # Correction to get the right bin size. Note from GK sncandrow["base_time"] = sncandroutvar.NRebins * 500 sncandrow["NMAvBins"] = sncandroutvar.NMAvBins sncandrow["NRebins"] = sncandroutvar.NRebins sncandrow["Signal"] = sncandroutvar.Signal sncandrow["SignalError"] = sncandroutvar.SignalError sncandrow["Chi2"] = sncandroutvar.Chi2 sncandrow["ActiveChannels"] = sncandroutvar.ActiveChannels sncandrow["RebinIndex"] = sncandroutvar.RebinIndex sncandrow["NCandidate"] = sncandvar.NCandidate sncandrow["NChannels"] = sncandvar.NChannels sncandrow["NEvent"] = sncandvar.NEvent # The detector has 5160 DOMs. The maximum size of the data array is therefore 5160 sncandrow["ChannelRate"] = np.array([sncandvar.ChannelRate[j] for j in range(5160)]) sncandrow["ChannelMean"] = np.array([sncandvar.ChannelMean[j] for j in range(5160)]) sncandrow["ChannelSigmaSquare"] = np.array([sncandvar.ChannelSigmaSquare[j] for j in range(5160)]) sncandrow["ChannelWeighedDev"] = np.array([sncandvar.ChannelWeighedDev[j] for j in range(5160)]) ########################################################## # Stuff that doesn't work at the moment # Prototype code # This attempts to get the number of new active DOMs # out of the file. The problem is again variable # length arrays. One can not save a variable length # array to an HDF5 file without some contortions. # We don't need the information right now, so ignore it. # We still need to tell ROOT that the data is there # else we will reading in the wrong data ########################################################## # sncandrow["NNewActOMs"] = sncandroutvar.NNewActOMs # newDOMs = np.array([sncandroutvar.NewActOMs[j] for j in range(sncandroutvar.NNewActOMs)]) # for j in range(len(newDOMs)): NewActOMs[j] = newDOMs[j] # sncandrow["NewActOMs"] = NewActOMs # sncandrow["NNewInactOMs"] = sncandroutvar.NNewInactOMs # removedDOMs = np.array([sncandroutvar.NewInactOMs[j] for j in range(sncandroutvar.NNewInactOMs)]) # for j in range(len(removedDOMs)): NewInactOMs[j] = removedDOMs[j] # sncandrow["NewInactOMs"] = NewInactOMs sncandrow.append()