예제 #1
0
 def readScalarDataFile(self, scalarfile):
     scalarData = []
     for j in range(2):
         scalerData.append(range(9))
     fis = FileInputStream(self.scalarList[i])
     dis = DataInputStream(fis)
     scalerBytes = jarray.zeros(18 * 4, 'b')
     dis.read(scalerBytes, 0, 18 * 4)
     fis.close()
     offset = 0
     for j in range(2):
         for l in range(0, 36, 4):
             scalarData[j][
                 l / 4] = (0x000000FF & scalerBytes[offset + l + 0]) + (
                     (0x000000FF & scalerBytes[offset + l + 1]) << 8
                 ) + ((0x000000FF & scalerBytes[offset + l + 2]) << 16) + (
                     (0x000000FF & scalerBytes[offset + l + 3]) << 24)
         offset = offset + 36
     fis.close()
     return scalarData
예제 #2
0
 def run(self):
     print "connect to GS"
     sgs = Socket("127.0.0.1", 9011)
     i = DataInputStream(sgs.getInputStream())
     print "connect to GeoEditor"
     sge = Socket("127.0.0.1", 2109)
     # o = DataOutputStream(sge.getOutputStream())
     o = sge.getOutputStream()
     Thread.sleep(5000)
     GeoEditorListener.getInstance().getThread().addListener(self.vpl)
     print "gsge Ready"
     bufsize = 4096
     lastpos = 0
     buf = String("\0" * bufsize).getBytes()
     fc = 0
     while True:
         if not i.available():
             Thread.sleep(10)
             fc += 1
             if fc % 500 == 0:
                 o.flush()
                 fc = 0
             continue
         lastpos += i.read(buf, lastpos, bufsize - lastpos)
         while lastpos > 0 and lastpos > buf[0]:
             if buf[1] == 2:
                 pass
             elif buf[1] == 1:
                 x = self.list2num(buf[2:6])
                 y = self.list2num(buf[6:10])
                 z = self.list2num(buf[10:12])
                 if z > -15000:
                     rx, ry = GeoUtil.getRegionXY(x, y)
                     if (rx, ry) == (22, 22):
                         bx, by = GeoUtil.getBlockXY(x, y)
                         cx, cy = GeoUtil.getCellXY(x, y)
                         o.write(struct.pack(">BBBBh", bx, by, cx, cy, z))
             newpos = buf[0] + 1
             if len(buf) - newpos < bufsize:
                 buf = buf[newpos:] + String("\0" * bufsize).getBytes()
             else:
                 buf = buf[newpos:]
             lastpos -= newpos
예제 #3
0
파일: GeoGen.py 프로젝트: w001122/s4L2J
 def run(self):
     print "connect to GS"
     sgs = Socket("127.0.0.1", 9011)
     i = DataInputStream(sgs.getInputStream())
     print "connect to GeoEditor"
     sge = Socket("127.0.0.1", 2109)
     #o = DataOutputStream(sge.getOutputStream())
     o = sge.getOutputStream()
     Thread.sleep(5000)
     GeoEditorListener.getInstance().getThread().addListener(self.vpl)
     print "gsge Ready"
     bufsize = 4096
     lastpos = 0
     buf = String("\0" * bufsize).getBytes()
     fc = 0
     while True:
         if not i.available():
             Thread.sleep(10)
             fc += 1
             if fc % 500 == 0:
                 o.flush()
                 fc = 0
             continue
         lastpos += i.read(buf, lastpos, bufsize - lastpos)
         while lastpos > 0 and lastpos > buf[0]:
             if buf[1] == 2:
                 pass
             elif buf[1] == 1:
                 x = self.list2num(buf[2:6])
                 y = self.list2num(buf[6:10])
                 z = self.list2num(buf[10:12])
                 if z > -15000:
                     rx, ry = GeoUtil.getRegionXY(x, y)
                     if (rx, ry) == (22, 22):
                         bx, by = GeoUtil.getBlockXY(x, y)
                         cx, cy = GeoUtil.getCellXY(x, y)
                         o.write(struct.pack('>BBBBh', bx, by, cx, cy, z))
             newpos = buf[0] + 1
             if len(buf) - newpos < bufsize:
                 buf = buf[newpos:] + String("\0" * bufsize).getBytes()
             else:
                 buf = buf[newpos:]
             lastpos -= newpos
예제 #4
0
    def writeKScanSummary(self, npoints, start, end, step, edgeEnergy, twoD,
                          kStartTime, kEndTime, kWeighting):
        self.writeDetectorFile(npoints)
        current = start
        # lets window this mofo
        fid = open(self.datafilename, 'a')
        current = start
        for i in range(npoints):
            windowedData = [0.0] * 9
            print 'Reading and windowing:', self.mcaList[i]
            frameData = Xspress2Utilities.interpretDataFile(
                self.mcaList[i].strip(), 0)
            totalw = 0.0
            for j in range(9):
                sumgrades = frameData[j]
                windowedData[j] = windowedData[j] + self.windowData(
                    sumgrades, self.windowValues[j][0],
                    self.windowValues[j][1])
            for j in range(9):
                totalw = totalw + windowedData[j]
            #
            # now read scalar data
            #
            scalarData = []
            for j in range(2):
                scalarData.append(range(9))
            fis = FileInputStream(self.scalarList[i])
            dis = DataInputStream(fis)
            scalerBytes = jarray.zeros(18 * 4, 'b')
            dis.read(scalerBytes, 0, 18 * 4)
            fis.close()
            offset = 0
            for j in range(2):
                for l in range(0, 36, 4):
                    scalarData[j][l / 4] = (
                        0x000000FF & scalerBytes[offset + l + 0]
                    ) + ((0x000000FF & scalerBytes[offset + l + 1]) << 8) + (
                        (0x000000FF & scalerBytes[offset + l + 2]) << 16) + (
                            (0x000000FF & scalerBytes[offset + l + 3]) << 24)
                offset = offset + 36
            secTime = self.timeForK(current, start, end, kWeighting, kEndTime,
                                    kStartTime)
            liveTime = secTime / 1000.0
            corrCounts = self.getCorrectedCounts(scalarData[0], scalarData[1],
                                                 liveTime)
            measuredCounts = scalarData[0]
            relinCounts = self.reLinearizeCounts(corrCounts)
            factor = []
            for j in range(len(relinCounts)):
                if (relinCounts[j] == 0 or measuredCounts[j] == 0):
                    val = 1
                    factor.append(1.0)
                else:
                    val = (relinCounts[j] / measuredCounts[j])
                    factor.append(val * liveTime)
            correctWindows = []
            corrWindTot = 0.0
            for j in range(9):
                correctW = float(windowedData[j]) * factor[j]
                corrWindTot = corrWindTot + correctW
                correctWindows.append(correctW)
            #print>>fid,self.mDegForK(current,edgeEnergy,twoD),comboDCM.calcEnergy(self.mDegForK(current,edgeEnergy,twoD)/1000.0),\
            #	secTime,self.ionchamberData[i][0],self.ionchamberData[i][1],self.ionchamberData[i][2],str(windowedData[0:]).strip('[]').replace(',',''), \
            #	totalw,str(correctWindows[0:]).strip('[]').replace(',',''),corrWindTot
            print>>fid,self.mDegForK(current,edgeEnergy,twoD),comboDCM.calcEnergy(self.mDegForK(current,edgeEnergy,twoD)/1000.0),\
             secTime,self.ionchamberData[i][0],self.ionchamberData[i][1],self.ionchamberData[i][2],str(windowedData[0:]).strip('[]').replace(',',''), \
             totalw,str(correctWindows[0:]).strip('[]').replace(',',''),corrWindTot
            current = current + step
            # SDP Stuff
            detectorVector = Vector()
            detectorVector.add(self.ionchamberData[i])
            detectorVector.add(windowedData[0:])
            positionVector = Vector()
            positionVector.add(str(self.mDegForK(current, edgeEnergy, twoD)))
            #sdp = ScanDataPoint("scan name",self.scannableNamesVector,self.detectorNamesVector,positionVector,detectorVector,"Panel Name","I18 Custom SDP","Header String",self.datafilename)
            sdp = ScanDataPoint("Exafs FluKScan", self.scannableNamesVector,
                                self.detectorNamesVector, None, None, None,
                                None, positionVector, detectorVector, None,
                                "Panel Name", "I18 Custom SDP",
                                "Header String", self.datafilename, 0)
            self.controller.update(None, sdp)
            self.mcontroller.update(None, sdp)

        fid.close()
from java.io import DataInputStream as DI
from java.io import DataOutputStream as DO

a = str(10)
b = str(20)
di = DI(a)
do = DO(b)
c = di.read()
do.write(c)

print(a,b,c)