Skip to content

Commit

Permalink
Update N5 Hash Function Names
Browse files Browse the repository at this point in the history
  • Loading branch information
AvocadoMoon committed Jan 7, 2025
1 parent 8c361ab commit 579eb5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public ExportEvent makeRemoteFile(OutputContext outputContext,User user, DataSer
case N5:
N5Exporter n5Exporter = new N5Exporter(this, user, dataServerImpl, (VCSimulationDataIdentifier) exportSpecs.getVCDataIdentifier());
ExportOutput exportOutput = n5Exporter.makeN5Data(outputContext, newExportJob, exportSpecs, fileDataContainerManager);
return makeRemoteN5File(fileFormat, n5Exporter.getN5FileNameHash(), exportOutput, exportSpecs, newExportJob, n5Exporter.getN5FilePathSuffix());
return makeRemoteN5File(fileFormat, n5Exporter.getN5FileHash(), exportOutput, exportSpecs, newExportJob, n5Exporter.getN5BucketPath());
default:
throw new DataAccessException("Unknown export format requested");
}
Expand Down
25 changes: 13 additions & 12 deletions vcell-core/src/main/java/cbit/vcell/export/server/N5Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public class N5Exporter implements ExportConstants {

private ExportServiceImpl exportServiceImpl = null;

private DataServerImpl dataServer;
private final DataServerImpl dataServer;

private VCSimulationDataIdentifier vcDataID;
private final VCSimulationDataIdentifier vcDataID;
public String n5BucketName = "n5Data";

private User user;
private final User user;

public static final ArrayList<VariableType> unsupportedTypes = new ArrayList<>(Arrays.asList(
VariableType.MEMBRANE,
Expand Down Expand Up @@ -90,7 +90,7 @@ private ExportOutput exportToN5(OutputContext outputContext, long jobID, N5Specs
int[] blockSize = {sizeX, sizeY, 1, 1, 1};

// rewrite so that it still results in a tmp file does not raise File already exists error
N5FSWriter n5FSWriter = new N5FSWriter(getN5FileAbsolutePath(), new GsonBuilder());
N5FSWriter n5FSWriter = new N5FSWriter(getN5FileSystemPath(), new GsonBuilder());
DatasetAttributes datasetAttributes = new DatasetAttributes(dimensions, blockSize, org.janelia.saalfeldlab.n5.DataType.FLOAT64, n5Specs.getCompression());
n5FSWriter.createDataset(String.valueOf(jobID), datasetAttributes);

Expand Down Expand Up @@ -183,7 +183,7 @@ private ExportOutput exportToN5(OutputContext outputContext, long jobID, N5Specs
exportSpecs.getHumanReadableExportData().numChannels = (int) dimensions[2];
exportSpecs.getHumanReadableExportData().zSlices = (int) dimensions[3];
exportSpecs.getHumanReadableExportData().tSlices = (int) dimensions[4];
ExportOutput exportOutput = new ExportOutput(true, "." + N5Specs.n5Suffix, vcDataID.getID(), getN5FileNameHash(), fileDataContainerManager);
ExportOutput exportOutput = new ExportOutput(true, "." + N5Specs.n5Suffix, vcDataID.getID(), getN5FileHash(), fileDataContainerManager);
return exportOutput;
}

Expand Down Expand Up @@ -213,19 +213,20 @@ public DataIdentifier getSpecificDI(String diName, OutputContext outputContext)
return null;
}

public String getN5FileAbsolutePath(){
File outPutDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.n5DataDir) + "/" + getN5FilePathSuffix());
public String getN5FileSystemPath(){
File outPutDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.n5DataDir) + "/" + getN5BucketPath());
return outPutDir.getAbsolutePath();
}

public String getN5FilePathSuffix(){
return n5BucketName + "/" + user.getName() + "/" + this.getN5FileNameHash() + "." + N5Specs.n5Suffix;
public String getN5BucketPath(){
return n5BucketName + "/" + user.getName() + "/" + this.getN5FileHash() + "." + N5Specs.n5Suffix;
}

public String getN5FileNameHash(){
return actualHash(vcDataID.getDataKey().toString(), String.valueOf(vcDataID.getJobIndex()));
public String getN5FileHash(){
return hashFunction(vcDataID.getDataKey().toString());
}
private static String actualHash(String simID, String jobID) {

private static String hashFunction(String simID) {
MessageDigest sha256 = DigestUtils.getMd5Digest();
sha256.update(simID.getBytes(StandardCharsets.UTF_8));
String hashString = Hex.encodeHexString(sha256.digest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void makeN5FileWithSpecificSimulationResults(N5Specs.CompressionLevel com
if(n5Reader != null){
n5Reader.close();
}
this.n5Reader = new N5FSReader(n5Exporter.getN5FileAbsolutePath());
this.n5Reader = new N5FSReader(n5Exporter.getN5FileSystemPath());
}

private void setExportTestState(TestModels simModel) throws IOException, DataAccessException, MathException {
Expand Down

0 comments on commit 579eb5a

Please sign in to comment.