changeset 6168:20e44205c260

merge
author Alain Mazy <am@orthanc.team>
date Wed, 11 Jun 2025 16:27:42 +0200
parents 2ab75e4e8c91 (current diff) ecd7fdc5f8d4 (diff)
children 1b3e041cd99b
files
diffstat 7 files changed, 65 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/ChunkedBuffer.cpp	Wed Jun 11 16:27:12 2025 +0200
+++ b/OrthancFramework/Sources/ChunkedBuffer.cpp	Wed Jun 11 16:27:42 2025 +0200
@@ -184,31 +184,58 @@
   {
     FlushPendingBuffer();
 
-    try
+    if (chunks_.empty())
+    {
+      if (numBytes_ != 0)
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
+
+      result.clear();
+    }
+    else if (chunks_.size() == 1)
     {
-      result.resize(numBytes_);
+      // Avoid reallocating a buffer if there is a single chunk
+      assert(chunks_.front() != NULL);
+      if (chunks_.front()->size() != numBytes_)
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
+      else
+      {
+        chunks_.front()->swap(result);
+        delete chunks_.front();
+      }
     }
-    catch (...)
+    else
     {
-      throw OrthancException(ErrorCode_NotEnoughMemory);
+      try
+      {
+        result.resize(numBytes_);
+      }
+      catch (...)
+      {
+        throw OrthancException(ErrorCode_NotEnoughMemory);
+      }
+
+      size_t pos = 0;
+      for (Chunks::iterator it = chunks_.begin();
+           it != chunks_.end(); ++it)
+      {
+        assert(*it != NULL);
+
+        size_t s = (*it)->size();
+        if (s != 0)
+        {
+          memcpy(&result[pos], (*it)->c_str(), s);
+          pos += s;
+        }
+
+        delete *it;
+      }
     }
 
-    size_t pos = 0;
-    for (Chunks::iterator it = chunks_.begin(); 
-         it != chunks_.end(); ++it)
-    {
-      assert(*it != NULL);
-
-      size_t s = (*it)->size();
-      if (s != 0)
-      {
-        memcpy(&result[pos], (*it)->c_str(), s);
-        pos += s;
-      }
-
-      delete *it;
-    }
-
+    // Reset the data structure
     chunks_.clear();
     numBytes_ = 0;
   }
--- a/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Wed Jun 11 16:27:12 2025 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Wed Jun 11 16:27:42 2025 +0200
@@ -31,7 +31,6 @@
 
 #include "../Compatibility.h"
 #include "../Endianness.h"
-#include "../Logging.h"
 #include "../OrthancException.h"
 #include "../Toolbox.h"
 #include "DicomArray.h"
@@ -1220,7 +1219,7 @@
   }
 
 
-  void DicomMap::LogMissingTagsForStore() const
+  std::string DicomMap::FormatMissingTagsForStore() const
   {
     std::string patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid;
     
@@ -1244,14 +1243,14 @@
       sopInstanceUid = ValueAsString(*this, DICOM_TAG_SOP_INSTANCE_UID);
     }
 
-    LogMissingTagsForStore(patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid);
+    return FormatMissingTagsForStore(patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid);
   }
 
   
-  void DicomMap::LogMissingTagsForStore(const std::string& patientId,
-                                        const std::string& studyInstanceUid,
-                                        const std::string& seriesInstanceUid,
-                                        const std::string& sopInstanceUid)
+  std::string DicomMap::FormatMissingTagsForStore(const std::string& patientId,
+                                                  const std::string& studyInstanceUid,
+                                                  const std::string& seriesInstanceUid,
+                                                  const std::string& sopInstanceUid)
   {
     std::string s, t;
 
@@ -1309,11 +1308,11 @@
 
     if (t.size() == 0)
     {
-      LOG(ERROR) << "Store has failed because all the required tags (" << s << ") are missing (is it a DICOMDIR file?)";
+      return "Store has failed because all the required tags (" + s + ") are missing (is it a DICOMDIR file?)";
     }
     else
     {
-      LOG(ERROR) << "Store has failed because required tags (" << s << ") are missing for the following instance: " << t;
+      return "Store has failed because required tags (" + s + ") are missing for the following instance: " + t;
     }
   }
 
--- a/OrthancFramework/Sources/DicomFormat/DicomMap.h	Wed Jun 11 16:27:12 2025 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomMap.h	Wed Jun 11 16:27:42 2025 +0200
@@ -171,12 +171,12 @@
                                           const void* dicom,
                                           size_t size);
 
-    void LogMissingTagsForStore() const;
+    std::string FormatMissingTagsForStore() const;
 
-    static void LogMissingTagsForStore(const std::string& patientId,
-                                       const std::string& studyInstanceUid,
-                                       const std::string& seriesInstanceUid,
-                                       const std::string& sopInstanceUid);
+    static std::string FormatMissingTagsForStore(const std::string& patientId,
+                                                 const std::string& studyInstanceUid,
+                                                 const std::string& seriesInstanceUid,
+                                                 const std::string& sopInstanceUid);
 
     bool LookupStringValue(std::string& result,
                            const DicomTag& tag,
--- a/OrthancFramework/Sources/DicomNetworking/Internals/StoreScp.cpp	Wed Jun 11 16:27:12 2025 +0200
+++ b/OrthancFramework/Sources/DicomNetworking/Internals/StoreScp.cpp	Wed Jun 11 16:27:42 2025 +0200
@@ -192,7 +192,7 @@
 
                   if (e.GetErrorCode() == ErrorCode_InexistentTag)
                   {
-                    FromDcmtkBridge::LogMissingTagsForStore(**imageDataSet);
+                    LOG(ERROR) << FromDcmtkBridge::FormatMissingTagsForStore(**imageDataSet);
                   }
                   else
                   {
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Wed Jun 11 16:27:12 2025 +0200
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Wed Jun 11 16:27:42 2025 +0200
@@ -3275,7 +3275,7 @@
   }
 
 
-  void FromDcmtkBridge::LogMissingTagsForStore(DcmDataset& dicom)
+  std::string FromDcmtkBridge::FormatMissingTagsForStore(DcmDataset& dicom)
   {
     std::string patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid;
 
@@ -3307,7 +3307,7 @@
       sopInstanceUid.assign(c);
     }
     
-    DicomMap::LogMissingTagsForStore(patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid);
+    return DicomMap::FormatMissingTagsForStore(patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid);
   }
 
 
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Wed Jun 11 16:27:12 2025 +0200
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Wed Jun 11 16:27:42 2025 +0200
@@ -280,7 +280,7 @@
     static bool LookupOrthancTransferSyntax(DicomTransferSyntax& target,
                                             DcmDataset& dicom);
 
-    static void LogMissingTagsForStore(DcmDataset& dicom);
+    static std::string FormatMissingTagsForStore(DcmDataset& dicom);
 
     static void RemovePath(DcmDataset& dataset,
                            const DicomPath& path);
--- a/OrthancServer/Sources/ServerContext.cpp	Wed Jun 11 16:27:12 2025 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Wed Jun 11 16:27:42 2025 +0200
@@ -846,7 +846,7 @@
     {
       if (e.GetErrorCode() == ErrorCode_InexistentTag)
       {
-        summary.LogMissingTagsForStore();
+        LOG(ERROR) << summary.FormatMissingTagsForStore();
       }
       
       throw;