# HG changeset patch # User Sebastien Jodogne # Date 1779990136 -7200 # Node ID aa4e5201fb9fc0ef819946b8b8718537e1d97d08 # Parent 42ca9122d0037ec71c9e80c82bf71e8cb7d6e5a5 using DicomSequentialReader in StoreJob diff -r 42ca9122d003 -r aa4e5201fb9f OrthancFramework/Sources/DataSource/DicomSequentialReader.cpp --- a/OrthancFramework/Sources/DataSource/DicomSequentialReader.cpp Thu May 28 18:24:26 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomSequentialReader.cpp Thu May 28 19:42:16 2026 +0200 @@ -156,7 +156,7 @@ case SourceType_StorageArea: { std::unique_ptr range(new StorageAreaDataSource::Range(protection.release())); - return new Item(range->GetBuffer()); + return new Item(range->GetBuffer()); // The buffer is shared through the cache } case SourceType_Dicom: diff -r 42ca9122d003 -r aa4e5201fb9f OrthancFramework/Sources/DataSource/DicomSequentialReader.h --- a/OrthancFramework/Sources/DataSource/DicomSequentialReader.h Thu May 28 18:24:26 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomSequentialReader.h Thu May 28 19:42:16 2026 +0200 @@ -55,6 +55,7 @@ ParsedDicomFile& GetParsedDicomFile(); + // There is a "const" here, as the value could be shared through the cache, so it cannot be modified const IMemoryBuffer& GetRawMemoryBuffer(); void SetUserData(IDynamicObject* userData /* takes ownership */); diff -r 42ca9122d003 -r aa4e5201fb9f OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp --- a/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp Thu May 28 18:24:26 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp Thu May 28 19:42:16 2026 +0200 @@ -48,19 +48,14 @@ assert(IsStarted()); OpenConnection(); - if (instancesLoader_.get() == NULL) - { - StartLoaderThreads(); - } - LOG(INFO) << "Sending instance " << instance << " to modality \"" << parameters_.GetRemoteModality().GetApplicationEntityTitle() << "\""; - std::string dicom; + std::unique_ptr item; try { - instancesLoader_->WaitDicomInstance(dicom, instance); + item.reset(WaitDicomInstance(instance)); } catch (OrthancException& e) { @@ -68,9 +63,10 @@ return false; } + const IMemoryBuffer& dicom = item->GetRawMemoryBuffer(); + std::string sopClassUid, sopInstanceUid; - context_.PerformCStoreWithTranscoding(sopClassUid, sopInstanceUid, *connection_, - dicom.empty() ? NULL : dicom.c_str(), dicom.size(), + context_.PerformCStoreWithTranscoding(sopClassUid, sopInstanceUid, *connection_, dicom.GetData(), dicom.GetSize(), HasMoveOriginator(), moveOriginatorAet_, moveOriginatorId_); if (storageCommitment_) diff -r 42ca9122d003 -r aa4e5201fb9f OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.h --- a/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.h Thu May 28 18:24:26 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.h Thu May 28 19:42:16 2026 +0200 @@ -56,11 +56,6 @@ virtual bool HandleTrailingStep() ORTHANC_OVERRIDE; - virtual const char* GetLoaderPrefix() const ORTHANC_OVERRIDE - { - return "CSTO"; - } - public: explicit DicomModalityStoreJob(ServerContext& context); diff -r 42ca9122d003 -r aa4e5201fb9f OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp --- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp Thu May 28 18:24:26 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp Thu May 28 19:42:16 2026 +0200 @@ -38,10 +38,7 @@ { bool OrthancPeerStoreJob::HandleInstance(const std::string& instance) { - if (instancesLoader_.get() == NULL) - { - StartLoaderThreads(); - } + assert(IsStarted()); if (client_.get() == NULL) { @@ -63,8 +60,10 @@ try { - std::string dicom; - instancesLoader_->WaitDicomInstance(dicom, instance); + std::unique_ptr item; + item.reset(WaitDicomInstance(instance)); + + const IMemoryBuffer& dicom = item->GetRawMemoryBuffer(); if (transcode_) { @@ -72,7 +71,7 @@ syntaxes.insert(transferSyntax_); IDicomTranscoder::DicomImage source, transcoded; - source.SetExternalBuffer(dicom); + source.SetExternalBuffer(dicom.GetData(), dicom.GetSize()); if (context_.GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew)) { @@ -81,12 +80,12 @@ } else { - body.swap(dicom); + dicom.CopyToString(body); } } else { - body.swap(dicom); + dicom.CopyToString(body); } } catch (OrthancException& e) diff -r 42ca9122d003 -r aa4e5201fb9f OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.h --- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.h Thu May 28 18:24:26 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.h Thu May 28 19:42:16 2026 +0200 @@ -49,11 +49,6 @@ virtual bool HandleTrailingStep() ORTHANC_OVERRIDE; - virtual const char* GetLoaderPrefix() const ORTHANC_OVERRIDE - { - return "PSTO"; - } - public: explicit OrthancPeerStoreJob(ServerContext& context) : StoreJob(context), diff -r 42ca9122d003 -r aa4e5201fb9f OrthancServer/Sources/ServerJobs/StoreJob.cpp --- a/OrthancServer/Sources/ServerJobs/StoreJob.cpp Thu May 28 18:24:26 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/StoreJob.cpp Thu May 28 19:42:16 2026 +0200 @@ -35,6 +35,24 @@ namespace Orthanc { + class StoreJob::ReaderUserData : public IDynamicObject + { + private: + std::string instanceId_; + + public: + ReaderUserData(const std::string& instanceId) : + instanceId_(instanceId) + { + } + + const std::string& GetInstanceId() const + { + return instanceId_; + } + }; + + StoreJob::StoreJob(ServerContext& context) : context_(context) { @@ -63,6 +81,51 @@ } + DicomSequentialReader::Item* StoreJob::WaitDicomInstance(const std::string& instanceId) + { + assert(IsStarted()); + + if (instancesLoader_.get() == NULL) + { + instancesLoader_.reset(context_.GetDicomSequentialReaderFactory().CreateForOriginalRawMemoryBuffer()); + + const size_t position = GetPosition(); // in case we reload a job in progress, we shall not preload the first instances + + if (instanceId != instancesIds_[position]) + { + throw OrthancException(ErrorCode_InternalError); + } + + for (size_t i = position; i < instancesIds_.size(); ++i) + { + instancesLoader_->Submit(filesInfo_[i], new ReaderUserData(instancesIds_[i])); + } + + instancesLoader_->Start(); + } + + if (!instancesLoader_->HasNext()) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + + std::unique_ptr next(instancesLoader_->Next()); + assert(next.get() != NULL && + next->HasUserData()); + + { + // This is just a sanity check, the class "MoveReaderUserData" could be removed + const ReaderUserData& userData = dynamic_cast(next->GetUserData()); + if (userData.GetInstanceId() != instanceId) + { + throw OrthancException(ErrorCode_InternalError); + } + } + + return next.release(); + } + + void StoreJob::AddInstances(const std::vector& instancesIds, const std::vector& filesInfo) { @@ -81,24 +144,6 @@ } } - - void StoreJob::StartLoaderThreads() - { - size_t loaderThreads = 1; - { - OrthancConfiguration::ReaderLock lock; - loaderThreads = lock.GetConfiguration().GetLoaderThreads(); - } - - instancesLoader_.reset(new ThreadedInstancesLoader(context_, loaderThreads, false, DicomTransferSyntax_LittleEndianImplicit /* dummy value not used*/, 0, GetLoaderPrefix())); - - size_t position = GetPosition(); // in case we reload a job in progress, we shall not preload the first instances - for (size_t i = position; i < instancesIds_.size(); ++i) - { - instancesLoader_->PreloadDicomInstance(instancesIds_[i], filesInfo_[i]); - } - } - void StoreJob::Stop(JobStopReason reason) { diff -r 42ca9122d003 -r aa4e5201fb9f OrthancServer/Sources/ServerJobs/StoreJob.h --- a/OrthancServer/Sources/ServerJobs/StoreJob.h Thu May 28 18:24:26 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/StoreJob.h Thu May 28 19:42:16 2026 +0200 @@ -24,27 +24,30 @@ #pragma once #include "../../../OrthancFramework/Sources/Compatibility.h" -#include "../../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h" +#include "../../../OrthancFramework/Sources/DataSource/DicomSequentialReader.h" #include "../../../OrthancFramework/Sources/FileStorage/FileInfo.h" -#include "ThreadedInstancesLoader.h" +#include "../../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h" #include namespace Orthanc { + class DicomSequentialReader; class ServerContext; class StoreJob : public SetOfInstancesJob { + private: + class ReaderUserData; + + std::unique_ptr instancesLoader_; + std::vector instancesIds_; + std::vector filesInfo_; + protected: - ServerContext& context_; - std::unique_ptr instancesLoader_; - std::vector instancesIds_; - std::vector filesInfo_; + ServerContext& context_; - virtual const char* GetLoaderPrefix() const = 0; - - void StartLoaderThreads(); + DicomSequentialReader::Item* WaitDicomInstance(const std::string& instanceId); public: explicit StoreJob(ServerContext& context);