CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

DDLVector Class Reference

DDLVector handles Rotation and ReflectionRotation elements. More...

#include <DDLVector.h>

Inheritance diagram for DDLVector:
DDXMLElement

List of all members.

Public Member Functions

void clearall ()
 DDLVector (DDLElementRegistry *myreg)
ReadMapType< std::vector
< std::string > > & 
getMapOfStrVectors ()
ReadMapType< std::vector
< double > > & 
getMapOfVectors ()
void preProcessElement (const std::string &name, const std::string &nmspace, DDCompactView &cpv)
 Called by loadAttributes AFTER attributes are loaded.
void processElement (const std::string &name, const std::string &nmspace, DDCompactView &cpv)
 Processing the element.
 ~DDLVector ()

Private Member Functions

void do_makeDouble (char const *str, char const *end)
void do_makeString (char const *str, char const *end)
void errorOut (const char *str) const
bool parse_numbers (char const *str) const
bool parse_strings (char const *str) const

Private Attributes

std::string pNameSpace
ReadMapType< std::vector
< std::string > > 
pStrVecMap
std::vector< std::string > pStrVector
ReadMapType< std::vector
< double > > 
pVecMap
std::vector< double > pVector

Friends

class VectorMakeDouble
class VectorMakeString

Detailed Description

DDLVector handles Rotation and ReflectionRotation elements.

Author:
Michael Case

DDLVector.h - description ------------------- begin: Fri Nov 21 2003 email: case@ucdhep.ucdavis.edu

This is the Vector container

Definition at line 31 of file DDLVector.h.


Constructor & Destructor Documentation

DDLVector::DDLVector ( DDLElementRegistry myreg)

Definition at line 72 of file DDLVector.cc.

  : DDXMLElement( myreg )
{}
DDLVector::~DDLVector ( void  )

Definition at line 76 of file DDLVector.cc.

{}

Member Function Documentation

void DDLVector::clearall ( void  )

Definition at line 199 of file DDLVector.cc.

References DDXMLElement::clear(), pStrVecMap, and pVecMap.

{
  DDXMLElement::clear();
  pVecMap.clear();
  pStrVecMap.clear();
}
void DDLVector::do_makeDouble ( char const *  str,
char const *  end 
) [private]

Definition at line 175 of file DDLVector.cc.

References DDI::Singleton< I >::instance(), pNameSpace, and pVector.

{
  std::string ts(str, end);
  double td = ExprEvalSingleton::instance().eval(pNameSpace, ts);
  pVector.push_back(td);
}
void DDLVector::do_makeString ( char const *  str,
char const *  end 
) [private]

Definition at line 183 of file DDLVector.cc.

References pStrVector.

{
  std::string ts(str, end);
  pStrVector.push_back(ts);
}
void DDLVector::errorOut ( const char *  str) const [private]

Definition at line 190 of file DDLVector.cc.

References ExpressReco_HICollisions_FallBack::e, and DDXMLElement::throwError().

Referenced by processElement().

{
  std::string e("Failed to parse the following: \n");
  e+= std::string(str);
  e+="\n as a Vector element (comma separated list).";
  throwError (e);
}
ReadMapType< std::vector< std::string > > & DDLVector::getMapOfStrVectors ( void  )

Definition at line 169 of file DDLVector.cc.

References pStrVecMap.

Referenced by DDLAlgorithm::processElement().

{
  return pStrVecMap;
}
ReadMapType< std::vector< double > > & DDLVector::getMapOfVectors ( void  )

Definition at line 163 of file DDLVector.cc.

References pVecMap.

Referenced by DDLAlgorithm::processElement().

{
  return pVecMap;
}
bool DDLVector::parse_numbers ( char const *  str) const [private]

Definition at line 51 of file DDLVector.cc.

References triggerExpression::parse().

Referenced by processElement().

{
  static VectorMakeDouble makeDouble;
  return parse(str,
               ((+(anychar_p - ','))[makeDouble] 
                >> *(',' >> (+(anychar_p - ','))[makeDouble]))
               >> end_p
               , space_p).full;
}
bool DDLVector::parse_strings ( char const *  str) const [private]

Definition at line 62 of file DDLVector.cc.

References triggerExpression::parse().

Referenced by processElement().

{
  static VectorMakeString makeString;
  return parse(str,
               ((+(anychar_p - ','))[makeString] 
                >> *(',' >> (+(anychar_p - ','))[makeString])) 
               >> end_p
               , space_p).full;
}
void DDLVector::preProcessElement ( const std::string &  name,
const std::string &  nmspace,
DDCompactView cpv 
) [virtual]

Called by loadAttributes AFTER attributes are loaded.

The preProcessElement method can assume that the attributes are loaded and perform any code that is necessary at the start of an element.

This would allow users to call their own code to setup anything necessary for the continued processing of the child elements.

Reimplemented from DDXMLElement.

Definition at line 80 of file DDLVector.cc.

References pNameSpace, pStrVector, and pVector.

{
  pVector.clear();
  pStrVector.clear();
  pNameSpace = nmspace;
}
void DDLVector::processElement ( const std::string &  name,
const std::string &  nmspace,
DDCompactView cpv 
) [virtual]

Processing the element.

The processElement method completes any necessary work to process the XML element.

For example, this can be used to call the DDCore to make the geometry in memory. There is a default for this so that if not declared in the inheriting class, no processing is done.

Reimplemented from DDXMLElement.

Definition at line 88 of file DDLVector.cc.

References DDXMLElement::clear(), DCOUT_V, errorOut(), DDXMLElement::getAttributeSet(), DDXMLElement::getDDName(), DDXMLElement::getText(), DDI::Singleton< I >::instance(), runTheMatrix::msg, DDXMLElement::parent(), parse_numbers(), parse_strings(), pNameSpace, pStrVecMap, pStrVector, pVecMap, pVector, and v.

{
  DCOUT_V('P', "DDLVector::processElement started");

  DDXMLAttribute atts = getAttributeSet();
  bool isNumVec((atts.find("type") == atts.end() 
                 || atts.find("type")->second == "numeric")
                ?  true : false);
  bool isStringVec((!isNumVec && atts.find("type") != atts.end() 
                    && atts.find("type")->second == "string")
                   ? true : false);
  std::string tTextToParse = getText();
  //  cout << "tTextToParse is |"<< tTextToParse << "|" << endl;
  if (tTextToParse.size() == 0) {
    errorOut(" EMPTY STRING ");
  }
  
  if (isNumVec) {//(atts.find("type") == atts.end() || atts.find("type")->second == "numeric") {
    if (!parse_numbers(tTextToParse.c_str())) {
      errorOut(tTextToParse.c_str());
    }
  }
  else if (isStringVec) { //(atts.find("type")->second == "string") {
    if (!parse_strings(tTextToParse.c_str())) {
      errorOut(tTextToParse.c_str());
    }
  }
  else {
    errorOut("Unexpected std::vector type. Only \"numeric\" and \"string\" are allowed.");
  }


  if (parent() == "Algorithm" || parent() == "SpecPar")
  {
    if (isNumVec) { //(atts.find("type") != atts.end() || atts.find("type")->second == "numeric") {
      //        std::cout << "adding to pVecMap name= " << atts.find("name")->second << std::endl;
      //        for (std::vector<double>::const_iterator it = pVector.begin(); it != pVector.end(); ++it)
      //          std::cout << *it << "\t" << std::endl;
      pVecMap[atts.find("name")->second] = pVector;
      //        std::cout << "size: " << pVecMap.size() << std::endl;
    }
    else if (isStringVec) { //(atts.find("type")->second == "string") {
      pStrVecMap[atts.find("name")->second] = pStrVector;
      //        cout << "it is a string, name is: " << atts.find("name")->second << endl;
    }
    size_t expNEntries = 0;
    if (atts.find("nEntries") != atts.end()) {
      std::string nEntries = atts.find("nEntries")->second;
      expNEntries = size_t (ExprEvalSingleton::instance().eval(pNameSpace, nEntries));
    }
    if ( (isNumVec && pVector.size() != expNEntries)
         || (isStringVec && pStrVector.size() != expNEntries) )
    {
      std::string msg ("Number of entries found in Vector text does not match number in attribute nEntries.");
      msg += "\n\tnEntries = " + atts.find("nEntries")->second;
      msg += "\n------------------text---------\n";
      msg += tTextToParse;
      msg += "\n------------------text---------\n";
      errorOut(msg.c_str());
    }
  }
  else if (parent() == "ConstantsSection" || parent() == "DDDefinition")
  {
    if (atts.find("type") == atts.end() || atts.find("type")->second == "numeric") {
      DDVector v(getDDName(nmspace), new std::vector<double>(pVector));
    }
    else {
      DDStrVector v(getDDName(nmspace), new std::vector<std::string>(pStrVector));
    }
  }
  clear();
  DCOUT_V('P', "DDLVector::processElement completed");
}

Friends And Related Function Documentation

friend class VectorMakeDouble [friend]

Definition at line 34 of file DDLVector.h.

friend class VectorMakeString [friend]

Definition at line 35 of file DDLVector.h.


Member Data Documentation

std::string DDLVector::pNameSpace [private]

Definition at line 58 of file DDLVector.h.

Referenced by do_makeDouble(), preProcessElement(), and processElement().

ReadMapType< std::vector<std::string> > DDLVector::pStrVecMap [private]

Definition at line 57 of file DDLVector.h.

Referenced by clearall(), getMapOfStrVectors(), and processElement().

std::vector<std::string> DDLVector::pStrVector [private]

Definition at line 55 of file DDLVector.h.

Referenced by do_makeString(), preProcessElement(), and processElement().

ReadMapType< std::vector<double> > DDLVector::pVecMap [private]

Definition at line 56 of file DDLVector.h.

Referenced by clearall(), getMapOfVectors(), and processElement().

std::vector<double> DDLVector::pVector [private]

Definition at line 54 of file DDLVector.h.

Referenced by do_makeDouble(), preProcessElement(), and processElement().