Loads a segment.
329830
private JournalSegment<E> loadSegment(long segmentId) {
    File segmentFile = JournalSegmentFile.createSegmentFile(name, directory, segmentId);
    ByteBuffer buffer = ByteBuffer.allocate(JournalSegmentDescriptor.BYTES);
    try (FileChannel channel = openChannel(segmentFile)) {
      channel.read(buffer);
      buffer.flip();
      JournalSegmentDescriptor descriptor = new JournalSegmentDescriptor(buffer);
      JournalSegment<E> segment = newSegment(new JournalSegmentFile(segmentFile), descriptor);
      log.debug("Loaded disk segment: {} ({})", descriptor.id(), segmentFile.getName());
      return segment;
    } catch (IOException e) {
      throw new StorageException(e);
    }
  }
907675
protected Collection<JournalSegment<E>> loadSegments() {
    // Ensure log directories are created.
    directory.mkdirs();

    TreeMap<Long, JournalSegment<E>> segments = new TreeMap<>();

    // Iterate through all files in the log directory.
    for (File file : directory.listFiles(File::isFile)) {

      // If the file looks like a segment file, attempt to load the segment.
      if (JournalSegmentFile.isSegmentFile(name, file)) {
        JournalSegmentFile segmentFile = new JournalSegmentFile(file);
        ByteBuffer buffer = ByteBuffer.allocate(JournalSegmentDescriptor.BYTES);
        try (FileChannel channel = openChannel(file)) {
          channel.read(buffer);
          buffer.flip();
        } catch (IOException e) {
          throw new StorageException(e);
        }

        JournalSegmentDescriptor descriptor = new JournalSegmentDescriptor(buffer);

        // Load the segment.
        JournalSegment<E> segment = loadSegment(descriptor.id());

        // Add the segment to the segments list.
        log.debug("Found segment: {} ({})", segment.descriptor().id(), segmentFile.file().getName());
        segments.put(segment.index(), segment);
      }
    }

    // Verify that all the segments in the log align with one another.
    JournalSegment<E> previousSegment = null;
    boolean corrupted = false;
    Iterator<Map.Entry<Long, JournalSegment<E>>> iterator = segments.entrySet().iterator();
    while (iterator.hasNext()) {
      JournalSegment<E> segment = iterator.next().getValue();
      if (previousSegment != null && previousSegment.lastIndex() != segment.index() - 1) {
        log.warn("Journal is inconsistent. {} is not aligned with prior segment {}", segment.file().file(), previousSegment.file().file());
        corrupted = true;
      }
      if (corrupted) {
        segment.close();
        segment.delete();
        iterator.remove();
      }
      previousSegment = segment;
    }

    return segments.values();
  }
394937
private void ensureCapacity(int segmentIndex) {
        while(segmentIndex >= segments.length) {
            segments = Arrays.copyOf(segments, segments.length * 3 / 2);
        }

        long numSegmentsPopulated = length >> log2OfSegmentSize;

        for(long i=numSegmentsPopulated; i <= segmentIndex; i++) {
            segments[(int)i] = memoryPool.getSegment();
            length += 1 << log2OfSegmentSize;
        }
    }
1010270
private void initializeBufferQueue(int segmentFileSizeMB) {
        int bufferLength = 
            (segmentFileSizeMB < Segment.maxSegmentFileSizeMB) ?
            (segmentFileSizeMB * 1024 * 1024) : Integer.MAX_VALUE;
            
        lazyCount = 3;
        for (int i = 0; i < lazyCount; i++) {
            ByteBuffer buffer = ByteBuffer.wrap(new byte[bufferLength]);
            _bufferQueue.add(buffer);
        }
    }
459883
def segments
      EXPORT.map do |sym|
        seg = __send__(sym)
        [sym, seg] if seg.is_a?(Segment)
      end.compact.to_h
    end
1144856
private void compactEntries(Segment segment, Segment compactSegment) {
    for (long i = segment.firstIndex(); i <= segment.lastIndex(); i++) {
      checkEntry(i, segment, compactSegment);
    }
  }
1208765
private SectionTable loadSectionTable(PESignature pesig,
            COFFFileHeader coff, RandomAccessFile raf) throws IOException {
        // offset is the start of the optional header + SizeOfOptionalHeader
        long offset = pesig.getOffset() + PESignature.PE_SIG.length
                + COFFFileHeader.HEADER_SIZE + coff.getSizeOfOptionalHeader();
        logger.info("SectionTable offset: " + offset);
        // get entries, so you can determine the size
        int numberOfEntries = (int) coff.getNumberOfSections();
        int size = SectionTable.ENTRY_SIZE * numberOfEntries;
        if (size + offset > file.length()) {
            size = (int) (file.length() - offset);
        }
        if (size <= 0) {
            logger.warn("Unable to parse Section table, offset outside the file");
            return new SectionTable(new byte[0], 0, offset);
        }
        // read bytes
        byte[] tableBytes = loadBytes(offset, size, raf);
        // construct header
        return new SectionTable(tableBytes, numberOfEntries, offset);
    }
863348
public static void decodePathSegment(List<PathSegment> segments, String segment, boolean decode) {
        int colon = segment.indexOf(';');
        if (colon != -1) {
            segments.add(new PathSegmentImpl(
                    (colon == 0) ? "" : segment.substring(0, colon),
                    decode,
                    decodeMatrix(segment, decode)));
        } else {
            segments.add(new PathSegmentImpl(
                    segment,
                    decode));
        }
    }
1147460
def start_end_from_segments(segment_file):
    
    from glue.ligolw.ligolw import LIGOLWContentHandler as h; lsctables.use_in(h)
    indoc = ligolw_utils.load_filename(segment_file, False, contenthandler=h)
    segment_table  = table.get_table(indoc, lsctables.SegmentTable.tableName)
    start = numpy.array(segment_table.getColumnByName('start_time'))
    start_ns = numpy.array(segment_table.getColumnByName('start_time_ns'))
    end = numpy.array(segment_table.getColumnByName('end_time'))
    end_ns = numpy.array(segment_table.getColumnByName('end_time_ns'))
    return start + start_ns * 1e-9, end + end_ns * 1e-9
1227729
def load(self, shapefile=None):
        """"""
        if shapefile:
            (shapeName, ext) = os.path.splitext(shapefile)
            self.shapeName = shapeName
            try:
                self.shp = open("%s.shp" % shapeName, "rb")
            except IOError:
                raise ShapefileException("Unable to open %s.shp" % shapeName)
            try:
                self.shx = open("%s.shx" % shapeName, "rb")
            except IOError:
                raise ShapefileException("Unable to open %s.shx" % shapeName)
            try:
                self.dbf = open("%s.dbf" % shapeName, "rb")
            except IOError:
                raise ShapefileException("Unable to open %s.dbf" % shapeName)
        if self.shp:
            self.__shpHeader()
        if self.dbf:
            self.__dbfHeader()
628588
def readsegment(d, segment):
    

    # set requested time range based on given parameters
    starttime = qa.getvalue(qa.convert(qa.time(qa.quantity(d['segmenttimes'][segment,0],'d'),form=['ymd'], prec=9)[0], 's'))[0]
    stoptime = qa.getvalue(qa.convert(qa.time(qa.quantity(d['segmenttimes'][segment,1],'d'),form=['ymd'], prec=9)[0], 's'))[0]
    logger.info('Reading segment %d/%d, times %s to %s' % (segment, len(d['segmenttimes'])-1, qa.time(qa.quantity(starttime/(24*3600),'d'),form=['hms'], prec=9)[0], qa.time(qa.quantity(stoptime/(24*3600), 'd'), form=['hms'], prec=9)[0]))

    # read data into data structure
    ms.open(d['filename'])
    if len(d['spwlist']) == 1:
        ms.selectinit(datadescid=d['spwlist'][0])
    else:
        ms.selectinit(datadescid=0, reset=True)    # reset includes spw in iteration over time
    selection = {'time': [starttime, stoptime], 'uvdist': [1., 1e10]}
#    selection = {'time': [starttime, stoptime], 'uvdist': [1., 1e10], 'antenna1': d['ants'], 'antenna2': d['ants']}    # **this misses ants for some reason!**
    ms.select(items = selection)
    ms.selectpolarization(d['pols'])
    da = ms.getdata([d['datacol'],'axis_info','u','v','w','flag','data_desc_id'], ifraxis=True)
    good = n.where((da['data_desc_id']) == d['spwlist'][0])[0]   # take first spw                                                
    time0 = da['axis_info']['time_axis']['MJDseconds'][good]
    data0 = n.transpose(da[d['datacol']], axes=[3,2,1,0])[good]
    flag0 = n.transpose(da['flag'], axes=[3,2,1,0])[good]
    u0 = da['u'].transpose()[good] * d['freq_orig'][0] * (1e9/3e8)    # uvw are in m, so divide by wavelength of first chan to set in lambda
    v0 = da['v'].transpose()[good] * d['freq_orig'][0] * (1e9/3e8)
    w0 = da['w'].transpose()[good] * d['freq_orig'][0] * (1e9/3e8)

    if len(d['spwlist']) > 1:
        for spw in d['spwlist'][1:]:
            good = n.where((da['data_desc_id']) == spw)[0]
            data1 = n.transpose(da[d['datacol']], axes=[3,2,1,0])[good]
            data0 = n.concatenate( (data0, data1), axis=2 )
            flag0 = n.concatenate( (flag0, n.transpose(da['flag'], axes=[3,2,1,0])[good]), axis=2 )

    del da
    data0 = data0[:,:,d['chans'],:] * n.invert(flag0[:,:,d['chans'],:])   # flag==1 means bad data (for vla)                     

    return data0.astype('complex64'), u0.astype('float32'), v0.astype('float32'), w0.astype('float32')
356116
public void freeSegment(SegmentKelp segment)
    throws IOException
  {
    // System.out.println("FREE: " + segment);
    SegmentMeta segmentMeta = findSegmentMeta(segment.length());
    
    segmentMeta.remove(segment);
    
    segment.close();
    
    segmentMeta.addFree(segment.extent());
    
    // System.out.println("  FREE: " + segmentMeta.getFreeCount() + " " + segment.getLength());
  }
1152717
private void compactEntry(long index, Segment segment, Segment compactSegment) {
    compactSegment.skip(1);
    LOGGER.trace("Compacted entry {} from segment {}", index, segment.descriptor().id());
  }
374611
public function current()
    {
        if ($this->currentSegment === null) {
            if (!$this->valid()) {
                throw new OutOfBoundsException('Cannot load segment, invalid offset');
            }

            $this->load(['offset' => $this->offset] + $this->params);
        }

        return $this->currentSegment;
    }
1320969
private void initSegs() throws IOException {
        int loaded = 0;
        File[] segFiles = listSegmentFiles();
        if (segFiles.length == 0) {
            return;
        }

        try {
            for (int i = 0; i < segFiles.length; i++) {
                File segFile = segFiles[i];
                int segId = Integer.parseInt(segFile.getName().substring(0, segFile.getName().indexOf('.')));
                if (segId != i) {
                    throw new IOException("Segment file " + i + ".seg missing");
                }

                if (getMeta().hasSegmentInService(segId)) {
                    // Always load a live segment as READ_ONLY
                    Segment s = getSegmentFactory().createSegment(segId, segFile, _segFileSizeMB, Segment.Mode.READ_ONLY);
                    s.incrLoadSize(getMeta().getSegmentLoadSize(segId));
                    _segList.add(s);
                    loaded++;
                } else {
                    // Segment is not live and is free for reuse
                    _segList.add(null);
                }
            }
        } catch (IOException e) {
            _log.error(e.getMessage());
            
            clearInternal(false /* DO NOT CLEAR META */);
            throw e;
        }

        _log.info("loaded: " + loaded + "/" + segFiles.length);
    }
1270443
public static void seg(File input, File output, SegmentationAlgorithm segmentationAlgorithm) throws Exception{
        Utils.seg(input, output, true, segmentationAlgorithm);
    }
1310781
def get_segment(self, indx):
        """"""
        if _debug: SSM._debug("get_segment %r", indx)

        # check for no context
        if not self.segmentAPDU:
            raise RuntimeError("no segmentation context established")

        # check for invalid segment number
        if indx >= self.segmentCount:
            raise RuntimeError("invalid segment number %r, APDU has %r segments" % (indx, self.segmentCount))

        if self.segmentAPDU.apduType == ConfirmedRequestPDU.pduType:
            if _debug: SSM._debug("    - confirmed request context")

            segAPDU = ConfirmedRequestPDU(self.segmentAPDU.apduService)

            segAPDU.apduMaxSegs = encode_max_segments_accepted(self.maxSegmentsAccepted)
            segAPDU.apduMaxResp = encode_max_apdu_length_accepted(self.maxApduLengthAccepted)
            segAPDU.apduInvokeID = self.invokeID

            # segmented response accepted?
            segAPDU.apduSA = self.segmentationSupported in ('segmentedReceive', 'segmentedBoth')
            if _debug: SSM._debug("    - segmented response accepted: %r", segAPDU.apduSA)

        elif self.segmentAPDU.apduType == ComplexAckPDU.pduType:
            if _debug: SSM._debug("    - complex ack context")

            segAPDU = ComplexAckPDU(self.segmentAPDU.apduService, self.segmentAPDU.apduInvokeID)
        else:
            raise RuntimeError("invalid APDU type for segmentation context")

        # maintain the the user data reference
        segAPDU.pduUserData = self.segmentAPDU.pduUserData

        # make sure the destination is set
        segAPDU.pduDestination = self.pdu_address

        # segmented message?
        if (self.segmentCount != 1):
            segAPDU.apduSeg = True
            segAPDU.apduMor = (indx < (self.segmentCount - 1)) # more follows
            segAPDU.apduSeq = indx % 256                       # sequence number

            # first segment sends proposed window size, rest get actual
            if indx == 0:
                if _debug: SSM._debug("    - proposedWindowSize: %r", self.ssmSAP.proposedWindowSize)
                segAPDU.apduWin = self.ssmSAP.proposedWindowSize
            else:
                if _debug: SSM._debug("    - actualWindowSize: %r", self.actualWindowSize)
                segAPDU.apduWin = self.actualWindowSize
        else:
            segAPDU.apduSeg = False
            segAPDU.apduMor = False

        # add the content
        offset = indx * self.segmentSize
        segAPDU.put_data( self.segmentAPDU.pduData[offset:offset+self.segmentSize] )

        # success
        return segAPDU