Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp @ 4508:8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 11 Feb 2021 11:00:05 +0100 |
parents | b4c58795f3a8 |
children | a3c6678aa7b1 |
comparison
equal
deleted
inserted
replaced
4507:b4c58795f3a8 | 4508:8f9090b137f1 |
---|---|
189 while (reader->ReadNextFile(filename, content)) | 189 while (reader->ReadNextFile(filename, content)) |
190 { | 190 { |
191 if (!content.empty()) | 191 if (!content.empty()) |
192 { | 192 { |
193 LOG(INFO) << "Uploading DICOM file from ZIP archive: " << filename; | 193 LOG(INFO) << "Uploading DICOM file from ZIP archive: " << filename; |
194 | 194 |
195 DicomInstanceToStore toStore; | 195 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromBuffer(content)); |
196 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call)); | 196 toStore->SetOrigin(DicomInstanceOrigin::FromRest(call)); |
197 toStore.SetBuffer(content.c_str(), content.size()); | |
198 | 197 |
199 std::string publicId; | 198 std::string publicId; |
200 | 199 |
201 try | 200 try |
202 { | 201 { |
203 StoreStatus status = context.Store(publicId, toStore, StoreInstanceMode_Default); | 202 StoreStatus status = context.Store(publicId, *toStore, StoreInstanceMode_Default); |
204 | 203 |
205 Json::Value info; | 204 Json::Value info; |
206 SetupResourceAnswer(info, toStore, status, publicId); | 205 SetupResourceAnswer(info, *toStore, status, publicId); |
207 answer.append(info); | 206 answer.append(info); |
208 } | 207 } |
209 catch (OrthancException& e) | 208 catch (OrthancException& e) |
210 { | 209 { |
211 if (e.GetErrorCode() == ErrorCode_BadFileFormat) | 210 if (e.GetErrorCode() == ErrorCode_BadFileFormat) |
226 { | 225 { |
227 // The lifetime of "dicom" must be longer than "toStore", as the | 226 // The lifetime of "dicom" must be longer than "toStore", as the |
228 // latter can possibly store a reference to the former (*) | 227 // latter can possibly store a reference to the former (*) |
229 std::string dicom; | 228 std::string dicom; |
230 | 229 |
231 DicomInstanceToStore toStore; | 230 std::unique_ptr<DicomInstanceToStore> toStore; |
232 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call)); | |
233 | 231 |
234 if (boost::iequals(call.GetHttpHeader("content-encoding", ""), "gzip")) | 232 if (boost::iequals(call.GetHttpHeader("content-encoding", ""), "gzip")) |
235 { | 233 { |
236 GzipCompressor compressor; | 234 GzipCompressor compressor; |
237 compressor.Uncompress(dicom, call.GetBodyData(), call.GetBodySize()); | 235 compressor.Uncompress(dicom, call.GetBodyData(), call.GetBodySize()); |
238 toStore.SetBuffer(dicom.c_str(), dicom.size()); // (*) | 236 toStore.reset(DicomInstanceToStore::CreateFromBuffer(dicom)); // (*) |
239 } | 237 } |
240 else | 238 else |
241 { | 239 { |
242 toStore.SetBuffer(call.GetBodyData(), call.GetBodySize()); | 240 toStore.reset(DicomInstanceToStore::CreateFromBuffer(call.GetBodyData(), call.GetBodySize())); |
243 } | 241 } |
244 | 242 |
243 toStore->SetOrigin(DicomInstanceOrigin::FromRest(call)); | |
244 | |
245 std::string publicId; | 245 std::string publicId; |
246 StoreStatus status = context.Store(publicId, toStore, StoreInstanceMode_Default); | 246 StoreStatus status = context.Store(publicId, *toStore, StoreInstanceMode_Default); |
247 | 247 |
248 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status, publicId); | 248 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, *toStore, status, publicId); |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 | 252 |
253 | 253 |