#!/usr/bin/env python # # Ported to GlueX by Sean Dobbs (s-dobbs@northwestern.edu), 2014 # # Copyright 2004 Cornell University, Ithaca, NY 14853. All rights reserved. # # Author: Valentin Kuznetsov, 2004 # """Set of high-level functions to build key/location files regardless from input data format. All EventStore file types are determined by fileType method.""" import os,sys,string,array # import auxilary modules for key/location files import os_path_util, gen_util import hddm_r_dump, hddm_r_reader #import hddm_s_dump, hddm_s_reader import evio_dump, evio_reader #import hddm_reader ##, lhddm_dump #import build_key_from_hddm ##import build_hddm_location import build_key_from_hddm_r #, build_key_from_hddm_s import build_key_from_evio def fileParser(fileName,what=""): """A high-level method to parse data files in EventStore. Based on a file type it propagates a request to appropriate module.""" type = fileType(fileName) if type == "rest": content = hddm_r_reader.hddmParser(fileName,what) #elif type == "mc": # content = hddm_s_reader.hddmParser(fileName,what) elif type == "evio": content = evio_reader.evioParser(fileName,what) else: print "Format of the %s is not recognized (format=%s)"%(fileName,type) sys.exit(1) return content def runParser(fileName): """A high-level method to parse files in EventStore and return run content.""" type = fileType(fileName) if type == "rest": content = hddm_r_reader.hddmRunParser(fileName) #elif type == "mc": # content = hddm_s_reader.hddmRunParser(fileName) elif type == "evio": content = evio_reader.evioRunParser(fileName) else: print "Format of the %s is not recognized (format=%s)"%(fileName,type) sys.exit(1) return content def locationFileParser(fileName): """A high-level method to parse location files in EventStore""" print "Location files are not currently supported!"%fileIn sys.exit(1) #type = fileType(fileName) #if type == "lhddm": # content = lhddm_dump.locationFileParser(fileName) #else: # print "Format of the %s is not recognized"%fileName # sys.exit(1) #return content def changeFileIdsInLocFile(locFileName,fileIdList): """A high-level method to change fileIds in location file to given list""" type = fileType(locFileName) if type == "lhddm": build_hddm_location.changeFileIdsInLocFile(locFileName,fileIdList) else: print "Format of the %s is not recognized (format=%s)"%(locFileName,type) sys.exit(1) return def getFileIds(locFileName): """A high-level method to get a list of fileIds from location file""" type = fileType(locFileName) file2IdList = [] # if type == "lhddm": # file2IdList = lhddm_dump.getFileIds(locFileName) # else: print "Format of the %s is not recognized (format=%s)"%(locFileName,type) sys.exit(1) # form 64-bit fileIds out of two 32-bit numbers fileIdList= [] idx = 0 while idx>8 # look if we match any of signatures what = "" if SIGNATURE == KEYSIGNATURE: what="ikey" #elif SIGNATURE == LOCSIGNATURE: what="lpds" # if nothing matches, swap bytes and check again headerHeader.byteswap() SWAPPEDSIGNATURE = headerHeader[0]>>8 if SWAPPEDSIGNATURE == KEYSIGNATURE: what="ikey" #elif SWAPPEDSIGNATURE == LOCSIGNATURE: what="lpds" # if file still not determined, try its extension if not what: what = string.split(fileName,".")[-1] fileDesc.close() return what