<commit_before>package bdv.img.hdf5;

import static bdv.img.hdf5.Util.getCellsPath;
import static bdv.img.hdf5.Util.reorder;

import java.io.StringWriter;

import net.imglib2.img.basictypeaccess.volatiles.array.VolatileShortArray;
import bdv.img.cache.CacheArrayLoader;
import ch.systemsx.cisd.base.mdarray.MDShortArray;
import ch.systemsx.cisd.hdf5.IHDF5Reader;

public class Hdf5VolatileShortArrayLoader implements CacheArrayLoader< VolatileShortArray >
{
	private final IHDF5Reader hdf5Reader;

	private VolatileShortArray theEmptyArray;

	public Hdf5VolatileShortArrayLoader( final IHDF5Reader hdf5Reader )
	{
		this.hdf5Reader = hdf5Reader;
		theEmptyArray = new VolatileShortArray( 32 * 32 * 32, false );
	}

	public static volatile String previousCellsPath = "";

	@Override
	public VolatileShortArray loadArray( final int timepoint, final int setup, final int level, final int[] dimensions, final long[] min )
	{
		final MDShortArray array;
		long t0 = System.currentTimeMillis();
		long t1;
		long t2;
		final String cellsPath = getCellsPath( timepoint, setup, level );
		final String prevCellsPath;
		synchronized ( hdf5Reader )
		{
			t1 = System.currentTimeMillis() - t0;
			t0 = System.currentTimeMillis();
			array = hdf5Reader.readShortMDArrayBlockWithOffset( getCellsPath( timepoint, setup, level ), reorder( dimensions ), reorder( min ) );
			t2 = System.currentTimeMillis() - t0;
			prevCellsPath = previousCellsPath;
			previousCellsPath = cellsPath;
		}
		if ( t1 > 5 )
		{
			final StringWriter sw = new StringWriter();
			sw.write( "waited " + t1 + " ms for hdf5Reader lock\n" );
			sw.write( "after   " + prevCellsPath + "\n" );
			sw.write( "loading " + cellsPath + "\n" );
			final StackTraceElement[] trace = Thread.currentThread().getStackTrace();
			boolean found = false;
			for ( final StackTraceElement elem : trace )
			{
				if ( elem.getClassName().equals( "bdv.img.cache.VolatileGlobalCellCache$Hdf5CellCache" ) && elem.getMethodName().equals( "get" ) )
				{
					found = true;
					sw.write( "Hdf5CellCache.get\n" );
					break;
				}
				if ( elem.getClassName().equals( "bdv.img.cache.VolatileGlobalCellCache$Hdf5CellCache" ) && elem.getMethodName().equals( "load" ) )
				{
					found = true;
					sw.write( "Hdf5CellCache.load\n" );
					break;
				}
				if ( elem.getClassName().equals( "bdv.img.cache.VolatileGlobalCellCache$Fetcher" ) && elem.getMethodName().equals( "run" ) )
				{
					found = true;
					sw.write( "Fetcher.run\n" );
					break;
				}
				if ( elem.getClassName().equals( "bdv.img.cache.VolatileGlobalCellCache" ) && elem.getMethodName().equals( "loadOrEnqueue" ) )
				{
					found = true;
					sw.write( "!!!!!!!!!! VolatileGlobalCellCache.loadOrEnqueue\n" );
					break;
				}
			}
			if ( !found )
			{
				for ( final StackTraceElement elem : trace )
					sw.write( elem.getClassName() + "." + elem.getMethodName() + "\n" );
			}
			System.out.println( sw.toString() );
		}
		if ( t2 > 20 )
		{
			final StringWriter sw = new StringWriter();
			sw.write( "waited " + t2 + " ms for hdf5 readShortMDArrayBlockWithOffset\n" );
			sw.write( "after   " + prevCellsPath + "\n" );
			sw.write( "loading " + cellsPath + "\n" );
			final StackTraceElement[] trace = Thread.currentThread().getStackTrace();
			boolean found = false;
			for ( final StackTraceElement elem : trace )
			{
				if ( elem.getClassName().equals( "bdv.img.cache.VolatileGlobalCellCache$Hdf5CellCache" ) && elem.getMethodName().equals( "get" ) )
				{
					found = true;
					sw.write( "Hdf5CellCache.get\n" );
					break;
				}
				if ( elem.getClassName().equals( "bdv.img.cache.VolatileGlobalCellCache$Hdf5CellCache" ) && elem.getMethodName().equals( "load" ) )
				{
					found = true;
					sw.write( "Hdf5CellCache.load\n" );
					break;
				}
				if ( elem.getClassName().equals( "bdv.img.cache.VolatileGlobalCellCache$Fetcher" ) && elem.getMethodName().equals( "run" ) )
				{
					found = true;
					sw.write( "Fetcher.run\n" );
					break;
				}
				if ( elem.getClassName().equals( "bdv.img.cache.VolatileGlobalCellCache" ) && elem.getMethodName().equals( "loadOrEnqueue" ) )
				{
					found = true;
					sw.write( "!!!!!!!!!! VolatileGlobalCellCache.loadOrEnqueue\n" );
					break;
				}
			}
			if ( !found )
			{
				for ( final StackTraceElement elem : trace )
					sw.write( elem.getClassName() + "." + elem.getMethodName() + "\n" );
			}
			System.out.println( sw.toString() );
		}
		return new VolatileShortArray( array.getAsFlatArray(), true );
	}
<commit_msg>remove debug output<commit_after>package bdv.img.hdf5;

import static bdv.img.hdf5.Util.getCellsPath;
import static bdv.img.hdf5.Util.reorder;
import net.imglib2.img.basictypeaccess.volatiles.array.VolatileShortArray;
import bdv.img.cache.CacheArrayLoader;
import ch.systemsx.cisd.base.mdarray.MDShortArray;
import ch.systemsx.cisd.hdf5.IHDF5Reader;

public class Hdf5VolatileShortArrayLoader implements CacheArrayLoader< VolatileShortArray >
{
	private final IHDF5Reader hdf5Reader;

	private VolatileShortArray theEmptyArray;

	public Hdf5VolatileShortArrayLoader( final IHDF5Reader hdf5Reader )
	{
		this.hdf5Reader = hdf5Reader;
		theEmptyArray = new VolatileShortArray( 32 * 32 * 32, false );
	}

	public static volatile String previousCellsPath = "";

	@Override
	public VolatileShortArray loadArray( final int timepoint, final int setup, final int level, final int[] dimensions, final long[] min )
	{
		final MDShortArray array;
		synchronized ( hdf5Reader )
		{
			array = hdf5Reader.readShortMDArrayBlockWithOffset( getCellsPath( timepoint, setup, level ), reorder( dimensions ), reorder( min ) );
		}
		return new VolatileShortArray( array.getAsFlatArray(), true );
	}

{'fraction_non_alphanumeric': 0.13038130381303814, 'fraction_numerical': 0.012124406958355299, 'mean_word_length': 3.7472894078398666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '372542', 'n_tokens_mistral': 2234, 'n_tokens_neox': 1918, 'n_words': 383}