comparison OrthancServer/Sources/ServerContext.cpp @ 5184:dd085f7e7e71

cleaning new constructors of StorageAccessor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 25 Mar 2023 12:20:34 +0100
parents 5ec3dcdf78b9
children 0ea402b4d901
comparison
equal deleted inserted replaced
5183:5ec3dcdf78b9 5184:dd085f7e7e71
518 518
519 519
520 void ServerContext::RemoveFile(const std::string& fileUuid, 520 void ServerContext::RemoveFile(const std::string& fileUuid,
521 FileContentType type) 521 FileContentType type)
522 { 522 {
523 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 523 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
524 accessor.Remove(fileUuid, type); 524 accessor.Remove(fileUuid, type);
525 } 525 }
526 526
527 527
528 ServerContext::StoreResult ServerContext::StoreAfterTranscoding(std::string& resultPublicId, 528 ServerContext::StoreResult ServerContext::StoreAfterTranscoding(std::string& resultPublicId,
564 DicomMap::GetAllMainDicomTags(allMainDicomTags); 564 DicomMap::GetAllMainDicomTags(allMainDicomTags);
565 565
566 try 566 try
567 { 567 {
568 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); 568 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms");
569 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 569 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
570 570
571 DicomInstanceHasher hasher(summary); 571 DicomInstanceHasher hasher(summary);
572 resultPublicId = hasher.HashInstance(); 572 resultPublicId = hasher.HashInstance();
573 573
574 Json::Value dicomAsJson; 574 Json::Value dicomAsJson;
878 { 878 {
879 throw OrthancException(ErrorCode_UnknownResource); 879 throw OrthancException(ErrorCode_UnknownResource);
880 } 880 }
881 else 881 else
882 { 882 {
883 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 883 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
884 accessor.AnswerFile(output, attachment, GetFileContentMime(content)); 884 accessor.AnswerFile(output, attachment, GetFileContentMime(content));
885 } 885 }
886 } 886 }
887 887
888 888
908 return; 908 return;
909 } 909 }
910 910
911 std::string content; 911 std::string content;
912 912
913 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 913 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
914 accessor.Read(content, attachment); 914 accessor.Read(content, attachment);
915 915
916 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), 916 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(),
917 content.size(), attachmentType, compression, storeMD5_); 917 content.size(), attachmentType, compression, storeMD5_);
918 918
964 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData)) 964 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData))
965 { 965 {
966 std::string dicom; 966 std::string dicom;
967 967
968 { 968 {
969 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 969 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
970 accessor.Read(dicom, attachment); 970 accessor.Read(dicom, attachment);
971 } 971 }
972 972
973 ParsedDicomFile parsed(dicom); 973 ParsedDicomFile parsed(dicom);
974 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength); 974 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength);
1030 **/ 1030 **/
1031 1031
1032 std::string dicom; 1032 std::string dicom;
1033 1033
1034 { 1034 {
1035 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 1035 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
1036 accessor.ReadStartRange(dicom, attachment.GetUuid(), FileContentType_Dicom, pixelDataOffset); 1036 accessor.ReadStartRange(dicom, attachment.GetUuid(), FileContentType_Dicom, pixelDataOffset);
1037 } 1037 }
1038 1038
1039 assert(dicom.size() == pixelDataOffset); 1039 assert(dicom.size() == pixelDataOffset);
1040 ParsedDicomFile parsed(dicom); 1040 ParsedDicomFile parsed(dicom);
1053 **/ 1053 **/
1054 1054
1055 std::string dicomAsJson; 1055 std::string dicomAsJson;
1056 1056
1057 { 1057 {
1058 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 1058 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
1059 accessor.Read(dicomAsJson, attachment); 1059 accessor.Read(dicomAsJson, attachment);
1060 } 1060 }
1061 1061
1062 if (!Toolbox::ReadJson(result, dicomAsJson)) 1062 if (!Toolbox::ReadJson(result, dicomAsJson))
1063 { 1063 {
1159 { 1159 {
1160 try 1160 try
1161 { 1161 {
1162 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s); 1162 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s);
1163 1163
1164 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 1164 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
1165 1165
1166 accessor.ReadStartRange(dicom, attachment.GetUuid(), attachment.GetContentType(), pixelDataOffset); 1166 accessor.ReadStartRange(dicom, attachment.GetUuid(), attachment.GetContentType(), pixelDataOffset);
1167 assert(dicom.size() == pixelDataOffset); 1167 assert(dicom.size() == pixelDataOffset);
1168 1168
1169 return true; // Success 1169 return true; // Success
1194 } 1194 }
1195 1195
1196 assert(attachment.GetContentType() == content); 1196 assert(attachment.GetContentType() == content);
1197 1197
1198 { 1198 {
1199 StorageCache* cache = NULL; 1199 std::unique_ptr<StorageAccessor> accessor;
1200 1200
1201 if (!skipCache) 1201 if (skipCache)
1202 { 1202 {
1203 cache = &storageCache_; 1203 accessor.reset(new StorageAccessor(area_, GetMetricsRegistry()));
1204 } 1204 }
1205 1205 else
1206 StorageAccessor accessor(area_, cache, GetMetricsRegistry()); 1206 {
1207 accessor.reset(new StorageAccessor(area_, storageCache_, GetMetricsRegistry()));
1208 }
1207 1209
1208 if (uncompressIfNeeded) 1210 if (uncompressIfNeeded)
1209 { 1211 {
1210 accessor.Read(result, attachment); 1212 accessor->Read(result, attachment);
1211 } 1213 }
1212 else 1214 else
1213 { 1215 {
1214 // Do not uncompress the content of the storage area, return the 1216 // Do not uncompress the content of the storage area, return the
1215 // raw data 1217 // raw data
1216 accessor.ReadRaw(result, attachment); 1218 accessor->ReadRaw(result, attachment);
1217 } 1219 }
1218 } 1220 }
1219 } 1221 }
1220 1222
1221 1223
1301 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; 1303 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId;
1302 1304
1303 // TODO Should we use "gzip" instead? 1305 // TODO Should we use "gzip" instead?
1304 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); 1306 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None);
1305 1307
1306 StorageAccessor accessor(area_, &storageCache_, GetMetricsRegistry()); 1308 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
1307 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_); 1309 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_);
1308 1310
1309 try 1311 try
1310 { 1312 {
1311 StoreStatus status = index_.AddAttachment( 1313 StoreStatus status = index_.AddAttachment(