ProteoWizard
MSDataCache.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2008 Spielberg Family Center for Applied Proteomics
8// Cedars-Sinai Medical Center, Los Angeles, California 90048
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
24#ifndef _MSDATACACHE_HPP_
25#define _MSDATACACHE_HPP_
26
27
30#include "MSDataAnalyzer.hpp"
31
32
33namespace pwiz {
34namespace analysis {
35
36
37using namespace msdata;
38
39
40///
41/// simple memory cache for common MSData info
42///
43/// Memory caching is useful to minimize data retrieval expenses:
44/// - disk I/O and decoding of binary data
45/// - indirection and pointer validation
46/// - parameter list searching
47/// - lexical casting
48///
49/// MSDataCache is a vector of SpectrumInfo objects, but also implements the
50/// MSDataAnalyzer interface. It can be used in two ways:
51/// 1) Updated from the outside via MSDataAnalyzer interface
52/// 2) Automatic updating via spectrumInfo() access method
53///
54/// Spectrum binary data (SpectrumInfo::data) is
55/// freed from the cache using a LRU (least recently used) algorithm.
56/// Binary data will be freed only to make room for a new update. The
57/// default cache size is 1, i.e. only the most recently updated binary
58/// data array is stored. Note that modifying the SpectrumInfo objects
59/// directly through the vector interface circumvents the LRU mechanism.
60///
61/// Usage #1: MSDataCache should be placed first in an
62/// MSDataAnalyzerContainer, so that it receives update() first. Other
63/// analyzers may then use it (preferably as const MSDataCache&) to access
64/// spectrum data when they receive update(). On updateRequested(),
65/// MSDataCache returns UpdateRequest_Ok to indicate that it should
66/// receive any updates that are requested by other analyzers. If no
67/// other analyzer requests an update, the cache will not be updated.
68///
69/// Usage #2: Instantiate independently and call open() to set reference to an
70/// MSData object. Calls to spectrumInfo() will return the requested SpectrumInfo,
71/// automatically updating the cache via call to SpectrumList::spectrum() if
72/// necessary.
73///
74class PWIZ_API_DECL MSDataCache : public std::vector<SpectrumInfo>,
75 public MSDataAnalyzer
76
77{
78 public:
79
80 /// MSDataCache configuration
82 {
84 Config(size_t cacheSize = 1) : binaryDataCacheSize(cacheSize) {}
85 };
86
87 MSDataCache(const Config& config = Config());
88
89 /// \name MSDataAnalyzer interface
90 //@{
91 virtual void open(const DataInfo& dataInfo);
92
93 virtual UpdateRequest updateRequested(const DataInfo& dataInfo,
94 const SpectrumIdentity& spectrumIdentity) const
95 {
96 // receive update() only if requested by another analyzer
97 return MSDataAnalyzer::UpdateRequest_Ok;
98 }
99
100 virtual void update(const DataInfo& dataInfo,
101 const Spectrum& spectrum);
102 //@}
103
104 /// access to SpectrumInfo with automatic update (open() must be called first)
105 const SpectrumInfo& spectrumInfo(size_t index, bool getBinaryData = false);
106
107 private:
108 struct Impl;
109 boost::shared_ptr<Impl> impl_;
112};
113
114
115} // namespace analysis
116} // namespace pwiz
117
118
119#endif // _MSDATACACHE_HPP_
120
#define PWIZ_API_DECL
Definition Export.hpp:32
Interface for MSData analyzers.
simple memory cache for common MSData info
virtual void open(const DataInfo &dataInfo)
start analysis of the data
boost::shared_ptr< Impl > impl_
MSDataCache(const Config &config=Config())
const SpectrumInfo & spectrumInfo(size_t index, bool getBinaryData=false)
access to SpectrumInfo with automatic update (open() must be called first)
MSDataCache & operator=(MSDataCache &)
virtual void update(const DataInfo &dataInfo, const Spectrum &spectrum)
analyze a single spectrum
virtual UpdateRequest updateRequested(const DataInfo &dataInfo, const SpectrumIdentity &spectrumIdentity) const
ask analyzer if it wants an update
information about the data to be analyzed
MSDataCache configuration.
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition MSData.hpp:506
Identifying information for a spectrum.
Definition MSData.hpp:471
simple structure for holding Spectrum info