# HG changeset patch # User Sebastien Jodogne # Date 1779349749 -7200 # Node ID da03aa08b9aa23d234e920930f232281b7ccafb5 # Parent 460330d630bc91eecffbeda734ea5cdd7bbaf268 removed ServerContext::ReadDicom() diff -r 460330d630bc -r da03aa08b9aa OrthancServer/Plugins/Engine/OrthancPlugins.cpp --- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Thu May 21 08:59:49 2026 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Thu May 21 09:49:09 2026 +0200 @@ -35,6 +35,8 @@ #include "../../../OrthancFramework/Sources/Compression/GzipCompressor.h" #include "../../../OrthancFramework/Sources/Compression/ZlibCompressor.h" +#include "../../../OrthancFramework/Sources/DataSource/DicomDataSource.h" +#include "../../../OrthancFramework/Sources/DataSource/StorageAreaDataSource.h" #include "../../../OrthancFramework/Sources/DicomFormat/DicomArray.h" #include "../../../OrthancFramework/Sources/DicomNetworking/DicomConnectionInfo.h" #include "../../../OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h" @@ -3543,14 +3545,14 @@ const _OrthancPluginGetDicomForInstance& p = *reinterpret_cast(parameters); - std::string dicom; + std::unique_ptr raw; { PImpl::ServerContextReference lock(*pimpl_); - lock.GetContext().ReadDicom(dicom, p.instanceId); - } - - CopyToMemoryBuffer(p.target, dicom); + raw.reset(lock.GetContext().ReadRawDicom(p.instanceId)); + } + + CopyToMemoryBuffer(p.target, raw->GetData(), raw->GetSize()); } static void ThrowOnHttpError(HttpStatus httpStatus) @@ -4697,14 +4699,11 @@ throw OrthancException(ErrorCode_NullPointer); } - std::string content; - { PImpl::ServerContextReference lock(*pimpl_); - lock.GetContext().ReadDicom(content, p.instanceId); - } - - dicom.reset(new ParsedDicomFile(content)); + std::unique_ptr loaded(lock.GetContext().ReadParsedDicom(p.instanceId)); + dicom.reset(loaded->Clone()); + } } Json::Value json; @@ -5125,14 +5124,14 @@ { case OrthancPluginLoadDicomInstanceMode_WholeDicom: { - std::string buffer; + std::unique_ptr raw; { PImpl::ServerContextReference lock(*pimpl_); - lock.GetContext().ReadDicom(buffer, params.instanceId); - } - - target.reset(new DicomInstanceFromBuffer(buffer)); + raw.reset(lock.GetContext().ReadRawDicom(params.instanceId)); + } + + target.reset(new DicomInstanceFromBuffer(raw->GetData(), raw->GetSize())); break; } @@ -5142,17 +5141,9 @@ std::unique_ptr parsed; { - std::string buffer; - - { - PImpl::ServerContextReference lock(*pimpl_); - if (!lock.GetContext().ReadDicomUntilPixelData(buffer, params.instanceId)) - { - lock.GetContext().ReadDicom(buffer, params.instanceId); - } - } - - parsed.reset(new ParsedDicomFile(buffer)); + PImpl::ServerContextReference lock(*pimpl_); + std::unique_ptr loaded(lock.GetContext().ReadParsedDicom(params.instanceId)); + parsed.reset(loaded->Clone()); } parsed->RemoveFromPixelData(); diff -r 460330d630bc -r da03aa08b9aa OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Thu May 21 08:59:49 2026 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Thu May 21 09:49:09 2026 +0200 @@ -487,12 +487,14 @@ std::string publicId = call.GetUriComponent("id", ""); - std::string dicom; - context.ReadDicom(dicom, publicId); - std::string target; call.BodyToString(target); - SystemToolbox::WriteFile(dicom, SystemToolbox::PathFromUtf8(target)); + + { + std::unique_ptr raw(context.ReadRawDicom(publicId)); + SystemToolbox::WriteFile(raw->GetData(), raw->GetSize(), + SystemToolbox::PathFromUtf8(target), false /* don't automatically call fsync */); + } call.GetOutput().AnswerBuffer("{}", MimeType_Json); } diff -r 460330d630bc -r da03aa08b9aa OrthancServer/Sources/OrthancWebDav.cpp --- a/OrthancServer/Sources/OrthancWebDav.cpp Thu May 21 08:59:49 2026 +0200 +++ b/OrthancServer/Sources/OrthancWebDav.cpp Thu May 21 09:49:09 2026 +0200 @@ -226,7 +226,11 @@ time_ = GetNow(); } - context_.ReadDicom(target_, resource.GetIdentifier()); + { + std::unique_ptr raw(context_.ReadRawDicom(resource.GetIdentifier())); + raw->Copy(target_); + } + success_ = true; } } @@ -482,7 +486,12 @@ try { mime = MimeType_Dicom; - context_.ReadDicom(content, instanceId); + + { + std::unique_ptr raw(context_.ReadRawDicom(instanceId)); + raw->Copy(content); + } + LookupTime(time, context_, instanceId, ResourceType_Instance, MetadataType_Instance_ReceptionDate); return true; } diff -r 460330d630bc -r da03aa08b9aa OrthancServer/Sources/ServerContext.cpp --- a/OrthancServer/Sources/ServerContext.cpp Thu May 21 08:59:49 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Thu May 21 09:49:09 2026 +0200 @@ -1452,30 +1452,6 @@ } - void ServerContext::ReadDicom(std::string& dicom, - const std::string& instancePublicId) - { - FileInfo attachment; - int64_t revision; - - if (!index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_Dicom)) - { - throw OrthancException(ErrorCode_InternalError, - "Unable to read attachment " + EnumerationToString(FileContentType_Dicom) + - " of instance " + instancePublicId); - } - - assert(attachment.GetContentType() == FileContentType_Dicom); - - std::unique_ptr range( - StorageAreaDataSource::ReadAttachment( - *storageAreaReader_, attachment, true /* uncompress */, checkMD5_)); - - assert(range->GetSize() == attachment.GetUncompressedSize()); - range->Copy(dicom); - } - - FileInfo ServerContext::LookupDicomForInstance(const std::string& instancePublicId) { FileInfo attachment; @@ -1512,7 +1488,8 @@ { if (!ReadDicomUntilPixelData(dicom, instancePublicId)) { - ReadDicom(dicom, instancePublicId); + std::unique_ptr raw(ReadRawDicom(instancePublicId)); + raw->Copy(dicom); } } diff -r 460330d630bc -r da03aa08b9aa OrthancServer/Sources/ServerContext.h --- a/OrthancServer/Sources/ServerContext.h Thu May 21 08:59:49 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.h Thu May 21 09:49:09 2026 +0200 @@ -382,15 +382,13 @@ void ReadDicomAsJson(Json::Value& result, const std::string& instancePublicId); // TODO-FIND: Can this be removed? - void ReadDicom(std::string& dicom, - const std::string& instancePublicId); // TODO-Streaming : Remove - FileInfo LookupDicomForInstance(const std::string& instancePublicId); StorageAreaDataSource::Range* ReadRawDicom(const std::string& instancePublicId); DicomDataSource::Dicom* ReadParsedDicom(const std::string& instancePublicId); + // TODO-Streaming : Remove void ReadDicomForHeader(std::string& dicom, const std::string& instancePublicId); diff -r 460330d630bc -r da03aa08b9aa OrthancServer/Sources/ServerJobs/Operations/DicomInstanceOperationValue.cpp --- a/OrthancServer/Sources/ServerJobs/Operations/DicomInstanceOperationValue.cpp Thu May 21 08:59:49 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/Operations/DicomInstanceOperationValue.cpp Thu May 21 09:49:09 2026 +0200 @@ -30,6 +30,7 @@ { void DicomInstanceOperationValue::ReadDicom(std::string& dicom) const { - context_.ReadDicom(dicom, id_); + std::unique_ptr raw(context_.ReadRawDicom(id_)); + raw->Copy(dicom); } }