#include <VisDesc/VisualizationSvc.h>
Inheritance diagram for VisualizationSvc:
Public Types | |
SUCCESS | |
NO_INTERFACE | |
VERSMISMATCH | |
LAST_ERROR | |
enum | Status |
Public Member Functions | |
VisualizationSvc (const std::string &name, ISvcLocator *svc) | |
Standard Constructor. | |
virtual | ~VisualizationSvc () |
default destructor | |
virtual StatusCode | initialize () |
Initializes the service. | |
virtual StatusCode | queryInterface (const InterfaceID &riid, void **ppvInterface) |
Queries interfaces of Interface. | |
virtual const VisAttribute | visAttribute (const Material *mat) const |
This method returns the visualization attribute associated to a given material or 0 if there is no attribute associated to it. | |
virtual const VisAttribute | visAttribute (const ILVolume *vol) const |
This method returns the visualization attribute associated to a given logical volume or 0 if there is no attribute associated to it. | |
virtual void | reload () |
this method erases the current set of attributes and loads a new set | |
virtual void | clear () |
this method erases the current set of attributes | |
virtual unsigned long | addRef () |
virtual unsigned long | release () |
virtual const std::string & | name () const |
virtual const InterfaceID & | type () const |
virtual StatusCode | configure () |
virtual StatusCode | start () |
virtual StatusCode | stop () |
virtual StatusCode | finalize () |
virtual StatusCode | terminate () |
virtual Gaudi::StateMachine::State | FSMState () const |
virtual Gaudi::StateMachine::State | targetFSMState () const |
virtual StatusCode | reinitialize () |
virtual StatusCode | restart () |
virtual StatusCode | sysInitialize () |
virtual StatusCode | sysStart () |
virtual StatusCode | sysStop () |
virtual StatusCode | sysFinalize () |
virtual StatusCode | sysReinitialize () |
virtual StatusCode | sysRestart () |
virtual StatusCode | setProperty (const Property &p) |
virtual StatusCode | setProperty (const std::string &s) |
virtual StatusCode | setProperty (const std::string &n, const std::string &v) |
StatusCode | setProperty (const std::string &name, const TYPE &value) |
virtual StatusCode | getProperty (Property *p) const |
virtual const Property & | getProperty (const std::string &name) const |
virtual StatusCode | getProperty (const std::string &n, std::string &v) const |
virtual const std::vector< Property * > & | getProperties () const |
ISvcLocator * | serviceLocator () const |
IMessageSvc * | msgSvc () |
IMessageSvc * | msgSvc () const |
IMessageSvc * | messageService () |
IMessageSvc * | messageService () const |
StatusCode | setProperties () |
StatusCode | service (const std::string &name, T *&psvc, bool createIf=true) const |
StatusCode | service (const std::string &svcType, const std::string &svcName, T *&psvc) const |
Property * | declareProperty (const std::string &name, T &property, const std::string &doc="none") const |
Property * | declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const |
IAuditorSvc * | auditorSvc () const |
Static Public Member Functions | |
static const InterfaceID & | interfaceID () |
static const InterfaceID & | interfaceID () |
static const InterfaceID & | interfaceID () |
static const InterfaceID & | interfaceID () |
Retrieve interface ID. | |
Public Attributes | |
SUCCESS | |
NO_INTERFACE | |
VERSMISMATCH | |
LAST_ERROR | |
Protected Member Functions | |
int | outputLevel () const |
Protected Attributes | |
IntegerProperty | m_outputLevel |
Gaudi::StateMachine::State | m_state |
Gaudi::StateMachine::State | m_targetState |
IMessageSvc * | m_messageSvc |
Private Types | |
typedef std::map< std::string, VisAttribute > | AttributeSet |
This defines a set of attributes. | |
typedef std::map< std::string, std::string > | Dictionnary |
This defines a dictionnary. | |
Private Attributes | |
AttributeSet | m_attributeSet |
a map of attributes to be used | |
Dictionnary | m_material2Vis |
a dictionnary linking materials and VisAttributes | |
Dictionnary | m_logvol2Vis |
a dictionnary linking logical volumes and VisAttributes | |
Dictionnary | m_logvol_regex_2Vis |
std::string | m_colorDbLocation |
The location of the Xml file containing all definitions. | |
Friends | |
class | SvcFactory< VisualizationSvc > |
Friend needed. | |
friend class | ServiceManager |
It is able to associate visualization attributes to materials and logical volumes. These describe the way these materials and volumes should be displayed
Definition at line 26 of file VisualizationSvc.h.
typedef std::map<std::string, VisAttribute> VisualizationSvc::AttributeSet [private] |
This defines a set of attributes.
Each one is associated to a name
Definition at line 98 of file VisualizationSvc.h.
typedef std::map<std::string, std::string> VisualizationSvc::Dictionnary [private] |
VisualizationSvc::VisualizationSvc | ( | const std::string & | name, | |
ISvcLocator * | svc | |||
) |
Standard Constructor.
name | String with service name | |
svc | Pointer to service locator interface |
Definition at line 48 of file VisualizationSvc.cpp.
00048 : 00049 Service (name, svc) { 00050 declareProperty ("ColorDbLocation", m_colorDbLocation="empty" ); 00051 }
virtual VisualizationSvc::~VisualizationSvc | ( | ) | [inline, virtual] |
StatusCode VisualizationSvc::initialize | ( | ) | [virtual] |
Initializes the service.
Reimplemented from Service.
Definition at line 56 of file VisualizationSvc.cpp.
00056 { 00057 // Before anything we have to initialize grand mother 00058 StatusCode status = Service::initialize(); 00059 if (!status.isSuccess()) { 00060 return status; 00061 } 00062 if( m_colorDbLocation.empty() || "empty" == m_colorDbLocation ) { 00063 if ( 0 != getenv("XMLVISROOT") ) { 00064 m_colorDbLocation = getenv("XMLVISROOT"); 00065 m_colorDbLocation += "/xml/colors.xml"; 00066 } else { 00067 m_colorDbLocation = ""; 00068 } 00069 } 00070 // loads the color set 00071 reload(); 00072 // returns 00073 return StatusCode::SUCCESS; 00074 }
StatusCode VisualizationSvc::queryInterface | ( | const InterfaceID & | riid, | |
void ** | ppvInterface | |||
) | [virtual] |
Queries interfaces of Interface.
riid | ID of Interface to be retrieved | |
ppvInterface | Pointer to Location for interface pointer |
Reimplemented from Service.
Definition at line 416 of file VisualizationSvc.cpp.
00416 { 00417 if (IID_IVisualizationSvc.versionMatch(riid)) { 00418 *ppvInterface = (IVisualizationSvc*)this; 00419 addRef(); 00420 return StatusCode::SUCCESS; 00421 } else { 00422 // Interface is not directly availible: try out a base class 00423 return Service::queryInterface(riid, ppvInterface); 00424 } 00425 }
const VisAttribute VisualizationSvc::visAttribute | ( | const Material * | mat | ) | const [virtual] |
This method returns the visualization attribute associated to a given material or 0 if there is no attribute associated to it.
mat | the material |
Implements IVisualizationSvc.
Definition at line 307 of file VisualizationSvc.cpp.
00307 { 00308 VisAttribute attr; 00309 00310 if (0 != mat) { 00311 Dictionnary::const_iterator it = 00312 m_material2Vis.find (mat->registry()->identifier()); 00313 if (it != m_material2Vis.end()) { 00314 AttributeSet::const_iterator it2 = m_attributeSet.find (it->second); 00315 if (it2 != m_attributeSet.end()) { 00316 attr = it2->second; 00317 } else { 00318 MsgStream log(msgSvc(), name()); 00319 log << MSG::WARNING << "VisAttribute " << it->second << " unknown but" 00320 << " used for material " << mat->name() << "." << endmsg; 00321 } 00322 } 00323 } 00324 return attr; 00325 }
const VisAttribute VisualizationSvc::visAttribute | ( | const ILVolume * | vol | ) | const [virtual] |
This method returns the visualization attribute associated to a given logical volume or 0 if there is no attribute associated to it.
vol | the logical volume |
Implements IVisualizationSvc.
Definition at line 332 of file VisualizationSvc.cpp.
00332 { 00333 VisAttribute attr; 00334 00335 if (0 != vol) { 00336 // try first to find an attribute associated directly to the logical volume 00337 std::string bnn = vol->name(); 00338 00339 Dictionnary::const_iterator it = m_logvol2Vis.find (bnn); 00340 if (it != m_logvol2Vis.end()) { 00341 AttributeSet::const_iterator it2 = m_attributeSet.find (it->second); 00342 if (it2 != m_attributeSet.end()) { 00343 attr = it2->second; 00344 // If the attribute is complete, just return 00345 if (attr.color().isValid() && 00346 VisAttribute::NO_VISIBILITY != attr.visible() && 00347 VisAttribute::NO_STATUS != attr.openStatus() && 00348 VisAttribute::NO_MODE != attr.displayMode()) { 00349 return attr; 00350 } 00351 } else { 00352 MsgStream log(msgSvc(), name()); 00353 log << MSG::WARNING << "VisAttribute " << it->second 00354 << " unknown but" 00355 << " used for logical volume " << vol->name() << "." << endmsg; 00356 return attr; 00357 } 00358 } 00359 00360 // look in LogVol Vis XMLs with regular expression : 00361 {Dictionnary::const_iterator it; 00362 for(it=m_logvol_regex_2Vis.begin();it!=m_logvol_regex_2Vis.end();it++) { 00363 boost::regex re(it->first); 00364 if(boost::regex_search(bnn,re)) { 00365 //printf("debug : for \"%s\", found \"%s\" with value \"%s\"\n", 00366 // bnn.c_str(),it->first.c_str(),it->second.c_str()); 00367 00368 AttributeSet::const_iterator it2 = m_attributeSet.find (it->second); 00369 if (it2 != m_attributeSet.end()) { 00370 attr = it2->second; 00371 // If the attribute is complete, just return 00372 if (attr.color().isValid() && 00373 VisAttribute::NO_VISIBILITY != attr.visible() && 00374 VisAttribute::NO_STATUS != attr.openStatus() && 00375 VisAttribute::NO_MODE != attr.displayMode()) { 00376 return attr; 00377 } 00378 } else { 00379 MsgStream log(msgSvc(), name()); 00380 log << MSG::WARNING << "VisAttribute " << it->second 00381 << " unknown but" 00382 << " used for logical volume " << vol->name() << "." << endmsg; 00383 return attr; 00384 } 00385 00386 break; 00387 } 00388 }} 00389 00390 // either we don't have an attribute or it may be interesting to 00391 // complete it using the material 00392 try { 00393 const VisAttribute attr2 = visAttribute(vol->material()); 00394 attr.merge(attr2); 00395 } catch (LogVolumeException ex) { 00396 // This occurs when the material retrieval raises an exception 00397 // We display the exception message and return an invalid color 00398 MsgStream log (msgSvc(), "VisualizationSvc"); 00399 log << MSG::WARNING 00400 << "Exception received in VisualizationSvc::logvolColor : " 00401 << endmsg; 00402 ex.printOut (log); 00403 log << MSG::WARNING << "Visualization attribute will be corrupted." 00404 << endmsg; 00405 } 00406 } 00407 00408 return attr; 00409 00410 }
void VisualizationSvc::reload | ( | ) | [virtual] |
this method erases the current set of attributes and loads a new set
Implements IVisualizationSvc.
Definition at line 89 of file VisualizationSvc.cpp.
00089 { 00090 MsgStream log (msgSvc(), "VisualizationSvc"); 00091 00092 // erases the old set of attributes 00093 clear(); 00094 00095 // gets the XmlSvc 00096 IXmlSvc* xmlSvc; 00097 StatusCode status = serviceLocator()->service("XmlCnvSvc", xmlSvc, true); 00098 if (status.isFailure()) { 00099 log << MSG::ERROR << "Unable to get XmlCnvSvc. The visualization " 00100 << "attributes will not be loaded." << endmsg; 00101 return; 00102 } 00103 log << MSG::INFO << "Loading visualization attributes file \"" 00104 << m_colorDbLocation << "\" ..." << endmsg; 00105 00106 // parses the file containing the color definitions 00107 IOVDOMDocument* iovDoc = xmlSvc->parse(m_colorDbLocation.c_str()); 00108 if (!iovDoc) { 00109 log << MSG::ERROR << "Unable to parse file " << m_colorDbLocation 00110 << ". The visualization attributes will not be loaded." << endmsg; 00111 return; 00112 } 00113 DOMDocument* document = iovDoc->getDOM(); 00114 if (!document) { 00115 log << MSG::ERROR << "Document does not exist " << m_colorDbLocation 00116 << ". The visualization attributes will not be loaded." << endmsg; 00117 xmlSvc->releaseDoc(iovDoc); 00118 return; 00119 } 00120 00121 // go through the tree of elements and fill in the attribute sets 00122 XMLCh* xs = xercesc::XMLString::transcode("VisAtt"); 00123 DOMNodeList* domAttrList = document->getElementsByTagName(xs); 00124 if(!domAttrList) { 00125 xmlSvc->releaseDoc(iovDoc); 00126 return; 00127 } 00128 00129 xercesc::XMLString::release(&xs); 00130 unsigned int i; 00131 for (i = 0; i < domAttrList->getLength(); i++) { 00132 DOMNode* attrNode = domAttrList->item(i); 00133 DOMElement* attr = (DOMElement*) attrNode; 00134 00135 xs = xercesc::XMLString::transcode("name"); 00136 std::string name = dom2Std (attr->getAttribute (xs)); 00137 xercesc::XMLString::release(&xs); 00138 00139 xs = xercesc::XMLString::transcode("visible"); 00140 std::string visibleAttribute = dom2Std (attr->getAttribute (xs)); 00141 xercesc::XMLString::release(&xs); 00142 00143 xs = xercesc::XMLString::transcode("opened"); 00144 std::string openedAttribute = dom2Std (attr->getAttribute (xs)); 00145 xercesc::XMLString::release(&xs); 00146 00147 xs = xercesc::XMLString::transcode("mode"); 00148 std::string modeAttribute = dom2Std (attr->getAttribute (xs)); 00149 xercesc::XMLString::release(&xs); 00150 00151 // computes the values 00152 VisAttribute::Visibility visible = VisAttribute::NO_VISIBILITY; 00153 if ("Yes" == visibleAttribute) { 00154 visible = VisAttribute::VISIBLE; 00155 } else if ("No" == visibleAttribute) { 00156 visible = VisAttribute::NOT_VISIBLE; 00157 } 00158 VisAttribute::OpenStatus opened = VisAttribute::NO_STATUS; 00159 if ("Yes" == openedAttribute) { 00160 opened = VisAttribute::OPENED; 00161 } else if ("No" == openedAttribute) { 00162 opened = VisAttribute::CLOSED; 00163 } 00164 VisAttribute::DisplayMode mode = VisAttribute::NO_MODE; 00165 if ("Plain" == modeAttribute) { 00166 mode = VisAttribute::PLAIN; 00167 } else if ("WireFrame" == modeAttribute) { 00168 mode = VisAttribute::WIRE_FRAME; 00169 } 00170 00171 // Looks whether a color node exists 00172 Color color; 00173 xs = xercesc::XMLString::transcode("Color"); 00174 DOMNodeList* domColorList = attr->getElementsByTagName(xs); 00175 xercesc::XMLString::release(&xs); 00176 00177 if (domColorList && domColorList->getLength() > 0) { 00178 DOMNode* colorNode = domColorList->item(0); 00179 DOMElement* colorElement = (DOMElement*) colorNode; 00180 00181 xs = xercesc::XMLString::transcode("R"); 00182 std::string RAttribute = dom2Std (colorElement->getAttribute (xs)); 00183 xercesc::XMLString::release(&xs); 00184 00185 xs = xercesc::XMLString::transcode("G"); 00186 std::string GAttribute = dom2Std (colorElement->getAttribute (xs)); 00187 xercesc::XMLString::release(&xs); 00188 00189 xs = xercesc::XMLString::transcode("B"); 00190 std::string BAttribute = dom2Std (colorElement->getAttribute (xs)); 00191 xercesc::XMLString::release(&xs); 00192 00193 xs = xercesc::XMLString::transcode("A"); 00194 std::string AAttribute = dom2Std (colorElement->getAttribute (xs)); 00195 xercesc::XMLString::release(&xs); 00196 00197 // computes the values 00198 float red = 0.0; 00199 float green = 0.0; 00200 float blue = 0.0; 00201 float alpha = 0.0; 00202 if (!RAttribute.empty()) { 00203 red = (float)xmlSvc->eval(RAttribute, false); 00204 } 00205 if (!GAttribute.empty()) { 00206 green = (float)xmlSvc->eval(GAttribute, false); 00207 } 00208 if (!BAttribute.empty()) { 00209 blue = (float)xmlSvc->eval(BAttribute, false); 00210 } 00211 if (!AAttribute.empty()) { 00212 alpha = (float)xmlSvc->eval(AAttribute, false); 00213 } 00214 00215 // creates the color 00216 color = Color (red, green, blue, alpha); 00217 } 00218 00219 // creates the attribute and register it 00220 m_attributeSet[name] = VisAttribute(visible, opened, mode, color); 00221 } 00222 00223 // go through the tree of elements and fill in the material2Vis map 00224 xs = xercesc::XMLString::transcode("Materials"); 00225 DOMNodeList* domMaterialsList = document->getElementsByTagName(xs); 00226 xercesc::XMLString::release(&xs); 00227 00228 if (domMaterialsList && domMaterialsList->getLength() > 0) { 00229 DOMNode* materialsNode = domMaterialsList->item(0); 00230 DOMElement* materialsElement = (DOMElement*) materialsNode; 00231 00232 xs = xercesc::XMLString::transcode("Item"); 00233 DOMNodeList* domMaterialList = materialsElement->getElementsByTagName(xs); 00234 xercesc::XMLString::release(&xs); 00235 00236 if(domMaterialList) { 00237 unsigned int i; 00238 for (i = 0; i < domMaterialList->getLength(); i++) { 00239 DOMNode* materialNode = domMaterialList->item(i); 00240 DOMElement* material = (DOMElement*) materialNode; 00241 00242 xs = xercesc::XMLString::transcode("name"); 00243 std::string name = dom2Std (material->getAttribute (xs)); 00244 xercesc::XMLString::release(&xs); 00245 00246 xs = xercesc::XMLString::transcode("attr"); 00247 std::string attr = dom2Std (material->getAttribute (xs)); 00248 xercesc::XMLString::release(&xs); 00249 00250 // register the association 00251 m_material2Vis[name] = attr; 00252 } 00253 } 00254 } 00255 00256 // go through the tree of elements and fill in the logvol2Vis map 00257 xs = xercesc::XMLString::transcode("LogVols"); 00258 DOMNodeList* domLogvolsList = document->getElementsByTagName(xs); 00259 xercesc::XMLString::release(&xs); 00260 00261 if (domLogvolsList->getLength() > 0) { 00262 DOMNode* logvolsNode = domLogvolsList->item(0); 00263 DOMElement* logvolsElement = (DOMElement*) logvolsNode; 00264 00265 xs = xercesc::XMLString::transcode("Item"); 00266 DOMNodeList* domLogvolList = logvolsElement->getElementsByTagName(xs); 00267 xercesc::XMLString::release(&xs); 00268 00269 unsigned int i; 00270 for (i = 0; i < domLogvolList->getLength(); i++) { 00271 DOMNode* logvolNode = domLogvolList->item(i); 00272 DOMElement* logvol = (DOMElement*) logvolNode; 00273 00274 xs = xercesc::XMLString::transcode("name"); 00275 std::string sname = dom2Std (logvol->getAttribute (xs)); 00276 xercesc::XMLString::release(&xs); 00277 00278 xs = xercesc::XMLString::transcode("regex"); 00279 std::string sregex = dom2Std (logvol->getAttribute (xs)); 00280 xercesc::XMLString::release(&xs); 00281 00282 xs = xercesc::XMLString::transcode("attr"); 00283 std::string attr = dom2Std (logvol->getAttribute (xs)); 00284 xercesc::XMLString::release(&xs); 00285 00286 // register the association 00287 if(sname.size()) { 00288 m_logvol2Vis[sname] = attr; 00289 } else if(sregex.size()) { 00290 m_logvol_regex_2Vis[sregex] = attr; 00291 } else { 00292 MsgStream log(msgSvc(), name()); 00293 log << MSG::WARNING << "LogVol with empty name or regex attribute." 00294 << endmsg; 00295 } 00296 } 00297 } 00298 00299 xmlSvc->releaseDoc(iovDoc); 00300 00301 }
void VisualizationSvc::clear | ( | ) | [virtual] |
this method erases the current set of attributes
Definition at line 79 of file VisualizationSvc.cpp.
00079 { 00080 m_attributeSet.clear(); 00081 m_material2Vis.clear(); 00082 m_logvol2Vis.clear(); 00083 m_logvol_regex_2Vis.clear(); 00084 }
static const InterfaceID& IVisualizationSvc::interfaceID | ( | ) | [inline, static, inherited] |
Retrieve interface ID.
Reimplemented from IInterface.
Definition at line 35 of file IVisualizationSvc.h.
00035 { return IID_IVisualizationSvc; }
friend class SvcFactory< VisualizationSvc > [friend] |
AttributeSet VisualizationSvc::m_attributeSet [private] |
Dictionnary VisualizationSvc::m_material2Vis [private] |
a dictionnary linking materials and VisAttributes
Definition at line 109 of file VisualizationSvc.h.
Dictionnary VisualizationSvc::m_logvol2Vis [private] |
a dictionnary linking logical volumes and VisAttributes
Definition at line 112 of file VisualizationSvc.h.
Definition at line 113 of file VisualizationSvc.h.
std::string VisualizationSvc::m_colorDbLocation [private] |
The location of the Xml file containing all definitions.
Definition at line 116 of file VisualizationSvc.h.