CMS 3D CMS Logo

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

DDLMap Class Reference

DDLMap handles Map container. More...

#include <DDLMap.h>

Inheritance diagram for DDLMap:
DDXMLElement

List of all members.

Public Member Functions

 DDLMap (DDLElementRegistry *myreg)
ReadMapType< std::map
< std::string, double > > & 
getMapOfMaps (void)
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.
virtual ~DDLMap (void)

Private Member Functions

void do_makeDouble (char const *str, char const *end)
void do_makeName (char const *str, char const *end)
void do_pair (char const *str, char const *end)
void errorOut (const char *str)

Private Attributes

double pDouble
dd_map_type pMap
ReadMapType< std::map
< std::string, double > > 
pMapMap
std::string pName
std::string pNameSpace

Friends

class MapMakeDouble
class MapMakeName
class MapPair

Detailed Description

DDLMap handles Map container.

Author:
Michael Case

DDLMap.h - description ------------------- begin: Fri Nov 28, 2003 email: case@ucdhep.ucdavis.edu

This is the Map container. It is a c++ stye std::map <std::string, double> and has a name associated with the Map for the DDD name-reference system.

Definition at line 58 of file DDLMap.h.


Constructor & Destructor Documentation

DDLMap::DDLMap ( DDLElementRegistry myreg)

Definition at line 18 of file DDLMap.cc.

  : DDXMLElement( myreg )
{}
DDLMap::~DDLMap ( void  ) [virtual]

Definition at line 22 of file DDLMap.cc.

{}

Member Function Documentation

void DDLMap::do_makeDouble ( char const *  str,
char const *  end 
) [private]

Definition at line 155 of file DDLMap.cc.

References instance, pDouble, and pNameSpace.

Referenced by MapMakeDouble::operator()().

{
  std::string ts(str, end);
  pDouble = ExprEvalSingleton::instance().eval(pNameSpace, ts);
}
void DDLMap::do_makeName ( char const *  str,
char const *  end 
) [private]

Definition at line 149 of file DDLMap.cc.

References pName.

Referenced by MapMakeName::operator()().

{
  pName = std::string(str, end); 
}
void DDLMap::do_pair ( char const *  str,
char const *  end 
) [private]

Definition at line 143 of file DDLMap.cc.

References pDouble, pMap, and pName.

Referenced by MapPair::operator()().

{
  pMap[pName] = pDouble;
}
void DDLMap::errorOut ( const char *  str) [private]

Definition at line 162 of file DDLMap.cc.

References lumiQueryAPI::msg, and DDXMLElement::throwError().

Referenced by processElement().

{
  std::string msg("\nDDLMap: Failed to parse the following: \n");
  msg+= std::string(str);
  msg+="\n as a Map element (comma separated list of name=value).";
  throwError(msg);
}
ReadMapType< std::map< std::string, double > > & DDLMap::getMapOfMaps ( void  )

Definition at line 171 of file DDLMap.cc.

References pMapMap.

Referenced by DDLAlgorithm::processElement().

{
  return pMapMap;
}
void DDLMap::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 76 of file DDLMap.cc.

References pDouble, pMap, pName, and pNameSpace.

{
  pName = "";
  pMap.clear() ;
  //pMapMap.clear(); only the DDLAlgorithm is allowed to clear this guy!
  pDouble = 0.0;
  pNameSpace = nmspace;
}
void DDLMap::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 86 of file DDLMap.cc.

References DDXMLElement::clear(), DCOUT_V, errorOut(), DDXMLElement::getAttributeSet(), DDXMLElement::getDDName(), DDXMLElement::getText(), info, DDI::Singleton< I >::instance(), m, DDXMLElement::parent(), triggerExpression::parse(), pMap, pMapMap, and pNameSpace.

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

  std::string tTextToParse = getText();
  DDXMLAttribute atts = getAttributeSet();
  std::string tName = atts.find("name")->second;

  if (tTextToParse.size() == 0)
  {
    errorOut("No std::string to parse!");
  }

  // NOT IMPLEMENTED YET
  if (atts.find("type") != atts.end() && atts.find("type")->second == "string")
  {
    errorOut("Map of type std::string is not supported yet.");
  }

  Mapper mapGrammar;
  
  pMap.clear();

  parse_info<> info = boost::spirit::classic::parse(tTextToParse.c_str(), mapGrammar >> end_p, space_p);
  if (!info.full)
  {
    errorOut("Does not conform to name=value, name=value... etc. of ddl Map element.");
  }

  if (parent() == "Algorithm" || parent() == "SpecPar")
  {
    pMapMap[tName] = pMap;
  }
  else if (parent() == "ConstantsSection" || parent() == "DDDefinition") 
  {
    dd_map_type * tMap = new dd_map_type;
    for (std::map<std::string, double>::const_iterator it = pMap.begin(); it != pMap.end(); ++it)
    {
      (*tMap)[it->first] = it->second;
    }
    DDMap m ( getDDName(pNameSpace) , tMap);
    // clear the map of maps, because in these elements we only have ONE at a time.
    pMapMap.clear(); 
  }

  std::string nEntries = atts.find("nEntries")->second;
  if (pMap.size() != 
      size_t(ExprEvalSingleton::instance().eval(pNameSpace, nEntries)))
  {
    errorOut("Number of entries found in Map text does not match number in attribute nEntries.");
  }
  clear();
  
  DCOUT_V('P', "DDLMap::processElement completed");
}

Friends And Related Function Documentation

friend class MapMakeDouble [friend]

Definition at line 62 of file DDLMap.h.

friend class MapMakeName [friend]

Definition at line 61 of file DDLMap.h.

friend class MapPair [friend]

Definition at line 60 of file DDLMap.h.


Member Data Documentation

double DDLMap::pDouble [private]

Definition at line 79 of file DDLMap.h.

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

Definition at line 77 of file DDLMap.h.

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

ReadMapType<std::map<std::string,double> > DDLMap::pMapMap [private]

Definition at line 78 of file DDLMap.h.

Referenced by getMapOfMaps(), and processElement().

std::string DDLMap::pName [private]

Definition at line 80 of file DDLMap.h.

Referenced by do_makeName(), do_pair(), and preProcessElement().

std::string DDLMap::pNameSpace [private]

Definition at line 81 of file DDLMap.h.

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