comparison Framework/Oracle/GenericOracleRunner.cpp @ 1137:cc029987b6dc broker

improved cache key
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Nov 2019 20:27:20 +0100
parents 42581a6182c8
children 6333e6f7248e
comparison
equal deleted inserted replaced
1136:42581a6182c8 1137:cc029987b6dc
247 { 247 {
248 } 248 }
249 249
250 virtual void Handle(Orthanc::ParsedDicomFile* dicom, 250 virtual void Handle(Orthanc::ParsedDicomFile* dicom,
251 const ParseDicomFileCommand& command, 251 const ParseDicomFileCommand& command,
252 const std::string& path,
252 uint64_t fileSize) = 0; 253 uint64_t fileSize) = 0;
253 254
254 static void Apply(IDicomHandler& handler, 255 static void Apply(IDicomHandler& handler,
255 const std::string& root, 256 const std::string& path,
256 const ParseDicomFileCommand& command) 257 const ParseDicomFileCommand& command)
257 { 258 {
258 std::string path = GetPath(root, command.GetPath());
259
260 if (!Orthanc::SystemToolbox::IsRegularFile(path)) 259 if (!Orthanc::SystemToolbox::IsRegularFile(path))
261 { 260 {
262 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentFile); 261 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentFile);
263 } 262 }
264 263
296 295
297 printf("Reading %s\n", path.c_str()); 296 printf("Reading %s\n", path.c_str());
298 297
299 if (ok) 298 if (ok)
300 { 299 {
301 handler.Handle(new Orthanc::ParsedDicomFile(dicom), command, fileSize); 300 handler.Handle(new Orthanc::ParsedDicomFile(dicom), command, path, fileSize);
302 } 301 }
303 else 302 else
304 { 303 {
305 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, 304 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
306 "Cannot parse file: " + path); 305 "Cannot parse file: " + path);
323 { 322 {
324 } 323 }
325 324
326 virtual void Handle(Orthanc::ParsedDicomFile* dicom, 325 virtual void Handle(Orthanc::ParsedDicomFile* dicom,
327 const ParseDicomFileCommand& command, 326 const ParseDicomFileCommand& command,
327 const std::string& path,
328 uint64_t fileSize) 328 uint64_t fileSize)
329 { 329 {
330 std::auto_ptr<Orthanc::ParsedDicomFile> parsed(dicom); 330 std::auto_ptr<Orthanc::ParsedDicomFile> parsed(dicom);
331 331
332 ParseDicomFileCommand::SuccessMessage message 332 ParseDicomFileCommand::SuccessMessage message
357 } 357 }
358 } 358 }
359 359
360 virtual void Handle(Orthanc::ParsedDicomFile* dicom, 360 virtual void Handle(Orthanc::ParsedDicomFile* dicom,
361 const ParseDicomFileCommand& command, 361 const ParseDicomFileCommand& command,
362 const std::string& path,
362 uint64_t fileSize) 363 uint64_t fileSize)
363 { 364 {
364 std::auto_ptr<Orthanc::ParsedDicomFile> parsed(dicom); 365 std::auto_ptr<Orthanc::ParsedDicomFile> parsed(dicom);
365 366
366 { 367 {
369 emitter_.EmitMessage(receiver_, message); 370 emitter_.EmitMessage(receiver_, message);
370 } 371 }
371 372
372 // Store it into the cache for future use 373 // Store it into the cache for future use
373 assert(cache_); 374 assert(cache_);
374 cache_->Acquire(command.GetPath(), parsed.release(), 375 cache_->Acquire(path, parsed.release(),
375 static_cast<size_t>(fileSize), command.IsPixelDataIncluded()); 376 static_cast<size_t>(fileSize), command.IsPixelDataIncluded());
376 } 377 }
377 }; 378 };
378 } 379 }
379 380
382 IMessageEmitter& emitter, 383 IMessageEmitter& emitter,
383 boost::shared_ptr<ParsedDicomFileCache> cache, 384 boost::shared_ptr<ParsedDicomFileCache> cache,
384 const std::string& root, 385 const std::string& root,
385 const ParseDicomFileCommand& command) 386 const ParseDicomFileCommand& command)
386 { 387 {
388 const std::string path = GetPath(root, command.GetPath());
389
387 #if 1 390 #if 1
388 if (cache.get()) 391 if (cache.get())
389 { 392 {
390 { 393 {
391 ParsedDicomFileCache::Reader reader(*cache, command.GetPath()); 394 ParsedDicomFileCache::Reader reader(*cache, path);
392 if (reader.IsValid() && 395 if (reader.IsValid() &&
393 (!command.IsPixelDataIncluded() || 396 (!command.IsPixelDataIncluded() ||
394 reader.HasPixelData())) 397 reader.HasPixelData()))
395 { 398 {
396 // Reuse the DICOM file from the cache 399 // Reuse the DICOM file from the cache
400 return; 403 return;
401 } 404 }
402 } 405 }
403 406
404 DicomHandlerWithCache handler(receiver, emitter, cache); 407 DicomHandlerWithCache handler(receiver, emitter, cache);
405 IDicomHandler::Apply(handler, root, command); 408 IDicomHandler::Apply(handler, path, command);
406 } 409 }
407 else 410 else
408 { 411 {
409 // No cache available 412 // No cache available
410 DicomHandlerWithoutCache handler(receiver, emitter); 413 DicomHandlerWithoutCache handler(receiver, emitter);
411 IDicomHandler::Apply(handler, root, command); 414 IDicomHandler::Apply(handler, path, command);
412 } 415 }
413 #else 416 #else
414 DicomHandlerWithoutCache handler(receiver, emitter); 417 DicomHandlerWithoutCache handler(receiver, emitter);
415 IDicomHandler::Apply(handler, root, command); 418 IDicomHandler::Apply(handler, path, command);
416 #endif 419 #endif
417 } 420 }
418 421
419 #endif 422 #endif
420 423