changeset 6830:da03aa08b9aa streaming

removed ServerContext::ReadDicom()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 21 May 2026 09:49:09 +0200
parents 460330d630bc
children 616e673d1499
files OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/OrthancWebDav.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h OrthancServer/Sources/ServerJobs/Operations/DicomInstanceOperationValue.cpp
diffstat 6 files changed, 40 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- 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<const _OrthancPluginGetDicomForInstance*>(parameters);
 
-    std::string dicom;
+    std::unique_ptr<StorageAreaDataSource::Range> 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<DicomDataSource::Dicom> 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<StorageAreaDataSource::Range> 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<ParsedDicomFile> 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<DicomDataSource::Dicom> loaded(lock.GetContext().ReadParsedDicom(params.instanceId));
+          parsed.reset(loaded->Clone());
         }
 
         parsed->RemoveFromPixelData();
--- 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<StorageAreaDataSource::Range> raw(context.ReadRawDicom(publicId));
+      SystemToolbox::WriteFile(raw->GetData(), raw->GetSize(),
+                               SystemToolbox::PathFromUtf8(target), false /* don't automatically call fsync */);
+    }
 
     call.GetOutput().AnswerBuffer("{}", MimeType_Json);
   }
--- 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<StorageAreaDataSource::Range> 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<StorageAreaDataSource::Range> raw(context_.ReadRawDicom(instanceId));
+            raw->Copy(content);
+          }
+
           LookupTime(time, context_, instanceId, ResourceType_Instance, MetadataType_Instance_ReceptionDate);
           return true;
         }
--- 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<StorageAreaDataSource::Range> 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<StorageAreaDataSource::Range> raw(ReadRawDicom(instancePublicId));
+      raw->Copy(dicom);
     }
   }
 
--- 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);
 
--- 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<StorageAreaDataSource::Range> raw(context_.ReadRawDicom(id_));
+    raw->Copy(dicom);
   }
 }