Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:46

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 """
0022 bouncelog.py
0023 ==============
0024 
0025 Parse the kernel print log::
0026 
0027      tboolean-;tboolean-box --okg4 --align --mask 1230 --pindex 0 --pindexlog -DD   
0028 
0029           ## write kernel pindexlog for photon 1230
0030 
0031     boucelog.py 1230
0032 
0033           ## parse the log 
0034 
0035 
0036 """
0037 from __future__ import print_function
0038 from collections import OrderedDict
0039 import os, sys, re
0040 
0041 
0042 class Bounce(list):
0043     def __init__(self):
0044         list.__init__(self)
0045     def __str__(self):
0046        return "\n".join([""]+self+[""])
0047 
0048 
0049 class BounceLog(OrderedDict):
0050     @classmethod
0051     def printlogpath(cls, pindex):
0052         return os.path.expandvars("$TMP/ox_%s.log" % pindex )
0053 
0054     BOUNCE = re.compile("bounce:(\S*)")
0055 
0056     def __init__(self, pindex):
0057         OrderedDict.__init__(self)
0058         self.pindex = pindex
0059         self.path = self.printlogpath(pindex)
0060         self.parse(self.path)
0061         
0062     def parse(self, path):
0063         self.lines = map(lambda line:line.rstrip(),file(path).readlines())
0064 
0065         curr = []
0066         bounce = -1
0067 
0068         for i, line in enumerate(self.lines):
0069             m = self.BOUNCE.search(line)
0070             if m:
0071                 #bounce = int(m.group(1))   ## some OptiX rtPrintf bug makes bounce always 0 
0072                 bounce += 1
0073                 self[bounce] = Bounce()
0074             pass
0075             if bounce > -1:
0076                 self[bounce].append(line)
0077             pass
0078             #print(" %3d : %3d : %s " % ( i, bounce,  line ))
0079 
0080 
0081 if __name__ == '__main__':
0082 
0083 
0084     pindex = int(sys.argv[1]) if len(sys.argv) > 1 else 1230
0085 
0086     bl = BounceLog(pindex)
0087 
0088     for k, v in bl.items():
0089         print(k)
0090         print(v)
0091         print("\n\n") 
0092 
0093    
0094