# HG changeset patch # User Sebastien Jodogne # Date 1779805329 -7200 # Node ID 4bd9dd9e3b9c8898bd276bd2477d3413fc5212f9 # Parent 634a8082ce0459257248ec79e41dff9732727735 replaced ThreadedInstancesLoader by DicomSequentialReader in ArchiveJob diff -r 634a8082ce04 -r 4bd9dd9e3b9c OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp --- a/OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp Tue May 26 15:52:35 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp Tue May 26 16:22:09 2026 +0200 @@ -192,7 +192,7 @@ IDicomTranscoder::DicomImage source; source.SetExternalBuffer(range->GetData(), range->GetSize()); - std::unique_ptr target; + std::unique_ptr target(new IDicomTranscoder::DicomImage); std::set allowedSyntaxes; allowedSyntaxes.insert(targetSyntax_); diff -r 634a8082ce04 -r 4bd9dd9e3b9c OrthancServer/Sources/ServerJobs/ArchiveJob.cpp --- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Tue May 26 15:52:35 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Tue May 26 16:22:09 2026 +0200 @@ -27,6 +27,7 @@ #include "../../../OrthancFramework/Sources/Cache/SharedArchive.h" #include "../../../OrthancFramework/Sources/Compression/HierarchicalZipWriter.h" #include "../../../OrthancFramework/Sources/Constants.h" +#include "../../../OrthancFramework/Sources/DataSource/DicomSequentialReader.h" #include "../../../OrthancFramework/Sources/DicomParsing/DicomDirWriter.h" #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" #include "../../../OrthancFramework/Sources/Logging.h" @@ -37,7 +38,6 @@ #include "../OrthancConfiguration.h" #include "../ServerContext.h" #include "../SimpleInstanceOrdering.h" -#include "ThreadedInstancesLoader.h" #include #include @@ -476,12 +476,12 @@ { } - virtual void Preload(ThreadedInstancesLoader& instancesLoader) const = 0; + virtual void Preload(DicomSequentialReader& instancesLoader) const = 0; // In the "archive" flavor (without DICOMDIR), dicomDir is NULL // In the "media" flavor (with DICOMDIR), dicomDir is not NULL virtual void Execute(HierarchicalZipWriter& writer, - ThreadedInstancesLoader& instancesLoader, + DicomSequentialReader& instancesLoader, DicomDirWriter* dicomDir) const = 0; }; @@ -500,12 +500,12 @@ { } - virtual void Preload(ThreadedInstancesLoader& instancesLoader) const ORTHANC_OVERRIDE + virtual void Preload(DicomSequentialReader& instancesLoader) const ORTHANC_OVERRIDE { } virtual void Execute(HierarchicalZipWriter& writer, - ThreadedInstancesLoader& instancesLoader, + DicomSequentialReader& instancesLoader, DicomDirWriter* dicomDir) const ORTHANC_OVERRIDE { writer.OpenDirectory(filename_); @@ -516,12 +516,12 @@ class CloseDirectoryCommand : public IZipCommand { public: - virtual void Preload(ThreadedInstancesLoader& instancesLoader) const ORTHANC_OVERRIDE + virtual void Preload(DicomSequentialReader& instancesLoader) const ORTHANC_OVERRIDE { } virtual void Execute(HierarchicalZipWriter& writer, - ThreadedInstancesLoader& instancesLoader, + DicomSequentialReader& instancesLoader, DicomDirWriter* dicomDir) const ORTHANC_OVERRIDE { writer.CloseDirectory(); @@ -551,36 +551,45 @@ dicomDirFolder == MEDIA_IMAGES_FOLDER); } - virtual void Preload(ThreadedInstancesLoader& instancesLoader) const ORTHANC_OVERRIDE + virtual void Preload(DicomSequentialReader& instancesLoader) const ORTHANC_OVERRIDE { - instancesLoader.PreloadDicomInstance(instanceId_, fileInfo_); + instancesLoader.Submit(fileInfo_); } virtual void Execute(HierarchicalZipWriter& writer, - ThreadedInstancesLoader& instancesLoader, + DicomSequentialReader& instancesLoader, DicomDirWriter* dicomDir) const ORTHANC_OVERRIDE { - std::string content; - - try + if (!instancesLoader.HasNext()) { - LOG(INFO) << "Adding instance " << instanceId_ << " in zip"; - instancesLoader.WaitDicomInstance(content, instanceId_); + throw OrthancException(ErrorCode_InternalError); } - catch (OrthancException& e) + else { - LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_; - return; - } + std::unique_ptr next; - writer.OpenFile(filename_); + std::string content; - writer.Write(content); + try + { + LOG(INFO) << "Adding instance " << instanceId_ << " in zip"; + next.reset(instancesLoader.Next()); + } + catch (OrthancException& e) + { + LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_; + return; + } - if (dicomDir != NULL) - { - std::unique_ptr parsed(new ParsedDicomFile(content)); - dicomDir->Add(dicomDirFolder_, filename_, *parsed); + next->SaveToMemoryBuffer(content); + + writer.OpenFile(filename_); + writer.Write(content); + + if (dicomDir != NULL) + { + dicomDir->Add(dicomDirFolder_, filename_, *next); + } } } }; @@ -932,7 +941,7 @@ return commands_.GetSize() + 1; } - void PreloadAllCommands(ThreadedInstancesLoader& instancesLoader) + void PreloadAllCommands(DicomSequentialReader& instancesLoader) { for (size_t i = 0; i < commands_.GetSize(); i++) { @@ -940,7 +949,7 @@ } } - void RunStep(ThreadedInstancesLoader& instancesLoader, + void RunStep(DicomSequentialReader& instancesLoader, size_t index) { if (index > commands_.GetSize()) @@ -1194,8 +1203,19 @@ instancesCount_ = writer_->GetInstancesCount(); uncompressedSize_ = writer_->GetUncompressedSize(); - instancesLoader_.reset(new ThreadedInstancesLoader(context_, loaderThreads_, transcode_, transferSyntax_, lossyQuality_, "ARCH")); + if (transcode_) + { + instancesLoader_.reset(context_.CreateTranscodedSequentialReader( + transferSyntax_, TranscodingSopInstanceUidMode_AllowNew, hasLossyQuality_, lossyQuality_)); + } + else + { + instancesLoader_.reset(context_.CreateDicomSequentialReader()); + } + writer_->PreloadAllCommands(*instancesLoader_); + + instancesLoader_->Start(); } } @@ -1235,10 +1255,7 @@ writer_.reset(); } - if (instancesLoader_.get() != NULL) - { - instancesLoader_->Clear(false); - } + instancesLoader_.reset(NULL); if (asynchronousTarget_.get() != NULL) { @@ -1307,10 +1324,7 @@ asynchronousTarget_.reset(); // clear the loader threads - if (instancesLoader_.get() != NULL) - { - instancesLoader_->Clear(true); - } + instancesLoader_.reset(NULL); } } diff -r 634a8082ce04 -r 4bd9dd9e3b9c OrthancServer/Sources/ServerJobs/ArchiveJob.h --- a/OrthancServer/Sources/ServerJobs/ArchiveJob.h Tue May 26 15:52:35 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.h Tue May 26 16:22:09 2026 +0200 @@ -33,9 +33,9 @@ namespace Orthanc { + class DicomSequentialReader; class ServerContext; - class ThreadedInstancesLoader; - + class ArchiveJob : public IJob { private: @@ -51,7 +51,7 @@ std::unique_ptr synchronousTarget_; // Only valid before "Start()" std::unique_ptr asynchronousTarget_; ServerContext& context_; - std::unique_ptr instancesLoader_; + std::unique_ptr instancesLoader_; boost::shared_ptr archive_; bool isMedia_; bool enableExtendedSopClass_;