def hddmParser(fileName, what=""): """HDDM file parser. Return a list of run/uid/sync.values in given file""" hddmFile = pyhddm_r.hddm_istream_proxy(fileName) #print "in hddmParser()..." #print "DEBUG: file name = " + fileName ## for now, take the uid from the file name uid = int(1) matchObj = re.match(r'dana_rest_\d\d\d\d\d_(\d\d\d\d\d\d\d).hddm', hddmFile.getFilename(), re.M | re.I) if matchObj: uid = int(matchObj.group(1)) #uid = int(0) ###### #print "in hddm_r_reader.py..." #print " filename = " + fileName #print " uid = " + str(uid) #start to read the rest of the file runList = [] uidList = [] syncList = [] while hddmFile.read(): run = hddmFile.getRunNumber() event = hddmFile.getEventNumber() #uid = 1 #uid = hddmFile.getUid() #print "DEBUG: read in " + str(run) + " " + str(event) #if not run: # break if run == 0 and event == 0: continue if ((event % 100000) == 0): print "processing event " + str(event) # form syncValue syncValue = (run, event, uid) syncList.append(syncValue) if len(runList) == 0 or (uid != uidList[-1] or run != runList[-1]): runList.append(run) uidList.append(uid) hddmFile.close() #print "DEBUG: RUNS = " + str(runList) if what == "run": return runList.sort() elif what == "uid": return uidList.sort() elif what == "syncValue": return syncList.sort() returnList = [runList, uidList, syncList] return returnList
def hddmParser(fileName,what=""): """HDDM file parser. Return a list of run/uid/sync.values in given file""" hddmFile = pyhddm_r.hddm_istream_proxy(fileName) #print "in hddmParser()..." #print "DEBUG: file name = " + fileName ## for now, take the uid from the file name uid = int(1) matchObj = re.match( r'dana_rest_\d\d\d\d\d_(\d\d\d\d\d\d\d).hddm', hddmFile.getFilename(), re.M|re.I) if matchObj: uid = int(matchObj.group(1)) #uid = int(0) ###### #print "in hddm_r_reader.py..." #print " filename = " + fileName #print " uid = " + str(uid) #start to read the rest of the file runList = [] uidList = [] syncList= [] while hddmFile.read(): run = hddmFile.getRunNumber() event = hddmFile.getEventNumber() #uid = 1 #uid = hddmFile.getUid() #print "DEBUG: read in " + str(run) + " " + str(event) #if not run: # break if run==0 and event==0: continue if( (event%100000) == 0): print "processing event " + str(event) # form syncValue syncValue = (run,event,uid) syncList.append(syncValue) if len(runList)==0 or (uid!=uidList[-1] or run!=runList[-1]): runList.append(run) uidList.append(uid) hddmFile.close() #print "DEBUG: RUNS = " + str(runList) if what=="run": return runList.sort() elif what=="uid": return uidList.sort() elif what=="syncValue": return syncList.sort() returnList = [runList,uidList,syncList] return returnList
def __init__(self,fileName): self.fileName = fileName self.hddmFile = pyhddm_r.hddm_istream_proxy(fileName) self.fileIndex = int(0) ## keeps track of which event we are at in the file self.uid = int(1) # if it's MC, the uid = file number, extract it from file name of form dana_rest_RRRRR_FFFFFFF.hddm # otherwise, assume uid = 1 (i.e. data) matchObj = re.match( r'dana_rest_\d\d\d\d\d_(\d\d\d\d\d\d\d).hddm', self.hddmFile.getFilename(), re.M|re.I) if matchObj: self.uid = int(matchObj.group(1))
def __init__(self, fileName): self.fileName = fileName self.hddmFile = pyhddm_r.hddm_istream_proxy(fileName) self.fileIndex = int( 0) ## keeps track of which event we are at in the file self.uid = int(1) # if it's MC, the uid = file number, extract it from file name of form dana_rest_RRRRR_FFFFFFF.hddm # otherwise, assume uid = 1 (i.e. data) matchObj = re.match(r'dana_rest_\d\d\d\d\d_(\d\d\d\d\d\d\d).hddm', self.hddmFile.getFilename(), re.M | re.I) if matchObj: self.uid = int(matchObj.group(1))
def build_key(iFile, oFile, oFileID): """Build a key file from a HDDM REST file""" # open the files hddmFile = pyhddm_r.hddm_istream_proxy(iFile) keyFile = open(oFile, 'wb') ## for now, take the uid from the file name uid = int(1) matchObj = re.match(r'dana_rest_\d\d\d\d\d_(\d\d\d\d\d\d\d).hddm', hddmFile.getFilename(), re.M | re.I) if matchObj: uid = int(matchObj.group(1)) # build key file header keyHeader = array.array('I') keyHeader.fromlist([2718281 * 256, oFileID]) keyHeaderOffsetToNRecords = len(keyHeader) * 4 keyHeader.fromlist([0]) keyHeader.tofile(keyFile) #now loop over all the records #recordsToSync = array.array('I') numRecord = int(0) outRecord = array.array('I') outRecord.fromlist([0, 0, 0, 0, 0, 0]) try: while hddmFile.read(): endReason = "" outRecord[0] = hddmFile.getRunNumber() outRecord[1] = hddmFile.getEventNumber() outRecord[2] = uid outRecord[3] = 1 ## stream id, hardcoded to 1 (CODA event) for now outRecord[4] = numRecord >> 32 outRecord[5] = numRecord & 0xffffffff outRecord.tofile(keyFile) numRecord = numRecord + 1 except EOFError: print endReason #break #pus out last record synchronization info #recordsToStore.tofile(keyFile) # save number of records in the header keyFile.seek(keyHeaderOffsetToNRecords) nSyncValues = array.array('I') nSyncValues.fromlist([numRecord]) nSyncValues.tofile(keyFile) keyFile.close()
def build_key(iFile, oFile, oFileID): """Build a key file from a HDDM REST file""" # open the files hddmFile = pyhddm_r.hddm_istream_proxy(iFile) keyFile = open(oFile,'wb') ## for now, take the uid from the file name uid = int(1) matchObj = re.match( r'dana_rest_\d\d\d\d\d_(\d\d\d\d\d\d\d).hddm', hddmFile.getFilename(), re.M|re.I) if matchObj: uid = int(matchObj.group(1)) # build key file header keyHeader = array.array('I') keyHeader.fromlist([2718281*256,oFileID]) keyHeaderOffsetToNRecords=len(keyHeader)*4 keyHeader.fromlist([0]) keyHeader.tofile(keyFile) #now loop over all the records #recordsToSync = array.array('I') numRecord = int(0) outRecord = array.array('I') outRecord.fromlist([0,0,0,0,0,0]) try: while hddmFile.read(): endReason = "" outRecord[0] = hddmFile.getRunNumber() outRecord[1] = hddmFile.getEventNumber() outRecord[2] = uid outRecord[3] = 1 ## stream id, hardcoded to 1 (CODA event) for now outRecord[4] = numRecord >> 32 outRecord[5] = numRecord & 0xffffffff outRecord.tofile(keyFile) numRecord = numRecord + 1 except EOFError: print endReason #break #pus out last record synchronization info #recordsToStore.tofile(keyFile) # save number of records in the header keyFile.seek(keyHeaderOffsetToNRecords) nSyncValues = array.array('I') nSyncValues.fromlist([numRecord]) nSyncValues.tofile(keyFile) keyFile.close()
def hddmRunParser(fileName, what=""): """HDDM run parser. Return run/uid list""" hddmFile = pyhddm_r.hddm_istream_proxy(fileName) ## for now, take the uid from the file name uid = int(1) matchObj = re.match(r'dana_rest_\d\d\d\d\d_(\d\d\d\d\d\d\d).hddm', hddmFile.getFilename(), re.M | re.I) if matchObj: uid = int(matchObj.group(1)) ###### #print "in hddm_r_reader.py..." #print " filename = " + fileName #print " uid = " + str(uid) #start to read the rest of the file runList = [] uidList = [] while hddmFile.read(): run = hddmFile.getRunNumber() #uid = 1 #uid = hddmFile.getUid() #if not run: # break # if not run in runList: # runList.append(run) # if not uid in uidList: # uidList.append(uid) if len(runList) == 0 or (uid != uidList[-1] or run != runList[-1]): runList.append(run) uidList.append(uid) hddmFile.close() runList.sort() uidList.sort() return [runList, uidList]
def hddmRunParser(fileName,what=""): """HDDM run parser. Return run/uid list""" hddmFile = pyhddm_r.hddm_istream_proxy(fileName) ## for now, take the uid from the file name uid = int(1) matchObj = re.match( r'dana_rest_\d\d\d\d\d_(\d\d\d\d\d\d\d).hddm', hddmFile.getFilename(), re.M|re.I) if matchObj: uid = int(matchObj.group(1)) ###### #print "in hddm_r_reader.py..." #print " filename = " + fileName #print " uid = " + str(uid) #start to read the rest of the file runList = [] uidList = [] while hddmFile.read(): run = hddmFile.getRunNumber() #uid = 1 #uid = hddmFile.getUid() #if not run: # break # if not run in runList: # runList.append(run) # if not uid in uidList: # uidList.append(uid) if len(runList)==0 or (uid!=uidList[-1] or run!=runList[-1]): runList.append(run) uidList.append(uid) hddmFile.close() runList.sort() uidList.sort() return [runList,uidList]