#!/usr/bin/env python2 # # Test the data dump of a midas file. import sys import os import os.path import commands import re inputFile = 'tript-banks-080801.mid.gz' outputFile = '200TripTRawMIDAS.root' dumpFile = '200TripTRawMIDAS.dump' if not os.path.exists(inputFile): print "MISSING INPUT" sys.exit(0) if os.path.exists(outputFile): os.remove(outputFile) # Get a dump of the file os.system("oaRawEvent_midas-event.exe -a -m " + inputFile + " -o " + outputFile + " | sed 's/(0x[0-9a-f]*)::/()::/' > " + dumpFile) eventDump = commands.getoutput('cat ' + dumpFile) # Make a simple way to check for a regular expression on a single line. def DoesExist(pattern): # Check if a pattern is found in the output. result = re.search(pattern,eventDump,re.M) if result is None: print "Pattern not found: ", pattern return False return True # Make a simple way to check for a regular expression on a single line. def DoesNotExist(pattern): # Check if a pattern is found in the output. result = re.search(pattern,eventDump,re.M) if result is not None: print "Pattern found: ", pattern return False return True # Look for re that should be in the file. valid = True if not DoesExist('^COMET::ICOMETEvent.+event.00251'): valid = False if not DoesExist('^ COMET::ICOMETRawEvent.+rawevent.00251'): valid = False if not DoesExist('COMET::IMidasBank'): valid = False if not DoesExist(r'\(COMET::ITripTDigitBank\)'): valid = False if not DoesExist('^Total Events Read: 9$'): valid = False if not valid: print "FAIL"