Segmented electromagnetic calorimeters are used to determine both the total energy and direction (momentum components) of charged particles and photons. A trade off is involved in selecting the degree of segmentation of the calorimeter as the spatial and energy resolutions are affected differently. Increased number of individual detectors reduces accidental particle pile-up per detector but introduces complications related to ADC pedestals and pedestal variations, exacerbates the effects of electronic noise and ground loops, and requires summing and discrimination of multiple analog signals. Moreover, electromagnetic showers initiated by individual ionizing particles spread over several detectors. This complicates the precise gain-matching of the detector elements which requires an iterative procedure. The PIBETA calorimeter is a 240-module pure CsI non-magnetic detector optimized for detection of photons and electrons in the energy range 5-100 MeV. We present the computer-controlled, automatic, in situ gain-matching procedure that we developed and used routinely in several rare pion and muon decay experiments with the PIBETA detector.