AmpTools
AmpParameter.cc
Go to the documentation of this file.
1 //******************************************************************************
2 // This file is part of AmpTools, a package for performing Amplitude Analysis
3 //
4 // Copyright Trustees of Indiana University 2010, all rights reserved
5 //
6 // This software written by Matthew Shepherd, Ryan Mitchell, and
7 // Hrayr Matevosyan at Indiana University, Bloomington
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
11 // are met:
12 // 1. Redistributions of source code must retain the above copyright
13 // notice and author attribution, this list of conditions and the
14 // following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright
16 // notice and author attribution, this list of conditions and the
17 // following disclaimer in the documentation and/or other materials
18 // provided with the distribution.
19 // 3. Neither the name of the University nor the names of its contributors
20 // may be used to endorse or promote products derived from this software
21 // without specific prior written permission.
22 //
23 // Creation of derivative forms of this software for commercial
24 // utilization may be subject to restriction; written permission may be
25 // obtained from the Trustees of Indiana University.
26 //
27 // INDIANA UNIVERSITY AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES,
28 // EXPRESS OR IMPLIED. By way of example, but not limitation, INDIANA
29 // UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCANTABILITY OR
30 // FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS SOFTWARE OR
31 // DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS,
32 // OR OTHER RIGHTS. Neither Indiana University nor the authors shall be
33 // held liable for any liability with respect to any claim by the user or
34 // any other party arising from use of the program.
35 //******************************************************************************
36 
37 #include <cassert>
38 #include <iostream>
39 #include <string.h>
40 #include <stdlib.h>
41 
43 
44 AmpParameter::AmpParameter( const string& arg ) :
45 m_valPtr( &m_defaultValue ),
46 m_defaultValue( 1E9 ),
47 m_name("-"),
48 m_hasExternalPtr( false )
49 {
50  int length = arg.size();
51  assert( length >= 1 );
52 
53  if( strncmp( &(arg[0]), "[", 1 ) == 0 ){
54 
55  if( strncmp( &(arg[length-1]), "]", 1 ) != 0 ){
56 
57  cerr << "ERROR in AmpParameter argument: " << arg << endl;
58  assert( false );
59  }
60 
61  int nameLength = length - 2;
62  m_name = arg.substr( 1, nameLength );
63  }
64  else{
65 
66  m_defaultValue = atof( arg.c_str() );
67  }
68 }
69 
71 m_defaultValue( ampPar ),
72 m_name( ampPar.name() ) {
73 
74  if( ampPar.hasExternalPtr() ){
75 
76  m_valPtr = ampPar.valPtr();
77  m_hasExternalPtr = true;
78  }
79  else{
80 
81  m_valPtr = &m_defaultValue;
82  m_hasExternalPtr = false;
83  }
84 }
85 
86 
89  m_defaultValue = ampPar;
90  m_name = ampPar.name();
91 
92  if( ampPar.hasExternalPtr() ){
93 
94  m_valPtr = ampPar.valPtr();
95  m_hasExternalPtr = true;
96  }
97  else{
98 
99  m_valPtr = &m_defaultValue;
100  m_hasExternalPtr = false;
101  }
102 
103  return *this;
104 }
105 
106 
107 bool
108 AmpParameter::operator==( const AmpParameter& otherPar ) const {
109 
110  if( otherPar.name() != m_name ) return false;
111 
112  if( hasExternalPtr() && otherPar.hasExternalPtr() ){
113 
114  return( m_valPtr == otherPar.valPtr() );
115  }
116 
117  if( !hasExternalPtr() && !otherPar.hasExternalPtr() ){
118 
119  return( (*m_valPtr) == otherPar );
120  }
121 
122  // if we get here one parameter has an external pointer and the
123  // other one doesn't -- return false
124 
125  return false;
126 }
127 
128 void
129 AmpParameter::setExternalValue( const double* ptr ){
130 
131  m_valPtr = ptr;
132  m_hasExternalPtr = true;
133 }
134 
135 void
137 
138  m_defaultValue = val;
139  m_valPtr = &m_defaultValue;
140  m_hasExternalPtr = false;
141 }
string name() const
Definition: AmpParameter.h:94
void setExternalValue(const double *ptr)
bool hasExternalPtr() const
Definition: AmpParameter.h:111
AmpParameter & operator=(const AmpParameter &ampPar)
Definition: AmpParameter.cc:88
bool operator==(const AmpParameter &otherPar) const
void setValue(double val)
const double * valPtr() const
Definition: AmpParameter.h:116