changeset 236:6d9be2b470b4

compression
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 30 Nov 2012 15:09:16 +0100
parents 1e0595885a81
children 16a4ac70bd8a
files NEWS OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/main.cpp Resources/Configuration.json
diffstat 5 files changed, 43 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Nov 30 14:37:48 2012 +0100
+++ b/NEWS	Fri Nov 30 15:09:16 2012 +0100
@@ -4,12 +4,13 @@
 Major changes
 -------------
 
-* Full refactoring of the DB schema and of the REST API
-* Introduction of generic classes for REST APIs (in Core/RestApi)
+* Transparent compression of the DICOM instances on the disk
 * The patient/study/series/instances are now indexed by SHA-1 digests
   of their DICOM Instance IDs (and not by UUIDs anymore): The same
   DICOM objects are thus always identified by the same Orthanc IDs
 * Log of exported instances through DICOM C-Store SCU ("/exported" URI)
+* Full refactoring of the DB schema and of the REST API
+* Introduction of generic classes for REST APIs (in Core/RestApi)
 
 Minor changes
 -------------
--- a/OrthancServer/ServerContext.cpp	Fri Nov 30 14:37:48 2012 +0100
+++ b/OrthancServer/ServerContext.cpp	Fri Nov 30 15:09:16 2012 +0100
@@ -55,6 +55,16 @@
   {
   }
 
+  void ServerContext::SetCompressionEnabled(bool enabled)
+  {
+    if (enabled)
+      LOG(WARNING) << "Disk compression is enabled";
+    else
+      LOG(WARNING) << "Disk compression is disabled";
+
+    compressionEnabled_ = enabled;
+  }
+
   void ServerContext::RemoveFile(const std::string& fileUuid)
   {
     storage_.Remove(fileUuid);
@@ -66,7 +76,14 @@
                                    const Json::Value& dicomJson,
                                    const std::string& remoteAet)
   {
-    //accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
+    if (compressionEnabled_)
+    {
+      accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
+    }
+    else
+    {
+      accessor_.SetCompressionForNextOperations(CompressionType_None);
+    }      
 
     FileInfo dicomInfo = accessor_.Write(dicomFile, dicomSize, FileContentType_Dicom);
     FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_Json);
@@ -107,16 +124,14 @@
                                  FileContentType content)
   {
     FileInfo attachment;
-    if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_Dicom))
+    if (!index_.LookupAttachment(attachment, instancePublicId, content))
     {
-      assert(attachment.GetCompressionType() == CompressionType_None);
-      assert(attachment.GetContentType() == FileContentType_Dicom);
+      throw OrthancException(ErrorCode_InternalError);
+    }
 
-      FilesystemHttpSender sender(storage_, attachment.GetUuid());
-      sender.SetDownloadFilename(attachment.GetUuid() + ".dcm");
-      sender.SetContentType("application/dicom");
-      output.AnswerFile(sender);
-    }
+    accessor_.SetCompressionForNextOperations(attachment.GetCompressionType());
+    std::auto_ptr<HttpFileSender> sender(accessor_.ConstructHttpFileSender(attachment.GetUuid()));
+    output.AnswerFile(*sender);
   }
 
 
--- a/OrthancServer/ServerContext.h	Fri Nov 30 14:37:48 2012 +0100
+++ b/OrthancServer/ServerContext.h	Fri Nov 30 15:09:16 2012 +0100
@@ -50,6 +50,7 @@
     FileStorage storage_;
     ServerIndex index_;
     CompressedFileStorageAccessor accessor_;
+    bool compressionEnabled_;
 
   public:
     ServerContext(const boost::filesystem::path& path);
@@ -59,6 +60,13 @@
       return index_;
     }
 
+    void SetCompressionEnabled(bool enabled);
+
+    bool IsCompressionEnabled() const
+    {
+      return compressionEnabled_;
+    }
+
     void RemoveFile(const std::string& fileUuid);
 
     StoreStatus Store(const char* dicomFile,
--- a/OrthancServer/main.cpp	Fri Nov 30 14:37:48 2012 +0100
+++ b/OrthancServer/main.cpp	Fri Nov 30 15:09:16 2012 +0100
@@ -212,6 +212,8 @@
 
     boost::filesystem::path storageDirectory = GetGlobalStringParameter("StorageDirectory", "OrthancStorage");
     ServerContext context(storageDirectory);
+    context.SetCompressionEnabled(GetGlobalBoolParameter("StorageCompression", false));
+
     MyDicomStoreFactory storeScp(context);
 
     {
--- a/Resources/Configuration.json	Fri Nov 30 14:37:48 2012 +0100
+++ b/Resources/Configuration.json	Fri Nov 30 15:09:16 2012 +0100
@@ -3,12 +3,15 @@
      * General configuration of Orthanc
      **/
 
+    // The logical name of this instance of Orthanc. This one is
+    // displayed in Orthanc Explorer and at the URI "/system".
+    "Name" : "MyOrthanc",
+
     // Path to the directory that holds the database
     "StorageDirectory" : "OrthancStorage",
 
-    // The logical name of this instance of Orthanc. This one is
-    // displayed in Orthanc Explorer and at the URI "/system".
-    "Name" : "MyOrthanc",
+    // Enable the transparent compression of the DICOM instances
+    "StorageCompression" : false,