private void AddChromCollector(int productFilterId, ChromCollector collector)
 {
     _collectors.AddCollector(productFilterId, collector);
 }
            /// <summary>
            /// Add key and collector for an SRM chromatogram.
            /// </summary>
            public void AddSrmCollector(ChromKey chromKey, ChromCollector collector)
            {
                // Not allowed to use this method in the async case
                Assume.IsFalse(IsRunningAsync);

                ChromKeys.Add(chromKey);
                // ReSharper disable once InconsistentlySynchronizedField
                _collectors.Add(collector);
            }
        public void ProcessExtractedSpectrum(float time, SpectraChromDataProvider.Collectors chromatograms, int scanId, ExtractedSpectrum spectrum, Action<int, ChromCollector> addCollector)
        {
            double precursorMz = spectrum.PrecursorMz;
            double? ionMobilityValue = spectrum.IonMobilityValue;
            double ionMobilityExtractionWidth = spectrum.IonMobilityExtractionWidth;
            string textId = spectrum.TextId;
            ChromExtractor extractor = spectrum.Extractor;
            int ionScanCount = spectrum.ProductFilters.Length;
            ChromDataCollector collector;
            var key = new PrecursorTextId(precursorMz, textId, extractor);
            int index = spectrum.FilterIndex;
            while (PrecursorCollectorMap.Count <= index)
                PrecursorCollectorMap.Add(null);
            if (PrecursorCollectorMap[index] != null)
                collector = PrecursorCollectorMap[index].Item2;
            else
            {
                collector = new ChromDataCollector(textId, precursorMz, ionMobilityValue, ionMobilityExtractionWidth, index, IsGroupedTime);
                PrecursorCollectorMap[index] = new Tuple<PrecursorTextId, ChromDataCollector>(key, collector);
            }

            int ionCount = collector.ProductIntensityMap.Count;
            if (ionCount == 0)
                ionCount = ionScanCount;

            // Add new time to the shared time list if not SRM, which doesn't share times, or
            // the times are shared with the entire set, as in MS1
            int lenTimes = collector.TimeCount;
            if (IsGroupedTime)
            {
                // Shared scan ids and times do not belong to a group.
                collector.AddScanId(scanId);
                collector.AddGroupedTime(time);
                lenTimes = collector.GroupedTimesCollector.Count;
            }

            // Add intensity values to ion scans

            for (int j = 0; j < ionScanCount; j++)
            {
                var productFilter = spectrum.ProductFilters[j];
                var chromIndex = chromatograms.ProductFilterIdToId(productFilter.FilterId);

                ChromCollector chromCollector;
                if (!collector.ProductIntensityMap.TryGetValue(productFilter, out chromCollector))
                {
                    chromCollector = new ChromCollector(chromIndex, IsSingleTime, spectrum.MassErrors != null);
                    // If more than a single ion scan, add any zeros necessary
                    // to make this new chromatogram have an entry for each time.
                    if (ionScanCount > 1 && lenTimes > 1)
                        chromCollector.FillIntensities(chromIndex, lenTimes - 1, _blockWriter);
                    collector.ProductIntensityMap.Add(productFilter, chromCollector);

                    if (addCollector != null)
                        addCollector(productFilter.FilterId, chromCollector);
                }
                if (IsSingleTime)
                    chromCollector.AddTime(chromIndex, time, _blockWriter);
                if (spectrum.MassErrors != null)
                    chromCollector.AddMassError(chromIndex, spectrum.MassErrors[j], _blockWriter);
                chromCollector.AddIntensity(chromIndex, spectrum.Intensities[j], _blockWriter);
            }

            // Add data for chromatogram graph.
            if (_allChromData != null && spectrum.PrecursorMz != 0) // Exclude TIC and BPC
                _allChromData.Add(spectrum.TextId, spectrum.PeptideColor, spectrum.FilterIndex, time, spectrum.Intensities);

            // If this was a multiple ion scan and not all ions had measurements,
            // make sure missing ions have zero intensities in the chromatogram.
            if (ionScanCount > 1 &&
                (ionCount != ionScanCount || ionCount != collector.ProductIntensityMap.Count))
            {
                // Times should have gotten one longer
                foreach (var item in collector.ProductIntensityMap)
                {
                    var productFilter = item.Key;
                    var chromCollector = item.Value;
                    var chromIndex = chromatograms.ProductFilterIdToId(productFilter.FilterId);
                    if (chromCollector.Count < lenTimes)
                        chromCollector.AddIntensity(chromIndex, 0, _blockWriter);
                }
            }
        }
 /// <summary>
 /// Add a collector for a non-SRM chromatogram.
 /// </summary>
 public void AddCollector(int productFilterId, ChromCollector collector)
 {
     lock (this)
     {
         int index = ProductFilterIdToId(productFilterId);
         _collectors[index] = collector;
     }
 }