When you request a calibration file, the first step is to select all calibration files of a given type (for instance, all darks, or all wavelength calibrations). Once it has that list, it has to restrict to a subset of applicable calibration files. This happens based on FITS keywords, as follows:
That selection yields a set of calibration files of the appropriate type (for instance, all H-band spectral wavelength calibrations).
Because the instrument configuration or detector properties can change significantly whenever you warm up the IFS, by default we then restrict our consideration to only calibration files taken from the same cooldown run as the science data. That is, any calibration files from before the start of that cooldown or after the start of the next cooldown will not be considered. The list of cooldowns is maintained in a file in the pipeline configuration directory.
Then from the subset of available files, you have to select the best one. The logic for that is as follows:
This is kind of convoluted but in practice should do a fairly robust job of automatically identifying the most appropriate calibration file in almost all circumstances. And remember, users can always manually select calibration files as well.