comparison OrthancServer/ServerContext.cpp @ 3681:9dac85e807c2 storage-commitment

integration mainline->storage-commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 Feb 2020 20:36:47 +0100
parents d8371b4302ff 6358923d3ced
children 56f2397f027a
comparison
equal deleted inserted replaced
3675:340bdcc298e9 3681:9dac85e807c2
252 new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("MediaArchiveSize", 1))); 252 new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("MediaArchiveSize", 1)));
253 defaultLocalAet_ = lock.GetConfiguration().GetStringParameter("DicomAet", "ORTHANC"); 253 defaultLocalAet_ = lock.GetConfiguration().GetStringParameter("DicomAet", "ORTHANC");
254 jobsEngine_.SetWorkersCount(lock.GetConfiguration().GetUnsignedIntegerParameter("ConcurrentJobs", 2)); 254 jobsEngine_.SetWorkersCount(lock.GetConfiguration().GetUnsignedIntegerParameter("ConcurrentJobs", 2));
255 saveJobs_ = lock.GetConfiguration().GetBooleanParameter("SaveJobs", true); 255 saveJobs_ = lock.GetConfiguration().GetBooleanParameter("SaveJobs", true);
256 metricsRegistry_->SetEnabled(lock.GetConfiguration().GetBooleanParameter("MetricsEnabled", true)); 256 metricsRegistry_->SetEnabled(lock.GetConfiguration().GetBooleanParameter("MetricsEnabled", true));
257
258 // New configuration options in Orthanc 1.5.1
259 findStorageAccessMode_ = StringToFindStorageAccessMode(lock.GetConfiguration().GetStringParameter("StorageAccessOnFind", "Always"));
260 limitFindInstances_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0);
261 limitFindResults_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0);
257 } 262 }
258 263
259 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); 264 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200);
260 265
261 listeners_.push_back(ServerListener(luaListener_, "Lua")); 266 listeners_.push_back(ServerListener(luaListener_, "Lua"));
794 const DatabaseLookup& lookup, 799 const DatabaseLookup& lookup,
795 ResourceType queryLevel, 800 ResourceType queryLevel,
796 size_t since, 801 size_t since,
797 size_t limit) 802 size_t limit)
798 { 803 {
799 LookupMode mode; 804 unsigned int databaseLimit = (queryLevel == ResourceType_Instance ?
800 unsigned int databaseLimit; 805 limitFindInstances_ : limitFindResults_);
801 806
802 {
803 // New configuration option in 1.5.1
804 OrthancConfiguration::ReaderLock lock;
805
806 std::string value = lock.GetConfiguration().GetStringParameter("StorageAccessOnFind", "Always");
807
808 if (value == "Always")
809 {
810 mode = LookupMode_DiskOnLookupAndAnswer;
811 }
812 else if (value == "Never")
813 {
814 mode = LookupMode_DatabaseOnly;
815 }
816 else if (value == "Answers")
817 {
818 mode = LookupMode_DiskOnAnswer;
819 }
820 else
821 {
822 throw OrthancException(ErrorCode_ParameterOutOfRange,
823 "Configuration option \"StorageAccessOnFind\" "
824 "should be \"Always\", \"Never\" or \"Answers\": " + value);
825 }
826
827 if (queryLevel == ResourceType_Instance)
828 {
829 databaseLimit = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0);
830 }
831 else
832 {
833 databaseLimit = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0);
834 }
835 }
836
837 std::vector<std::string> resources, instances; 807 std::vector<std::string> resources, instances;
838 808
839 { 809 {
840 const size_t lookupLimit = (databaseLimit == 0 ? 0 : databaseLimit + 1); 810 const size_t lookupLimit = (databaseLimit == 0 ? 0 : databaseLimit + 1);
841 GetIndex().ApplyLookupResources(resources, &instances, lookup, queryLevel, lookupLimit); 811 GetIndex().ApplyLookupResources(resources, &instances, lookup, queryLevel, lookupLimit);
844 bool complete = (databaseLimit == 0 || 814 bool complete = (databaseLimit == 0 ||
845 resources.size() <= databaseLimit); 815 resources.size() <= databaseLimit);
846 816
847 LOG(INFO) << "Number of candidate resources after fast DB filtering on main DICOM tags: " << resources.size(); 817 LOG(INFO) << "Number of candidate resources after fast DB filtering on main DICOM tags: " << resources.size();
848 818
819 /**
820 * "resources" contains the Orthanc ID of the resource at level
821 * "queryLevel", "instances" contains one the Orthanc ID of one
822 * sample instance from this resource.
823 **/
849 assert(resources.size() == instances.size()); 824 assert(resources.size() == instances.size());
850 825
851 size_t countResults = 0; 826 size_t countResults = 0;
852 size_t skipped = 0; 827 size_t skipped = 0;
853 828
861 std::auto_ptr<Json::Value> dicomAsJson; 836 std::auto_ptr<Json::Value> dicomAsJson;
862 837
863 bool hasOnlyMainDicomTags; 838 bool hasOnlyMainDicomTags;
864 DicomMap dicom; 839 DicomMap dicom;
865 840
866 if (mode == LookupMode_DatabaseOnly || 841 if (findStorageAccessMode_ == FindStorageAccessMode_DatabaseOnly ||
867 mode == LookupMode_DiskOnAnswer || 842 findStorageAccessMode_ == FindStorageAccessMode_DiskOnAnswer ||
868 lookup.HasOnlyMainDicomTags()) 843 lookup.HasOnlyMainDicomTags())
869 { 844 {
870 // Case (1): The main DICOM tags, as stored in the database, 845 // Case (1): The main DICOM tags, as stored in the database,
871 // are sufficient to look for match 846 // are sufficient to look for match
872 847
873 if (!GetIndex().GetAllMainDicomTags(dicom, instances[i])) 848 DicomMap tmp;
849 if (!GetIndex().GetAllMainDicomTags(tmp, instances[i]))
874 { 850 {
875 // The instance has been removed during the execution of the 851 // The instance has been removed during the execution of the
876 // lookup, ignore it 852 // lookup, ignore it
877 continue; 853 continue;
878 } 854 }
855
856 #if 1
857 // New in Orthanc 1.6.0: Only keep the main DICOM tags at the
858 // level of interest for the query
859 switch (queryLevel)
860 {
861 // WARNING: Don't reorder cases below, and don't add "break"
862 case ResourceType_Instance:
863 dicom.MergeMainDicomTags(tmp, ResourceType_Instance);
864
865 case ResourceType_Series:
866 dicom.MergeMainDicomTags(tmp, ResourceType_Series);
867
868 case ResourceType_Study:
869 dicom.MergeMainDicomTags(tmp, ResourceType_Study);
870
871 case ResourceType_Patient:
872 dicom.MergeMainDicomTags(tmp, ResourceType_Patient);
873 break;
874
875 default:
876 throw OrthancException(ErrorCode_InternalError);
877 }
878
879 // Special case of the "Modality" at the study level, in order
880 // to deal with C-FIND on "ModalitiesInStudy" (0008,0061).
881 // Check out integration test "test_rest_modalities_in_study".
882 if (queryLevel == ResourceType_Study)
883 {
884 dicom.CopyTagIfExists(tmp, DICOM_TAG_MODALITY);
885 }
886 #else
887 dicom.Assign(tmp); // This emulates Orthanc <= 1.5.8
888 #endif
879 889
880 hasOnlyMainDicomTags = true; 890 hasOnlyMainDicomTags = true;
881 } 891 }
882 else 892 else
883 { 893 {
905 complete = false; 915 complete = false;
906 break; 916 break;
907 } 917 }
908 else 918 else
909 { 919 {
910 if ((mode == LookupMode_DiskOnLookupAndAnswer || 920 if ((findStorageAccessMode_ == FindStorageAccessMode_DiskOnLookupAndAnswer ||
911 mode == LookupMode_DiskOnAnswer) && 921 findStorageAccessMode_ == FindStorageAccessMode_DiskOnAnswer) &&
912 dicomAsJson.get() == NULL && 922 dicomAsJson.get() == NULL &&
913 isDicomAsJsonNeeded) 923 isDicomAsJsonNeeded)
914 { 924 {
915 dicomAsJson.reset(new Json::Value); 925 dicomAsJson.reset(new Json::Value);
916 ReadDicomAsJson(*dicomAsJson, instances[i]); 926 ReadDicomAsJson(*dicomAsJson, instances[i]);