~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/FORMAT/HANDLERS/AcqusHandler.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
//                    Flex series file support
6
 
// --------------------------------------------------------------------------
7
 
//  Copyright (C) 2009 -- Guillaume Belz (guillaume.belz@chu-lyon.fr)
8
 
//
9
 
//  This library is free software; you can redistribute it and/or
10
 
//  modify it under the terms of the GNU Lesser General Public
11
 
//  License as published by the Free Software Foundation; either
12
 
//  version 2.1 of the License, or (at your option) any later version.
13
 
//
14
 
//  This library is distributed in the hope that it will be useful,
15
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
//  Lesser General Public License for more details.
18
 
//
19
 
//  You should have received a copy of the GNU Lesser General Public
20
 
//  License along with this library; if not, write to the Free Software
21
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
1
// --------------------------------------------------------------------------
 
2
//                   OpenMS -- Open-Source Mass Spectrometry
 
3
// --------------------------------------------------------------------------
 
4
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
 
5
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
 
6
//
 
7
// This software is released under a three-clause BSD license:
 
8
//  * Redistributions of source code must retain the above copyright
 
9
//    notice, this list of conditions and the following disclaimer.
 
10
//  * Redistributions in binary form must reproduce the above copyright
 
11
//    notice, this list of conditions and the following disclaimer in the
 
12
//    documentation and/or other materials provided with the distribution.
 
13
//  * Neither the name of any author or any participating institution
 
14
//    may be used to endorse or promote products derived from this software
 
15
//    without specific prior written permission.
 
16
// For a full list of authors, refer to the file AUTHORS.
 
17
// --------------------------------------------------------------------------
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
 
22
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
27
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
28
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
29
//
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Guillaume Belz$
34
41
 
35
42
namespace OpenMS
36
43
{
37
 
        namespace Internal
38
 
        {
39
 
        
40
 
    AcqusHandler::AcqusHandler(const String& filename)
41
 
    {  
 
44
  namespace Internal
 
45
  {
 
46
 
 
47
    AcqusHandler::AcqusHandler(const String & filename)
 
48
    {
42
49
      params_.clear();
43
 
      
 
50
 
44
51
      std::ifstream is(filename.c_str());
45
52
      if (!is)
46
53
      {
47
54
        throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename);
48
55
      }
49
 
      
 
56
 
50
57
      //temporary variables
51
58
      String line;
52
59
      std::vector<String> strings(2);
54
61
      //read lines
55
62
      while (getline(is, line, '\n'))
56
63
      {
57
 
        if (line.size() < 5) continue; // minimal string = "##x=x"
58
 
        if (line.prefix(2) != String("##")) continue; 
59
 
      
 
64
        if (line.size() < 5)
 
65
          continue;                    // minimal string = "##x=x"
 
66
        if (line.prefix(2) != String("##"))
 
67
          continue;
 
68
 
60
69
        if (line.split('=', strings))
61
 
        {       
 
70
        {
62
71
          if (strings.size() == 2)
63
72
          {
64
73
            params_[strings[0].substr(2)] = strings[1].trim();
65
74
          }
66
 
        }      
 
75
        }
67
76
      }
68
 
     
 
77
 
69
78
      // TOF calibration params
70
79
      dw_ = params_[String("$DW")].toDouble();
71
80
      delay_ = (Size)params_[String("$DELAY")].toInt();
74
83
      ml3_ = params_[String("$ML3")].toDouble();
75
84
      td_ = (Size) params_[String("$TD")].toInt();
76
85
 
77
 
      is.close();       
 
86
      is.close();
78
87
    }
79
 
    
 
88
 
80
89
    AcqusHandler::~AcqusHandler()
81
90
    {
82
91
      params_.clear();
86
95
    {
87
96
      return td_;
88
97
    }
89
 
        
 
98
 
90
99
    DoubleReal AcqusHandler::getPosition(const Size index)
91
100
    {
92
101
      DoubleReal sqrt_mz_;
93
102
      DoubleReal tof_ = dw_ * index + delay_;
94
103
      DoubleReal a_ = ml3_;
95
 
      DoubleReal b_ = sqrt(1000000000000.0/ml1_);
 
104
      DoubleReal b_ = sqrt(1000000000000.0 / ml1_);
96
105
      DoubleReal c_ = ml2_ - tof_;
97
 
      
98
 
      if(ml3_== 0.0)
99
 
                        {
 
106
 
 
107
      if (ml3_ == 0.0)
 
108
      {
100
109
        sqrt_mz_ = c_ / b_;
101
 
                        }
 
110
      }
102
111
      else
103
 
                        {
 
112
      {
104
113
        sqrt_mz_ = (sqrt(b_ * b_ - 4 * a_ * c_) - b_) / (2 * a_);
105
 
                        }
106
 
      return sqrt_mz_* sqrt_mz_;
 
114
      }
 
115
      return sqrt_mz_ * sqrt_mz_;
107
116
    }
108
117
 
109
 
    String AcqusHandler::getParam(const String& param)
 
118
    String AcqusHandler::getParam(const String & param)
110
119
    {
111
120
      if (param == String("mzMax"))
112
 
                        {
 
121
      {
113
122
        return String(getPosition(td_ - 1));
114
 
                        }
 
123
      }
115
124
      else if (param == String("mzMin"))
116
 
                        {
 
125
      {
117
126
        return String(getPosition(0));
118
 
                        }
 
127
      }
119
128
      return params_[param];
120
129
    }
121
130
 
122
 
        } // namespace Internal
 
131
  }   // namespace Internal
123
132
} // namespace OpenMS
124