CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Static Private Member Functions | Private Attributes | Friends

DDValue Class Reference

#include <DDValue.h>

List of all members.

Public Member Functions

 DDValue (void)
 create a unnamed emtpy value. One can assing a named DDValue to it.
 DDValue (const std::string &)
 create a named empty value
 DDValue (const std::string &name, const std::string &val)
 DDValue (unsigned int)
 DDValue (const std::string &, const std::vector< DDValuePair > &)
 creates a named DDValue initialized with a std::vector of values
 DDValue (const char *)
 create a named empty value
 DDValue (const std::string &, double)
 creates a single double valued named DDValue. The corresponding std::string-value is an empty std::string
 DDValue (const std::string &, const std::string &, double)
const std::vector< double > & doubles () const
 a reference to the double-valued values stored in the given instance of DDValue
unsigned int id (void) const
 returns the ID of the DDValue
void init (const std::string &)
bool isEvaluated (void) const
 true, if values are numerical evaluated; else false.
const std::string & name (void) const
 the name of the DDValue
 operator unsigned int (void) const
 converts a DDValue object into its ID
bool operator< (const DDValue &) const
 A DDValue a is smaller than a DDValue b if (a.id()<b.id()) OR (a.id()==b.id() and value(a)<value(b))
bool operator== (const DDValue &v) const
 Two DDValues are equal only if their id() is equal AND their values are equal.
DDValuePair operator[] (unsigned int i) const
void setEvalState (bool newState)
 set to true, if the double-values (method DDValue::doubles()) make sense
unsigned int size () const
 the size of the stored value-pairs (std::string,double)
const std::vector< std::string > & strings () const
 a reference to the std::string-valued values stored in the given instance of DDValue
 ~DDValue (void)

Static Public Member Functions

static void clear (void)

Public Attributes

vecpair_typevecPair_

Private Types

typedef std::pair< bool,
std::pair< std::vector
< std::string >, std::vector
< double > > > 
vecpair_type

Static Private Member Functions

static std::map< std::string,
unsigned int > & 
indexer ()
static std::vector
< boost::shared_ptr
< vecpair_type > > & 
mem (vecpair_type *)
static std::vector< std::string > & names ()

Private Attributes

unsigned int id_

Friends

class DDLSpecPar
class DDSpecifics

Detailed Description

A DDValue std::maps a std::vector of DDValuePair (std::string,double) to a name. Names of DDValues are stored transiently. Furthermore, an ID is assigned std::mapping to the name. If a particular DDValue is not used anymore, use DDValue::clear() to free the internally allocated memory. Use DDValue::setEvalState(true) to indicate whether the double numbers stored in the DDValuePair make sense, otherwise an exception will be thrown when trying to get access to these values via DDValue::doubles() or DDValue::operator[].

Definition at line 25 of file DDValue.h.


Member Typedef Documentation

typedef std::pair<bool, std::pair<std::vector<std::string>, std::vector<double> > > DDValue::vecpair_type [private]

Definition at line 101 of file DDValue.h.


Constructor & Destructor Documentation

DDValue::DDValue ( void  ) [inline]

create a unnamed emtpy value. One can assing a named DDValue to it.

Definition at line 31 of file DDValue.h.

: id_(0), vecPair_(0) { }
DDValue::DDValue ( const std::string &  name)

create a named empty value

Definition at line 24 of file DDValue.cc.

References init().

 : id_( 0 ),
   vecPair_( 0 )
{
  init( name );
}
DDValue::DDValue ( const char *  name)

create a named empty value

Definition at line 31 of file DDValue.cc.

References init().

 : id_( 0 ),
   vecPair_( 0 )
{
  init( name );
}
DDValue::DDValue ( const std::string &  name,
const std::vector< DDValuePair > &  v 
) [explicit]

creates a named DDValue initialized with a std::vector of values

Definition at line 38 of file DDValue.cc.

References init(), mem(), and vecPair_.

 : id_( 0 )
{
  init( name );
  
  std::vector<DDValuePair>::const_iterator it = v.begin();
  std::vector<std::string> svec;
  std::vector<double> dvec;
  vecPair_ = new vecpair_type( false, std::make_pair( svec, dvec ));
  mem( vecPair_ );
  for(; it != v.end(); ++it )
  {
    vecPair_->second.first.push_back( it->first );
    vecPair_->second.second.push_back( it->second );
  }
}
DDValue::DDValue ( const std::string &  name,
double  val 
) [explicit]

creates a single double valued named DDValue. The corresponding std::string-value is an empty std::string

Definition at line 56 of file DDValue.cc.

References init(), mem(), setEvalState(), and vecPair_.

 : id_( 0 )
{
  init( name );
  
  std::vector<std::string> svec( 1, "" ); 
  std::vector<double> dvec( 1, val );
  
  vecPair_ =  new vecpair_type( false, std::make_pair( svec, dvec ));
  setEvalState( true );
  mem( vecPair_ );
}
DDValue::DDValue ( const std::string &  name,
const std::string &  sval,
double  dval 
) [explicit]

creates a single std::string & numerical-valued named DDValue.

Definition at line 69 of file DDValue.cc.

References init(), mem(), setEvalState(), and vecPair_.

 : id_( 0 )
{
  init( name );
  
  std::vector<std::string> svec( 1, sval );
  std::vector<double> dvec( 1, dval );
  vecPair_ = new vecpair_type( false, std::make_pair( svec, dvec ));
  setEvalState( true );
  mem( vecPair_ );
}
DDValue::DDValue ( const std::string &  name,
const std::string &  val 
) [explicit]

creates a single std::string-valued named DDValue

Definition at line 81 of file DDValue.cc.

References init(), mem(), setEvalState(), and vecPair_.

 : id_( 0 )
{
  init( name );
  
  std::vector<std::string> svec( 1, sval );
  std::vector<double> dvec( 1, 0 );
  vecPair_ = new vecpair_type( false, std::make_pair( svec, dvec ));
  setEvalState( false );
  mem( vecPair_ );
}
DDValue::DDValue ( unsigned int  i) [explicit]

Definition at line 93 of file DDValue.cc.

References i, id_, names(), and size().

 : id_( 0 ),
   vecPair_( 0 )
{
  if( names().size() - 1 <= i )
    id_ = i;
}
DDValue::~DDValue ( void  )

Definition at line 101 of file DDValue.cc.

{}

Member Function Documentation

void DDValue::clear ( void  ) [static]

Definition at line 105 of file DDValue.cc.

References mem(), and v.

{
  std::vector<boost::shared_ptr<vecpair_type> > & v = mem( 0 );
  v.clear();
}
const std::vector< double > & DDValue::doubles ( void  ) const
unsigned int DDValue::id ( void  ) const [inline]

returns the ID of the DDValue

Definition at line 58 of file DDValue.h.

References id_.

Referenced by DDI::LogicalPart::hasDDValue(), operator<(), and operator==().

{ return id_; }
std::map< std::string, unsigned int > & DDValue::indexer ( void  ) [static, private]

Definition at line 112 of file DDValue.cc.

Referenced by init().

{ 
  static std::map<std::string,unsigned int> indexer_;
  return indexer_;
}  
void DDValue::init ( const std::string &  name)

Definition at line 7 of file DDValue.cc.

References id_, indexer(), names(), query::result, and groupFilesInBlocks::temp.

Referenced by DDValue().

{
  unsigned int temp = indexer().size()+1;
  typedef std::map<std::string,unsigned int>::iterator itT;
  std::pair<itT,bool> result = indexer().insert( std::make_pair( name, temp ));
  
  if( result.second )
  {
    id_ = temp;
    names().push_back( name );
  }
  else
  {
    id_ = result.first->second;
  }  
}
bool DDValue::isEvaluated ( void  ) const

true, if values are numerical evaluated; else false.

in case of a 'true' return value, the method DDValue::doubles() and the operator DDValue::operator[] can be used

Definition at line 198 of file DDValue.cc.

References vecPair_.

Referenced by operator<<(), DDCoreToDDXMLOutput::specpar(), DDStreamer::specs_write(), and DDI::Specific::stream().

{
  return vecPair_->first;
}
std::vector< boost::shared_ptr< DDValue::vecpair_type > > & DDValue::mem ( DDValue::vecpair_type vp) [static, private]

Definition at line 126 of file DDValue.cc.

Referenced by clear(), and DDValue().

{
  static std::vector<boost::shared_ptr<vecpair_type> > memory_;
  memory_.push_back( boost::shared_ptr<vecpair_type>( vp ));
  return memory_;
}
const std::string& DDValue::name ( void  ) const [inline]

the name of the DDValue

Definition at line 64 of file DDValue.h.

References id_, and names().

Referenced by DDI::LogicalPart::addSpecifics(), operator<<(), DDCoreToDDXMLOutput::specpar(), DDStreamer::specs_write(), and DDI::Specific::stream().

{ return names()[id_]; }
std::vector< std::string > & DDValue::names ( void  ) [static, private]

Definition at line 119 of file DDValue.cc.

Referenced by DDValue(), doubles(), init(), name(), and operator[]().

{
  static std::vector<std::string> names_( 1 );
  return names_;
} 
DDValue::operator unsigned int ( void  ) const [inline]

converts a DDValue object into its ID

Definition at line 61 of file DDValue.h.

References id_.

{ return id_; }
bool DDValue::operator< ( const DDValue v) const

A DDValue a is smaller than a DDValue b if (a.id()<b.id()) OR (a.id()==b.id() and value(a)<value(b))

Definition at line 222 of file DDValue.cc.

References id(), query::result, and vecPair_.

{
  bool result( false );
  if( id() < v.id())
  { 
    result = true;
  }
  else
  {
    if( id() == v.id())
    {
      assert( vecPair_ );
      assert( v.vecPair_ );
      if( vecPair_->first && v.vecPair_->first ) { // numerical values
        result = ( vecPair_->second.second < v.vecPair_->second.second );
      }  
      else { // std::string values
        result = ( vecPair_->second.first < v.vecPair_->second.first );
      }
    }
  }
  return result;
}
bool DDValue::operator== ( const DDValue v) const

Two DDValues are equal only if their id() is equal AND their values are equal.

If the DDValue::isEvalued() == true, the numerical representation is taken for comparison, else the std::string representation

Definition at line 204 of file DDValue.cc.

References id(), query::result, and vecPair_.

{
  bool result( false );
  if( id() == v.id())
  { 
    assert( vecPair_ );
    assert( v.vecPair_ );
    if( vecPair_->first ) { // numerical values
      result = ( vecPair_->second.second == v.vecPair_->second.second );
    }  
    else { // std::string values
      result = ( vecPair_->second.first == v.vecPair_->second.first );
    }
  }
  return result;
}
DDValuePair DDValue::operator[] ( unsigned int  i) const

access to the values stored in DDValue by an index. Note, that the index is not checked for bounds excess!

Definition at line 177 of file DDValue.cc.

References Exception, id_, python::rootplot::argparse::message, names(), and vecPair_.

{ 
  if( vecPair_->first )
  {
    return DDValuePair( vecPair_->second.first[i], vecPair_->second.second[i] );
  }
  else
  {
    std::string message = "DDValue " + names()[id_] + " is not numerically evaluated! Use DDValue::std::strings()!";
    edm::LogError( "DDValue" ) << message;
    throw cms::Exception("DDException") << message;
  }
}
void DDValue::setEvalState ( bool  newState)

set to true, if the double-values (method DDValue::doubles()) make sense

Definition at line 192 of file DDValue.cc.

References vecPair_.

Referenced by DDValue(), DDLSpecPar::processElement(), and DDStreamer::specs_read().

{
  vecPair_->first = newState; 
}
unsigned int DDValue::size ( void  ) const [inline]

the size of the stored value-pairs (std::string,double)

Definition at line 78 of file DDValue.h.

References vecPair_.

Referenced by DDValue(), DDMapper< KeyType, ValueType >::noSpecifics(), operator<<(), DDCoreToDDXMLOutput::specpar(), DDStreamer::specs_write(), DDI::Specific::stream(), DDMapper< KeyType, ValueType >::toDouble(), and DDMapper< KeyType, ValueType >::toString().

                            { 
   return vecPair_ ? vecPair_->second.first.size() : 0 ; 
  } 
const std::vector<std::string>& DDValue::strings ( ) const [inline]

Friends And Related Function Documentation

friend class DDLSpecPar [friend]

Definition at line 28 of file DDValue.h.

friend class DDSpecifics [friend]

Definition at line 27 of file DDValue.h.


Member Data Documentation

unsigned int DDValue::id_ [private]

Definition at line 106 of file DDValue.h.

Referenced by DDValue(), doubles(), id(), init(), name(), operator unsigned int(), and operator[]().