grib/src/main/java/ucar/nc2/grib/collection/GribCollectionBuilder.java
private boolean createAllRuntimeCollections(Formatter errlog) throws IOException {
    long start = System.currentTimeMillis();
    this.type =  GribCollectionImmutable.Type.SRC;
    boolean ok = true;

    List<MFile> files = new ArrayList<>();
    List<? extends Group> groups = makeGroups(files, true, errlog);
    List<MFile> allFiles = Collections.unmodifiableList(files);

    // gather into collections with a single runtime
    Map<Long, List<Group>> runGroups = new HashMap<>();
    for (Group g : groups) {
      List<Group> runGroup = runGroups
          .computeIfAbsent(g.getRuntime().getMillis(), k -> new ArrayList<>());
      runGroup.add(g);
    }

    // write each rungroup separately
    boolean multipleRuntimes = runGroups.values().size() > 1;
    List<MFile> partitions = new ArrayList<>();
    for (List<Group> runGroupList : runGroups.values()) {
      Group g = runGroupList.get(0);
      // if multiple Runtimes, we will write a partition. otherwise, we need to use the standard name (without runtime) so we know the filename from the collection
      String gcname = multipleRuntimes ? GribCollectionMutable.makeName(this.name, g.getRuntime()) : this.name;
      MFile indexFileForRuntime = GribCollectionMutable.makeIndexMFile(gcname, directory); // not using disk cache LOOK why ?
      partitions.add(indexFileForRuntime);

     // create the master runtimes, consisting of the single runtime
      List<Long> runtimes = new ArrayList<>(1);
      runtimes.add(g.getRuntime().getMillis());
      CoordinateRuntime masterRuntimes = new CoordinateRuntime(runtimes, null);

      CalendarDateRange calendarDateRangeAll = null;
      for (Coordinate coord : g.getCoordinates()) {
        if (coord instanceof CoordinateTimeAbstract) {
          CalendarDateRange calendarDateRange = ((CoordinateTimeAbstract) coord).makeCalendarDateRange(null);
          if (calendarDateRangeAll == null) calendarDateRangeAll = calendarDateRange;
          else calendarDateRangeAll = calendarDateRangeAll.extend(calendarDateRange);
        }
      }
      assert calendarDateRangeAll != null;

      // for each Group write an index file
      ok &= writeIndex(gcname, indexFileForRuntime.getPath(), masterRuntimes, runGroupList, allFiles, calendarDateRangeAll);
      logger.info("GribCollectionBuilder write {} ok={}", indexFileForRuntime.getPath(), ok);
    }

    // if theres more than one runtime, create a partition collection to collect all the runtimes together
    if (multipleRuntimes) {
      Collections.sort(partitions); // ??
      PartitionManager part = new PartitionManagerFromIndexList(dcm, partitions, logger);
      part.putAuxInfo(FeatureCollectionConfig.AUX_CONFIG, dcm.getAuxInfo(FeatureCollectionConfig.AUX_CONFIG));
      ok &= GribCdmIndex.updateGribCollectionFromPCollection(isGrib1, part, CollectionUpdateType.always, errlog, logger);
    }

    long took = System.currentTimeMillis() - start;
    logger.debug("That took {} msecs", took);
    return ok;
  }
private boolean createAllRuntimeCollections(Formatter errlog) throws IOException {
    long start = System.currentTimeMillis();
    this.type =  GribCollectionImmutable.Type.SRC;
    boolean ok = true;

    List<MFile> files = new ArrayList<>();
    List<? extends Group> groups = makeGroups(files, true, errlog);
    List<MFile> allFiles = Collections.unmodifiableList(files);

    // gather into collections with a single runtime
    Map<Long, List<Group>> runGroups = new HashMap<>();
    for (Group g : groups) {
      List<Group> runGroup = runGroups
          .computeIfAbsent(g.getRuntime().getMillis(), k -> new ArrayList<>());
      runGroup.add(g);
    }

    // write each rungroup separately
    boolean multipleRuntimes = runGroups.values().size() > 1;
    List<MFile> partitions = new ArrayList<>();
    for (List<Group> runGroupList : runGroups.values()) {
      Group g = runGroupList.get(0);
      // if multiple Runtimes, we will write a partition. otherwise, we need to use the standard name (without runtime) so we know the filename from the collection
      String gcname = multipleRuntimes ? GribCollectionMutable.makeName(this.name, g.getRuntime()) : this.name;
      MFile indexFileForRuntime = GribCollectionMutable.makeIndexMFile(gcname, directory); // not using disk cache LOOK why ?
      partitions.add(indexFileForRuntime);

     // create the master runtimes, consisting of the single runtime
      List<Long> runtimes = new ArrayList<>(1);
      runtimes.add(g.getRuntime().getMillis());
      CoordinateRuntime masterRuntimes = new CoordinateRuntime(runtimes, null);

      CalendarDateRange calendarDateRangeAll = null;
      for (Coordinate coord : g.getCoordinates()) {
        if (coord instanceof CoordinateTimeAbstract) {
          CalendarDateRange calendarDateRange = ((CoordinateTimeAbstract) coord).makeCalendarDateRange(null);
          if (calendarDateRangeAll == null) calendarDateRangeAll = calendarDateRange;
          else calendarDateRangeAll = calendarDateRangeAll.extend(calendarDateRange);
        }
      }
      assert calendarDateRangeAll != null;

      // for each Group write an index file
      ok &= writeIndex(gcname, indexFileForRuntime.getPath(), masterRuntimes, runGroupList, allFiles, calendarDateRangeAll);
      logger.info("GribCollectionBuilder write {} ok={}", indexFileForRuntime.getPath(), ok);
    }

    // if theres more than one runtime, create a partition collection to collect all the runtimes together
    if (multipleRuntimes) {
      Collections.sort(partitions); // ??
      PartitionManager part = new PartitionManagerFromIndexList(dcm, partitions, logger);
      part.putAuxInfo(FeatureCollectionConfig.AUX_CONFIG, dcm.getAuxInfo(FeatureCollectionConfig.AUX_CONFIG));
      ok &= GribCdmIndex.updateGribCollectionFromPCollection(isGrib1, part, CollectionUpdateType.always, errlog, logger);
    }

    long took = System.currentTimeMillis() - start;
    logger.debug("That took {} msecs", took);
    return ok;
  }
private boolean createAllRuntimeCollections ( Formatter errlog ) throws IOException { long start = System . currentTimeMillis ( ) ; this . type = GribCollectionImmutable . Type . SRC ; boolean ok = true ; List < MFile > files = new ArrayList <> ( ) ; List < ? extends Group > groups = makeGroups ( files , true , errlog ) ; List < MFile > allFiles = Collections . unmodifiableList ( files ) ; // gather into collections with a single runtime Map < Long , List < Group > > runGroups = new HashMap <> ( ) ; for ( Group g : groups ) { List < Group > runGroup = runGroups . computeIfAbsent ( g . getRuntime ( ) . getMillis ( ) , k -> new ArrayList <> ( ) ) ; runGroup . add ( g ) ; } // write each rungroup separately boolean multipleRuntimes = runGroups . values ( ) . size ( ) > 1 ; List < MFile > partitions = new ArrayList <> ( ) ; for ( List < Group > runGroupList : runGroups . values ( ) ) { Group g = runGroupList . get ( 0 ) ; // if multiple Runtimes, we will write a partition. otherwise, we need to use the standard name (without runtime) so we know the filename from the collection String gcname = multipleRuntimes ? GribCollectionMutable . makeName ( this . name , g . getRuntime ( ) ) : this . name ; MFile indexFileForRuntime = GribCollectionMutable . makeIndexMFile ( gcname , directory ) ; // not using disk cache LOOK why ? partitions . add ( indexFileForRuntime ) ; // create the master runtimes, consisting of the single runtime List < Long > runtimes = new ArrayList <> ( 1 ) ; runtimes . add ( g . getRuntime ( ) . getMillis ( ) ) ; CoordinateRuntime masterRuntimes = new CoordinateRuntime ( runtimes , null ) ; CalendarDateRange calendarDateRangeAll = null ; for ( Coordinate coord : g . getCoordinates ( ) ) { if ( coord instanceof CoordinateTimeAbstract ) { CalendarDateRange calendarDateRange = ( ( CoordinateTimeAbstract ) coord ) . makeCalendarDateRange ( null ) ; if ( calendarDateRangeAll == null ) calendarDateRangeAll = calendarDateRange ; else calendarDateRangeAll = calendarDateRangeAll . extend ( calendarDateRange ) ; } } assert calendarDateRangeAll != null ; // for each Group write an index file ok &= writeIndex ( gcname , indexFileForRuntime . getPath ( ) , masterRuntimes , runGroupList , allFiles , calendarDateRangeAll ) ; logger . info ( "GribCollectionBuilder write {} ok={}" , indexFileForRuntime . getPath ( ) , ok ) ; } // if theres more than one runtime, create a partition collection to collect all the runtimes together if ( multipleRuntimes ) { Collections . sort ( partitions ) ; // ?? PartitionManager part = new PartitionManagerFromIndexList ( dcm , partitions , logger ) ; part . putAuxInfo ( FeatureCollectionConfig . AUX_CONFIG , dcm . getAuxInfo ( FeatureCollectionConfig . AUX_CONFIG ) ) ; ok &= GribCdmIndex . updateGribCollectionFromPCollection ( isGrib1 , part , CollectionUpdateType . always , errlog , logger ) ; } long took = System . currentTimeMillis ( ) - start ; logger . debug ( "That took {} msecs" , took ) ; return ok ; }
creates seperate collection and index for each runtime.
creates seperate collection and index for each runtime .