00001
00002 #include <OnXSvc/OnXSvc.h>
00003
00004
00005 #include <Slash/Core/IWriter.h>
00006 #include <Slash/Data/IProcessor.h>
00007 #include <Slash/Core/IManager.h>
00008 #include <Slash/UI/IUI_Manager.h>
00009
00010
00011 #include <Lib/Interfaces/ISession.h>
00012
00013 #include <Lib/smanip.h>
00014 #include <Lib/Printer.h>
00015 #include <Lib/Manager.h>
00016 #include <Lib/System.h>
00017 #include <Lib/Arguments.h>
00018
00019
00020 #include <OnX/Interfaces/IUI.h>
00021 #include <OnX/Interfaces/IWidgetClass.h>
00022
00023
00024 #include <GaudiKernel/ISvcLocator.h>
00025 #include <GaudiKernel/IAppMgrUI.h>
00026 #include <GaudiKernel/IDataProviderSvc.h>
00027 #include <GaudiKernel/IDataManagerSvc.h>
00028 #include <GaudiKernel/IRegistry.h>
00029 #include <GaudiKernel/IHistogramSvc.h>
00030 #include <GaudiKernel/IEvtSelector.h>
00031 #include <GaudiKernel/SvcFactory.h>
00032 #include <GaudiKernel/SmartIF.h>
00033 #include <GaudiKernel/MsgStream.h>
00034 #include <GaudiKernel/SmartDataPtr.h>
00035 #include <GaudiKernel/GaudiException.h>
00036 #include <GaudiKernel/System.h>
00037
00038
00039 #include <AIDA/IHistogram.h>
00040
00041 #include <XmlTools/IXmlSvc.h>
00042
00043
00044 #include <VisSvc/IVisualizationSvc.h>
00045
00046
00047 #include <OnXSvc/ISoConversionSvc.h>
00048 #include <OnXSvc/ISvcLocatorManager.h>
00049
00050 #include <OnXSvc/Helpers.h>
00051
00052
00053 #include <OnX/Core/Main.h>
00054
00055 DECLARE_SERVICE_FACTORY( OnXSvc );
00056
00057 class SvcLocatorManager
00058 :public virtual Slash::Core::IManager
00059 ,public virtual ISvcLocatorManager {
00060 public:
00061 virtual std::string name() const { return fName; }
00062 virtual void* cast(const std::string& aString) const {
00063 if(aString=="ISvcLocatorManager") {
00064 return ((ISvcLocatorManager*)this);
00065 } else if(aString=="Slash::Core::IManager") {
00066 return ((Slash::Core::IManager*)this);
00067 } else {
00068 return 0;
00069 }
00070 }
00071 public:
00072 virtual ISvcLocator* serviceLocator() const {
00073 return fSvcLocator;
00074 }
00075 virtual IService* service(const std::string& aName) const {
00076 IService* svc;
00077 fSvcLocator->service(aName,svc);
00078 return svc;
00079 }
00080 public:
00081 SvcLocatorManager(ISvcLocator* aSvcLocator)
00082 :fName("SvcLocatorManager"),fSvcLocator(aSvcLocator){}
00083 virtual ~SvcLocatorManager(){}
00084 private:
00085 std::string fName;
00086 ISvcLocator* fSvcLocator;
00087 };
00088
00089 class Printer : public virtual Slash::Core::IWriter {
00090 public:
00091 virtual void disable() {}
00092 virtual void enable() {}
00093 virtual bool enabled() const { return true;}
00094 virtual bool write(const std::string& aString) {
00095 fLog << aString;
00096 return true;
00097 }
00098 virtual bool flush() {
00099 return true;
00100 }
00101 public:
00102 Printer(MsgStream& aLog):fLog(aLog){}
00103 virtual ~Printer(){}
00104 private:
00105 MsgStream& fLog;
00106 };
00107
00109 OnXSvc::OnXSvc(
00110 const std::string& aName
00111 ,ISvcLocator* aSvcLoc
00112 )
00113 :Service(aName,aSvcLoc)
00114 ,fAppMgrUI(0)
00115 ,fSoCnvSvc(0)
00116 ,fEventDataSvc(0)
00117 ,fDetectorDataSvc(0)
00118 ,fHistogramSvc(0)
00119 ,fSession(0)
00120 ,fThreaded(false)
00121 ,fToolkit("NATIVE")
00122 ,fFile("$ONXFILE")
00123 ,fVerboseLevel(0)
00124 ,fOutputToTerminal(false)
00125 ,fLog(0)
00126 ,fOnXMain(0)
00127 ,fTypeManager(0)
00128 ,fMetaType(0)
00129 ,fLibPrinter(0)
00130 ,fGaudiPrinter(0)
00133 {
00134 declareProperty("Threaded",fThreaded);
00135 declareProperty("Toolkit",fToolkit);
00136 declareProperty("File",fFile);
00137 declareProperty("VerboseLevel",fVerboseLevel);
00138 declareProperty("OutputToTerminal",fOutputToTerminal);
00139
00140
00141 fLibPrinter = new Lib::Printer();
00142 }
00144 OnXSvc::~OnXSvc(
00145 )
00146
00147
00148 {
00149 }
00151 StatusCode OnXSvc::queryInterface(
00152 const InterfaceID& aRIID
00153 ,void** aPPVIF
00154 )
00155
00156
00157 {
00158 if (aRIID==IRunable::interfaceID()) {
00159 *aPPVIF = static_cast<IRunable*>(this);
00160 addRef();
00161 return StatusCode::SUCCESS;
00162 } else if(aRIID==IUserInterfaceSvc::interfaceID()) {
00163 *aPPVIF = static_cast<IUserInterfaceSvc*>(this);
00164 addRef();
00165 return StatusCode::SUCCESS;
00166 } else {
00167 return Service::queryInterface(aRIID, aPPVIF);
00168 }
00169 }
00171 StatusCode OnXSvc::initialize(
00172 )
00173
00174
00175 {
00176 StatusCode status = Service::initialize();
00177 if( status.isFailure() ) return status;
00178
00179 fLog = new MsgStream(messageService(), Service::name());
00180
00181 fGaudiPrinter = new Printer(*fLog);
00182
00183 MsgStream log(messageService(), Service::name());
00184
00185 log << MSG::INFO << "OnXSvc::initialize " << endreq;
00186
00187 setProperties();
00188
00189 if(!serviceLocator()) {
00190 log << MSG::INFO << "Service locator not found " << endreq;
00191 return StatusCode::FAILURE;
00192 }
00193
00194 if(fAppMgrUI) {
00195 fAppMgrUI->release();
00196 fAppMgrUI = 0;
00197 }
00198 status = serviceLocator()->service("ApplicationMgr",fAppMgrUI);
00199 if( status.isFailure() || !fAppMgrUI) {
00200 log << MSG::INFO << "ApplicationMgr not found " << endreq;
00201 return StatusCode::FAILURE;
00202 }
00203 fAppMgrUI->addRef();
00204
00205
00206 if(fToolkit=="NONE") {
00207 log << MSG::INFO << "GUI toolkit NONE." << endreq;
00208 } else {
00209 Lib::Arguments gaudi_args(System::cmdLineArgs());
00210
00211
00212 Lib::Arguments args;
00213 {std::string key = "-debug_check_class";
00214 if(gaudi_args.isAnArgument(key)) {
00215 std::string value;
00216 gaudi_args.find(key,value);
00217 args.add(key,value);
00218 }}
00219 {std::string key = "-Qt";
00220 if(gaudi_args.isAnArgument(key)) {
00221 std::string value;
00222 gaudi_args.find(key,value);
00223 args.add(key,value);
00224 }}
00225
00226 fOnXMain = new OnX::Main(false,false,args.tovector());
00227 if(!fOnXMain->isValid()) {
00228 log << MSG::INFO << "Can't create a valid OnX::Main" << endreq;
00229 delete fOnXMain;
00230 fOnXMain = 0;
00231 return StatusCode::FAILURE;
00232 }
00233
00234
00235
00236 if(!fOnXMain->loadInterpreter("Python")) {
00237
00238 log << MSG::INFO << "Can't load the OnX Python module." << endreq;
00239 }
00240
00241
00242 ISession* session = fOnXMain;
00243 if(!session) {
00244 log << MSG::INFO << "OnX::Main don't have a ISession." << endreq;
00245 delete fOnXMain;
00246 fOnXMain = 0;
00247 return StatusCode::FAILURE;
00248 }
00249
00250 if(fOutputToTerminal) session->setParameter("session.output","terminal");
00251
00252 session->setParameter("UI_Manager.thread",fThreaded?"true":"false");
00253
00254 setSession(session);
00255
00256 std::string driver;
00257 if(fToolkit=="NATIVE") {
00258 driver = "";
00259 } else {
00260 driver = fToolkit;
00261 }
00262
00263 log << MSG::INFO << "GUI toolkit " << driver << "." << endreq;
00264 log << MSG::INFO << "OnX GUI file " << fFile << "." << endreq;
00265
00266 if(fOnXMain->createUI(driver,fFile,true)) {
00267 log << MSG::INFO << "GUI created." << endreq;
00268 } else {
00269 log << MSG::INFO << "GUI creation failed." << endreq;
00270 delete fOnXMain;
00271 fOnXMain = 0;
00272 fSession = 0;
00273 return StatusCode::FAILURE;
00274 }
00275 }
00276
00277 return status;
00278 }
00280 StatusCode OnXSvc::finalize(
00281 )
00282
00283
00284 {
00285 if(fAppMgrUI) {
00286 fAppMgrUI->release();
00287 fAppMgrUI = 0;
00288 }
00289 if(fSoCnvSvc) {
00290 fSoCnvSvc->release();
00291 fSoCnvSvc = 0;
00292 }
00293 if(fEventDataSvc) {
00294 fEventDataSvc->release();
00295 fEventDataSvc = 0;
00296 }
00297 if(fDetectorDataSvc) {
00298 fDetectorDataSvc->release();
00299 fDetectorDataSvc = 0;
00300 }
00301 if(fHistogramSvc) {
00302 fHistogramSvc->release();
00303 fHistogramSvc = 0;
00304 }
00305
00306 MsgStream log(messageService(), Service::name());
00307 log << MSG::INFO << "OnXSvc finalizing..." << endreq;
00308
00309 delete fOnXMain;
00310 fOnXMain = 0;
00311 fSession = 0;
00312
00313 delete fGaudiPrinter;
00314 fGaudiPrinter = 0;
00315 delete fLibPrinter;
00316 fLibPrinter = 0;
00317 delete fLog;
00318 fLog = 0;
00319
00320 log << MSG::INFO << "OnXSvc finalized successfully" << endreq;
00321
00322 return StatusCode::SUCCESS;
00323 }
00325 StatusCode OnXSvc::run(
00326 )
00327
00328
00330 {
00331 MsgStream log(messageService(), Service::name());
00332 if(!fSession) {
00333 log << MSG::INFO << "No ISession given " << endreq;
00334 return StatusCode::FAILURE;
00335 }
00336 IUI* ui = findUI();
00337 if(!ui) return StatusCode::FAILURE;
00338 log << MSG::INFO << "Enter in GUI toolkit mainloop... " << endreq;
00339 ui->steer();
00340 log << MSG::INFO << "GUI toolkit mainloop exited. " << endreq;
00341 return StatusCode::SUCCESS;
00342 }
00344 SoPage* OnXSvc::currentSoPage(
00345 )
00346
00347
00348 {
00349 if(!fSession) {
00350 MsgStream log(messageService(), Service::name());
00351 log << MSG::INFO << "No ISession given " << endreq;
00352 return 0;
00353 }
00354 IUI* ui = findUI();
00355 if(!ui) return 0;
00356 return ui_SoPage(*ui);
00357 }
00359 SoRegion* OnXSvc::currentSoRegion(
00360 )
00361
00362
00363 {
00364 SoPage* soPage = currentSoPage();
00365 if(!soPage) {
00366 MsgStream log(messageService(), Service::name());
00367 log << MSG::INFO << "SoPage not found " << endreq;
00368 return 0;
00369 }
00370 return page_currentRegion(*soPage);
00371 }
00373 IWidget* OnXSvc::currentWidget(
00374 )
00375
00376
00377 {
00378 if(!fSession) {
00379 MsgStream log(messageService(), Service::name());
00380 log << MSG::INFO << "No ISession given " << endreq;
00381 return 0;
00382 }
00383 IUI* ui = findUI();
00384 if(!ui) return 0;
00385 return ui->currentWidget();
00386 }
00388 Slash::Data::IProcessor* OnXSvc::typeManager(
00389 )
00390
00391
00392 {
00393 return fTypeManager;
00394 }
00396 Slash::Data::IAccessor* OnXSvc::metaType(
00397 )
00398
00399
00400 {
00401 return fMetaType;
00402 }
00406 void OnXSvc::setSession(
00407 Slash::Core::ISession* aSession
00408 )
00409
00410
00411
00413 {
00414 if(fSession) return;
00415 if(!aSession) return;
00416 fSession = aSession;
00417
00418 fSession->addManager(new SvcLocatorManager(serviceLocator()));
00419
00420 fTypeManager =
00421 Lib_findManager(*fSession,"AccessorManager",Slash::Data::IProcessor);
00422
00423 if(fTypeManager) {
00424 std::vector<Slash::Data::IAccessor*>::const_iterator it;
00425 for(it=fTypes.begin(); it!=fTypes.end(); it++) {
00426 fTypeManager->addAccessor(*it);
00427 }
00428 fTypes.clear();
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 }
00444
00445 }
00447 ISession* OnXSvc::session(
00448 )
00449
00450
00451 {
00452 return fSession;
00453 }
00455 void OnXSvc::nextEvent(
00456 )
00457
00458
00459 {
00460 if(!fAppMgrUI) return;
00461 fAppMgrUI->nextEvent(1);
00462 }
00464 void OnXSvc::eventInfo(
00465 )
00466
00467
00468 {
00469 MsgStream log(messageService(), Service::name());
00470
00471 if(!fSession) {
00472 log << MSG::INFO << "No ISession given " << endreq;
00473 return;
00474 }
00475
00476 if(!fEventDataSvc) {
00477 StatusCode status = service("EventDataSvc",fEventDataSvc,true);
00478 if(status.isFailure() || !fEventDataSvc) {
00479 log << MSG::INFO << "EventDataSvc not found " << endreq;
00480 return;
00481 }
00482 fEventDataSvc->addRef();
00483 }
00484
00485
00486
00487
00488 DataObject* dataObject;
00489 StatusCode sc = fEventDataSvc->retrieveObject("/Event", dataObject);
00490 if(!sc.isSuccess()) {
00491 log << MSG::ERROR << "Unable to retrieve /Event " << endreq;
00492 return;
00493 }
00494 if(!dataObject) {
00495 log << MSG::ERROR << "Unable to retrieve /Event " << endreq;
00496 return;
00497 }
00498
00499
00500
00501
00502 }
00504 StatusCode OnXSvc::visualize(
00505 const DataObject& aDataObject
00506 )
00507
00508
00509 {
00510 MsgStream log(messageService(), Service::name());
00511
00512 log << MSG::INFO << " visualize DataObject... " << endreq;
00513
00514 if(!fSoCnvSvc) {
00515 StatusCode status = service("SoConversionSvc",fSoCnvSvc,true);
00516 if(status.isFailure() || !fSoCnvSvc) {
00517 log << MSG::INFO << "SoConversionSvc not found " << endreq;
00518 return StatusCode::FAILURE;
00519 }
00520 fSoCnvSvc->addRef();
00521 }
00522
00523 try {
00524 IOpaqueAddress* addr = 0;
00525 fCuts = "";
00526 StatusCode sc = fSoCnvSvc->createRep ((DataObject*)&aDataObject, addr);
00527 fCuts = "";
00528 if (sc.isSuccess())
00529 sc = fSoCnvSvc->fillRepRefs(addr,(DataObject*)&aDataObject);
00530 if (sc.isFailure()) {
00531 log << MSG::WARNING
00532 << "Error creating graphical representations"
00533 << endreq;
00534 return sc;
00535 }
00536 } catch (GaudiException e) {
00537 fCuts = "";
00538 log << MSG::ERROR
00539 << "Unable to create graphical representation, received exception :";
00540 e.printOut(log);
00541 log << endreq;
00542 return StatusCode::FAILURE;
00543 }
00544
00545 return StatusCode::SUCCESS;
00546 }
00548 StatusCode OnXSvc::visualize(
00549 const AIDA::IHistogram& aHistogram
00550 )
00551
00552
00553 {
00554 MsgStream log(messageService(), Service::name());
00555
00556 const DataObject* dataObject = dynamic_cast<const DataObject*>(&aHistogram);
00557 if(!dataObject) {
00558 log << MSG::ERROR << "histogram not a DataObject." << endreq;
00559 return StatusCode::FAILURE;
00560 }
00561
00562 return visualize(*dataObject);
00563 }
00565 IDataProviderSvc* OnXSvc::dataProvider(const std::string& aPath)
00566
00567
00568 {
00569 MsgStream log(messageService(), Service::name());
00570 if(aPath.find_first_of("E", 1) == 1) {
00571 if(!fEventDataSvc) {
00572 StatusCode status = service("EventDataSvc",fEventDataSvc,true);
00573 if(status.isFailure() || !fEventDataSvc) {
00574 log << MSG::INFO << "EventDataSvc not found " << endreq;
00575 return 0;
00576 }
00577 fEventDataSvc->addRef();
00578 }
00579 return fEventDataSvc;
00580 } else if( aPath.find_first_of("d", 1) == 1) {
00581 if(!fDetectorDataSvc) {
00582 StatusCode status = service("DetectorDataSvc",fDetectorDataSvc,true);
00583 if(status.isFailure() || !fDetectorDataSvc) {
00584 log << MSG::INFO << "DetectorDataSvc not found " << endreq;
00585 return 0;
00586 }
00587 fDetectorDataSvc->addRef();
00588 }
00589 return fDetectorDataSvc;
00590 } else if(aPath.find_first_of("s",1)==1) {
00591 if(!fHistogramSvc) {
00592 StatusCode status = service("HistogramDataSvc",fHistogramSvc,true);
00593 if(status.isFailure() || !fHistogramSvc) {
00594 log << MSG::INFO << "HistogramDataSvc not found " << endreq;
00595 return 0;
00596 }
00597 fHistogramSvc->addRef();
00598 }
00599 return fHistogramSvc;
00600 } else {
00601 log << MSG::INFO
00602 << "Data service not found for \"" << aPath << "\"."
00603 << endreq;
00604 return 0;
00605 }
00606 }
00608 StatusCode OnXSvc::visualize(
00609 const std::string& aWhat
00610 )
00611
00612
00613 {
00614 MsgStream log(messageService(), Service::name());
00615
00616 if(!fSoCnvSvc) {
00617 StatusCode status = service("SoConversionSvc",fSoCnvSvc,true);
00618 if(status.isFailure() || !fSoCnvSvc) {
00619 log << MSG::INFO << "SoConversionSvc not found " << endreq;
00620 return StatusCode::FAILURE;
00621 }
00622 fSoCnvSvc->addRef();
00623 }
00624
00625 StatusCode sc = StatusCode::FAILURE;
00626
00627 std::string path = aWhat;
00628 std::string cuts;
00629
00630 std::string::size_type sp;
00631 if((sp=aWhat.find(' '))!=std::string::npos){
00632 path = aWhat.substr(0,sp);
00633 cuts = aWhat.substr(sp+1,aWhat.size()-(sp+1));
00634 }
00635 log << MSG::INFO << "Path \"" << path << "\"" << endreq;
00636 log << MSG::INFO << "Cuts \"" << cuts << "\"" << endreq;
00637
00638 IDataProviderSvc* dataSvc = dataProvider(path);
00639 if(!dataSvc) return StatusCode::FAILURE;
00640
00641 DataObject* dataObject = 0;
00642 sc = dataSvc->retrieveObject(path, dataObject);
00643 if(!sc.isSuccess()) {
00644 log << MSG::ERROR << "Unable to retrieve " << path << endreq;
00645 return sc;
00646 }
00647 if(!dataObject) {
00648 log << MSG::ERROR << "Unable to retrieve " << path << endreq;
00649 return StatusCode::FAILURE;
00650 }
00651
00652 try {
00653 IOpaqueAddress* addr = 0;
00654 fCuts = cuts;
00655 sc = fSoCnvSvc->createRep(dataObject,addr);
00656 fCuts = "";
00657 if (sc.isSuccess()) sc = fSoCnvSvc->fillRepRefs(addr,dataObject);
00658 if (sc.isFailure()) {
00659 log << MSG::WARNING
00660 << "Error creating graphical representations" << endreq;
00661 return sc;
00662 }
00663 } catch (GaudiException e) {
00664 fCuts = "";
00665 log << MSG::ERROR << "Unable to convert : "
00666 << path << endreq;
00667 return StatusCode::FAILURE;
00668 }
00669
00670 return StatusCode::SUCCESS;
00671 }
00675 std::vector<std::string> OnXSvc::dataChildren(const std::string& aPath)
00676
00677
00678 {
00679 MsgStream log(messageService(), Service::name());
00680
00681 std::vector<std::string> text;
00682
00683 IDataProviderSvc* dataSvc = dataProvider(aPath);
00684 if(!dataSvc) return text;
00685 SmartIF<IDataManagerSvc> dataManagerSvc(dataSvc);
00686 if(dataManagerSvc==0) {
00687 log << MSG::ERROR
00688 << "Unable to get DataManager interface."
00689 << endreq;
00690 return text;
00691 }
00692
00693 SmartDataPtr<DataObject> dataObject(dataSvc,aPath);
00694 if(dataObject==0) {
00695 log << MSG::ERROR
00696 << "Can't get \"" << aPath << "\"."
00697 << endreq;
00698 return text;
00699 }
00700
00701 std::vector<IRegistry*> children;
00702 dataManagerSvc->objectLeaves(dataObject->registry(),children);
00703 std::vector<IRegistry*>::iterator it;
00704 for (it = children.begin();it != children.end();it++) {
00705 text.push_back((*it)->identifier());
00706 }
00707
00708 return text;
00709 }
00713 bool OnXSvc::ls (
00714 IDataProviderSvc* aDataSvc
00715 ,SmartIF<IDataManagerSvc>& aDataManagerSvc
00716 ,SmartDataPtr<DataObject>& aDataObject
00717 ,MsgStream& aLog
00718 ,int aWantedDepth
00719 ,int& aDepth
00720 )
00721
00722
00723 {
00724 if((aWantedDepth!=-1)&&(aDepth>=aWantedDepth)) return true;
00725
00726 std::vector<IRegistry*> children;
00727 aDataManagerSvc->objectLeaves(aDataObject->registry(),children);
00728 std::vector<IRegistry*>::iterator it;
00729 for (it = children.begin();it != children.end();it++) {
00730 try {
00731
00732 aLog << MSG::INFO << (*it)->identifier() << endreq;
00733 SmartDataPtr<DataObject> obj(aDataSvc,(*it));
00734
00735 if(obj) {
00736 aDepth++;
00737 if(!ls(aDataSvc,aDataManagerSvc,obj,aLog,aWantedDepth,aDepth))
00738 return false;
00739 aDepth--;
00740 } else {
00741 aLog << MSG::ERROR
00742 << "Unable to load \"" << (*it)->identifier() << "\"." << endreq;
00743 }
00744
00745 } catch (GaudiException e) {
00746 aLog << MSG::ERROR
00747 << "Unable to load \"" << (*it)->identifier() << "\"." << endreq;
00748 return false;
00749 }
00750
00751 }
00752
00753 return true;
00754 }
00756 void OnXSvc::ls (
00757 const std::string& aPath
00758 ,int aDepth
00759 )
00760
00761
00762 {
00763 MsgStream log(messageService(), Service::name());
00764
00765 IDataProviderSvc* dataSvc = dataProvider(aPath);
00766 if(!dataSvc) return;
00767 SmartIF<IDataManagerSvc> dataManagerSvc(dataSvc);
00768 if (dataManagerSvc==0) {
00769 log << MSG::ERROR
00770 << "Unable to get DataManager interface "
00771 << endreq;
00772 return;
00773 }
00774
00775 SmartDataPtr<DataObject> dataObject(dataSvc,aPath);
00776 if(dataObject==0) {
00777 log << MSG::ERROR
00778 << "Can't get \"" << aPath << "\"."
00779 << endreq;
00780 return;
00781 }
00782
00783 log << MSG::INFO << aPath << endreq;
00784
00785 int depth = 0;
00786 ls(dataSvc,dataManagerSvc,dataObject,log,aDepth,depth);
00787 }
00791 void OnXSvc::clearDetectorStore(
00792 )
00793
00794
00795 {
00796 MsgStream log(messageService(), Service::name());
00797
00798 if(!fDetectorDataSvc) {
00799 StatusCode status = service("DetectorDataSvc",fDetectorDataSvc,true);
00800 if(status.isFailure() || !fDetectorDataSvc) {
00801 log << MSG::INFO << "DetectorDataSvc not found " << endreq;
00802 return;
00803 }
00804 fDetectorDataSvc->addRef();
00805 }
00806
00807 SmartIF<IDataManagerSvc> dm(fDetectorDataSvc);
00808 if(dm==0) {
00809 log << MSG::ERROR << "No DataManagerSvc. Store not cleared." << endreq;
00810 return;
00811 }
00812
00813 IXmlSvc* xs = 0;
00814 service ("XmlCnvSvc", xs);
00815 if(!xs) {
00816 log << MSG::ERROR << "No XmlCnvSvc. Store not cleared." << endreq;
00817 return;
00818 }
00819
00820 IVisualizationSvc* vs = 0;
00821 service ("VisualizationSvc", vs);
00822 if(!vs) {
00823 log << MSG::WARNING
00824 << "No VisualizationSvc. Visualization attributes not reloaded."
00825 << endreq;
00826 return;
00827 }
00828
00829 StatusCode sc = dm->clearStore();
00830 if (!sc.isSuccess()) {
00831 log << MSG::ERROR << "Unable to clear store !!!" << endreq;
00832 return;
00833 }
00834 xs->clearCache();
00835 vs->reload();
00836 }
00838 StatusCode OnXSvc::changeGeometry(const std::string& file)
00841 {
00842 MsgStream log(messageService(), Service::name());
00843
00844
00845 IProperty* pdm = 0;
00846 service ("DetectorDataSvc", pdm);
00847 if(!pdm) {
00848 log << MSG::ERROR
00849 << "No DetectorDataSvc found (Looking for IProperty Interface)."
00850 << endreq;
00851 return StatusCode::FAILURE;
00852 }
00853 pdm->setProperty("DetDbLocation", file);
00854
00855
00856 IService* dm = 0;
00857 service ("DetectorDataSvc", dm);
00858 if(!dm) {
00859 log << MSG::ERROR << "No DetectorDataSvc found." << endreq;
00860 return StatusCode::FAILURE;
00861 }
00862
00863 IService* xs = 0;
00864 service ("XmlCnvSvc", xs);
00865 if(!xs) {
00866 log << MSG::ERROR << "No XmlCnvSvc found." << endreq;
00867 return StatusCode::FAILURE;
00868 }
00869
00870 StatusCode sc = dm->reinitialize();
00871 if (!sc.isSuccess()) {
00872 log << MSG::ERROR << "Unable to reinitialize DetectorDataSvc !" << endreq;
00873 return sc;
00874 }
00875 sc = xs->reinitialize();
00876 if (!sc.isSuccess()) {
00877 log << MSG::ERROR << "Unable to reinitialize XmlCnvSvc !" << endreq;
00878 return sc;
00879 }
00880 return StatusCode::SUCCESS;
00881 }
00883 StatusCode OnXSvc::changeColors(const std::string& file)
00886 {
00887 MsgStream log(messageService(), Service::name());
00888
00889
00890 IProperty* pvs = 0;
00891 service ("VisualizationSvc", pvs);
00892 if(!pvs) {
00893 log << MSG::ERROR
00894 << "No VisualizationSvc found (Looking for IProperty Interface)."
00895 << endreq;
00896 return StatusCode::FAILURE;
00897 }
00898 pvs->setProperty("ColorDbLocation", file);
00899
00900
00901 IService* vs = 0;
00902 service ("VisualizationSvc", vs);
00903 if(!vs) {
00904 log << MSG::WARNING << "No VisualizationSvc found." << endreq;
00905 return StatusCode::FAILURE;
00906 }
00907
00908 StatusCode sc = vs->reinitialize();
00909 if (!sc.isSuccess()) {
00910 log << MSG::ERROR << "Unable to reinitialize VisualizationSvc !" << endreq;
00911 return sc;
00912 }
00913 return StatusCode::SUCCESS;
00914 }
00916 void OnXSvc::openEventFile(
00917 const std::string& aFile
00918 )
00921 {
00922 if(aFile=="") return;
00923
00924 MsgStream log(messageService(), Service::name());
00925
00926 log << MSG::INFO << "Try to open " << aFile << "..." << endreq;
00927
00928 IEvtSelector* eventSelector = 0;
00929 StatusCode status = service("EventSelector",eventSelector,true);
00930 if(status.isFailure() || !eventSelector) {
00931 log << MSG::INFO << "EventSelector not found " << endreq;
00932 return;
00933
00934 }
00935 eventSelector->addRef();
00936
00937 SmartIF<IProperty> prp(eventSelector);
00938 std::string prop =
00939 std::string("[\"DATAFILE='") + aFile + "' TYP='ROOT' OPT='READ'\"]";
00940
00941 prp->setProperty("Input",prop);
00942 SmartIF<IService> prp2(eventSelector);
00943 prp2->reinitialize();
00944
00945 eventSelector->release();
00946
00947 IService* eventLoopMgr = 0;
00948 status = service("EventLoopMgr",eventLoopMgr,true);
00949 if(status.isFailure() || !eventLoopMgr) {
00950 log << MSG::INFO << "EventLoopMgr not found " << endreq;
00951 return;
00952 }
00953 eventLoopMgr->addRef();
00954 eventLoopMgr->reinitialize();
00955 eventLoopMgr->release();
00956 }
00960 bool OnXSvc::visitToXML(
00961 IDataProviderSvc* aDataSvc
00962 ,SmartIF<IDataManagerSvc>& aDataManagerSvc
00963 ,SmartDataPtr<DataObject>& aDataObject
00964 ,std::string& aOut
00965 )
00966
00967
00968 {
00969 std::vector<IRegistry*> children;
00970 aDataManagerSvc->objectLeaves(aDataObject->registry(), children);
00971 std::vector<IRegistry*>::iterator it;
00972 for(it=children.begin();it != children.end();it++) {
00973
00974 std::string path = (*it)->identifier();
00975 std::string name = path;
00976 {std::string::size_type pos = path.find_last_of("/");
00977 if(pos!=std::string::npos) name = path.substr(pos+1,path.size()-pos);}
00978
00979 aOut += "<treeItem><label>" + name + "</label>";
00980
00981 try {
00982
00983 SmartDataPtr<DataObject> obj(aDataSvc,(*it));
00984 if(obj) {
00985 if(!visitToXML(aDataSvc,aDataManagerSvc,obj,aOut)) {
00986 aOut = "";
00987 return false;
00988 }
00989 } else {
00990 MsgStream log(messageService(), Service::name());
00991 log << MSG::ERROR
00992 << "Unable to load \"" << (*it)->identifier() << "\"."
00993 << endreq;
00994 }
00995
00996 } catch (GaudiException e) {
00997 MsgStream log(messageService(), Service::name());
00998 log << MSG::ERROR
00999 << "Unable to load \"" << (*it)->identifier() << "\"."
01000 << endreq;
01001 aOut = "";
01002 return false;
01003 }
01004
01005 aOut += "</treeItem>";
01006 }
01007
01008 return true;
01009 }
01011 bool OnXSvc::writeToString(
01012 const std::string& aPath
01013 ,std::string& aOut
01014 )
01015
01016
01017 {
01018 aOut = "";
01019 if(!fSession) return false;
01020 MsgStream log(messageService(), Service::name());
01021
01022 IDataProviderSvc* dataSvc = dataProvider(aPath);
01023 if(!dataSvc) return false;
01024 SmartIF<IDataManagerSvc> dataManagerSvc(dataSvc);
01025 if (dataManagerSvc==0) {
01026 log << MSG::ERROR
01027 << "Unable to get DataManager interface "
01028 << endreq;
01029 return false;
01030 }
01031
01032 SmartDataPtr<DataObject> dataObject(dataSvc,aPath);
01033 if(dataObject==0) {
01034 log << MSG::ERROR
01035 << "Can't get \"" << aPath << "\"."
01036 << endreq;
01037 return false;
01038 }
01039
01040 aOut = "<tree>";
01041
01042 std::string name = aPath;
01043 {std::string::size_type pos = aPath.find_last_of("/");
01044 if(pos!=std::string::npos) name = aPath.substr(pos+1,aPath.size()-pos);}
01045 aOut += "<treeItem><label>" + name + "</label>";
01046
01047 if(!visitToXML(dataSvc,dataManagerSvc,dataObject,aOut)) return false;
01048
01049 aOut += "</treeItem>";
01050 aOut += "</tree>";
01051 return true;
01052 }
01056 void OnXSvc::addType(
01057 Slash::Data::IAccessor* aType
01058 )
01061 {
01062 if(!aType) return;
01063 if(!fSession) {
01064
01065 fTypes.push_back(aType);
01066 } else {
01067 if(!fTypeManager) return;
01068 fTypeManager->addAccessor(aType);
01069 }
01070 }
01072 IService* OnXSvc::getService(
01073 const std::string& aName
01074 )
01075
01076
01077 {
01078 MsgStream log(messageService(), Service::name());
01079 if(!serviceLocator()) {
01080 log << MSG::INFO << "service locator not found " << endreq;
01081 return 0;
01082 }
01083 IService* svc = 0;
01084 StatusCode status = serviceLocator()->service(aName,svc);
01085 if(status.isFailure() || !svc) {
01086 log << MSG::INFO << aName << " not found " << endreq;
01087 return 0;
01088 }
01089 return svc;
01090 }
01092 const std::string& OnXSvc::cuts(
01093 ) const
01096 {
01097 return fCuts;
01098 }
01100 Slash::Core::IWriter& OnXSvc::printer(
01101 )
01104 {
01105 return fGaudiPrinter ? *fGaudiPrinter : *fLibPrinter;
01106 }
01107
01109 std::string OnXSvc::torgb(
01110 const std::string& aColor
01111 )
01112
01113
01114 {
01115 double r,g,b;
01116 if(!Lib::smanip::torgb(aColor,r,g,b)) return "";
01117 std::string s;
01118 Lib::smanip::printf(s,128,"%g %g %g",r,g,b);
01119 return s;
01120 }
01122 void* OnXSvc::topointer(
01123 const std::string& aValue
01124 ) const
01127 {
01128 void* p;
01129 Lib::smanip::topointer(aValue,p);
01130 return p;
01131 }
01133 IAppMgrUI* OnXSvc::appMgr(
01134 ) const
01137 {
01138 return fAppMgrUI;
01139 }
01141 Slash::UI::IUI* OnXSvc::findUI(
01142 )
01143
01144
01145 {
01146 if(!fSession) {
01147 MsgStream log(messageService(), Service::name());
01148 log << MSG::INFO << "No ISession given " << endreq;
01149 return 0;
01150 }
01151 Slash::UI::IUI_Manager* uiManager =
01152 Lib_findManager(*fSession,"UI_Manager",Slash::UI::IUI_Manager);
01153 if(!uiManager) {
01154 MsgStream log(messageService(), Service::name());
01155 log << MSG::INFO << "UI manager not found " << endreq;
01156 return 0;
01157 }
01158 IUI* ui = uiManager->find("default");
01159 if(!ui) {
01160 MsgStream log(messageService(), Service::name());
01161 log << MSG::INFO << "UI not found " << endreq;
01162 return 0;
01163 }
01164 return ui;
01165 }
01166
01170
01171
01172 #include <Inventor/SbPlane.h>
01173 #include <Inventor/nodes/SoSeparator.h>
01174 #include <Inventor/nodes/SoLightModel.h>
01175 #include <Inventor/nodes/SoDrawStyle.h>
01176 #include <Inventor/nodes/SoNormalBinding.h>
01177
01178
01179 #include <HEPVis/SbStyle.h>
01180 #include <HEPVis/nodes/SoHighlightMaterial.h>
01181 #include <HEPVis/misc/SoTools.h>
01182
01183
01184 #include <SoUtils/SbProjector.h>
01185
01187 SbMarkerStyle SoTools_markerStyle (
01188 const std::string& aString
01189 )
01192 {
01193 SbStyle sbStyle;
01194 std::string s = "markerStyle " + aString;
01195 sbStyle.setFromString(s.c_str());
01196 return sbStyle.getMarkerStyle();
01197 }
01202 StatusCode OnXSvc::visualize(
01203 const Gaudi::XYZPoint& aData
01204 )
01205
01206
01207 {
01208 MsgStream log(messageService(), Service::name());
01209 log << MSG::INFO << " visualize Gaudi::XYZPoint... " << endreq;
01210
01211 SoRegion* region = currentSoRegion();
01212 if(!region) {
01213 log << MSG::INFO << " can't get viewing region." << endreq;
01214 return StatusCode::FAILURE;
01215 }
01216
01217 double r = 0.5, g = 0.5, b = 0.5;
01218 double hr = 1.0, hg = 1.0, hb = 0.0;
01219 std::string value;
01220 if(fSession->parameterValue("modeling.color",value))
01221 Lib::smanip::torgb(value,r,g,b);
01222 if(fSession->parameterValue("modeling.highlightColor",value))
01223 Lib::smanip::torgb(value,hr,hg,hb);
01224
01225 fSession->parameterValue("modeling.projection",value);
01226 SoUtils::SbProjector projector(value.c_str());
01227
01228 SbMarkerStyle mStyle = SbMarkerPlus;
01229 if(fSession->parameterValue("modeling.markerStyle",value))
01230 mStyle = SoTools_markerStyle(value);
01231 int mSize = 5;
01232 if(fSession->parameterValue("modeling.markerSize",value))
01233 if(!Lib::smanip::toint(value,mSize)) mSize = 5;
01234
01235 SoSeparator* separator = new SoSeparator;
01236 separator->setName("sceneGraph");
01237
01238
01239 SoHighlightMaterial* highlightMaterial = new SoHighlightMaterial;
01240 highlightMaterial->setName("highlight");
01241 highlightMaterial->diffuseColor.setValue
01242 (SbColor(float(r),float(g),float(b)));
01243 highlightMaterial->highlightColor.setValue
01244 (SbColor(float(hr),float(hg),float(hb)));
01245
01246 separator->addChild(highlightMaterial);
01247
01248 SbVec3f point;
01249 point.setValue((float)aData.x(), (float)aData.y(), (float)aData.z());
01250 projector.project(1,&point);
01251
01252 SoTools::addPointsToNode(separator,1,&point,mStyle,mSize);
01253
01254
01255
01256 region_addToDynamicScene(*region,separator);
01257
01258 return StatusCode::SUCCESS;
01259 }
01261 StatusCode OnXSvc::visualize(
01262 const std::vector<Gaudi::XYZPoint>& aData
01263 ,RepType aType
01264 )
01265
01266
01267 {
01268 MsgStream log(messageService(), Service::name());
01269 log << MSG::INFO << " visualize std::vector<Gaudi::XYZPoint>... " << endreq;
01270
01271 if(!aData.size()) return StatusCode::SUCCESS;
01272 if((aType==POLYGON)&&(aData.size()<=2)) return StatusCode::FAILURE;
01273
01274 SoRegion* region = currentSoRegion();
01275 if(!region) {
01276 log << MSG::INFO << " can't get viewing region." << endreq;
01277 return StatusCode::FAILURE;
01278 }
01279
01280 double r = 0.5, g = 0.5, b = 0.5;
01281 double hr = 1.0, hg = 1.0, hb = 0.0;
01282 std::string value;
01283 if(fSession->parameterValue("modeling.color",value))
01284 Lib::smanip::torgb(value,r,g,b);
01285 if(fSession->parameterValue("modeling.highlightColor",value))
01286 Lib::smanip::torgb(value,hr,hg,hb);
01287
01288 fSession->parameterValue("modeling.projection",value);
01289 SoUtils::SbProjector projector(value.c_str());
01290
01291 int pointn = aData.size();
01292 SbVec3f* points = new SbVec3f[pointn];
01293 for(int index=0;index<pointn;index++) {
01294 points[index].setValue
01295 ((float)aData[index].x(),(float)aData[index].y(),(float)aData[index].z());
01296 }
01297 projector.project(pointn,points);
01298
01299 SoSeparator* separator = new SoSeparator;
01300 separator->setName("sceneGraph");
01301
01302
01303 SoHighlightMaterial* highlightMaterial = new SoHighlightMaterial;
01304 highlightMaterial->setName("highlight");
01305 highlightMaterial->diffuseColor.setValue
01306 (SbColor((float)r,(float)g,(float)b));
01307 highlightMaterial->highlightColor.setValue
01308 (SbColor((float)hr,(float)hg,(float)hb));
01309
01310 separator->addChild(highlightMaterial);
01311
01312 switch(aType) {
01313 case POINTS: {
01314 SbMarkerStyle mStyle = SbMarkerPlus;
01315 if(fSession->parameterValue("modeling.markerStyle",value))
01316 mStyle = SoTools_markerStyle(value);
01317 int mSize = 5;
01318 if(fSession->parameterValue("modeling.markerSize",value))
01319 if(!Lib::smanip::toint(value,mSize)) mSize = 5;
01320 SoTools::addPointsToNode(separator,pointn,points,mStyle,mSize);
01321 }break;
01322 case LINES: {
01323 SoLightModel* lightModel = new SoLightModel;
01324 lightModel->model = SoLightModel::BASE_COLOR;
01325 separator->addChild(lightModel);
01326
01327 SoDrawStyle* drawStyle = new SoDrawStyle;
01328 drawStyle->style.setValue(SoDrawStyle::LINES);
01329 drawStyle->linePattern.setValue(0xFFFF);
01330 separator->addChild(drawStyle);
01331
01332 SoTools::addLinesToNode(separator,pointn,points);
01333 }break;
01334 case SEGMENTS: {
01335 SoLightModel* lightModel = new SoLightModel;
01336 lightModel->model = SoLightModel::BASE_COLOR;
01337 separator->addChild(lightModel);
01338
01339 SoDrawStyle* drawStyle = new SoDrawStyle;
01340 drawStyle->style.setValue(SoDrawStyle::LINES);
01341 drawStyle->linePattern.setValue(0xFFFF);
01342 separator->addChild(drawStyle);
01343
01344 SoTools::addSegmentsToNode(separator,pointn,points);
01345 }break;
01346 case POLYGON: {
01347 SoLightModel* lightModel = new SoLightModel;
01348 lightModel->model = SoLightModel::PHONG;
01349 separator->addChild(lightModel);
01350
01351 SoDrawStyle* drawStyle = new SoDrawStyle;
01352 drawStyle->style.setValue(SoDrawStyle::FILLED);
01353 separator->addChild(drawStyle);
01354
01355 SoNormalBinding* normalBinding = new SoNormalBinding;
01356 normalBinding->value=SoNormalBinding::PER_FACE;
01357 separator->addChild(normalBinding);
01358
01359
01360
01361
01362 SbPlane plane(points[0],points[1],points[2]);
01363 SbVec3f normal = plane.getNormal();
01364 if(normal.length()<=0) normal.setValue(0,0,1);
01365 SoTools::addPolygonToNode(separator,pointn,points,normal);
01366 }break;
01367 }
01368
01369
01370
01371 region_addToDynamicScene(*region,separator);
01372
01373 delete [] points;
01374
01375 return StatusCode::SUCCESS;
01376 }
01377 #include <Inventor/nodes/SoShape.h>
01378 #include <Inventor/actions/SoSearchAction.h>
01380 std::vector<std::string> OnXSvc::getHighlightedSoShapeNames()
01381
01382
01384 {
01385 std::vector<std::string> names;
01386
01387 MsgStream log(messageService(), Service::name());
01388
01389 SoRegion* region = currentSoRegion();
01390 if(!region) {
01391 log << MSG::INFO << " can't get viewing region." << endreq;
01392 return names;
01393 }
01394
01395
01396
01397
01398 SoNode* node = region->findNode("part","topSeparator");
01399 if(!node) {
01400 log << MSG::INFO << " part not found." << endreq;
01401 return names;
01402 }
01403
01404
01405 SbBool oldsearch = SoBaseKit::isSearchingChildren();
01406 SoBaseKit::setSearchingChildren(TRUE);
01407 SoSearchAction searchAction;
01408 searchAction.setFind(SoSearchAction::NAME);
01409 searchAction.setName("sceneGraph");
01410
01411 searchAction.setInterest(SoSearchAction::ALL);
01412 searchAction.apply(node);
01413 SoBaseKit::setSearchingChildren(oldsearch);
01414
01415 SoPathList& pathList = searchAction.getPaths();
01416 unsigned int number = pathList.getLength();
01417
01418 for(unsigned int index=0;index<number;index++) {
01419 SoFullPath* path = (SoFullPath*)pathList[index];
01420
01421 SoNode* sep_sceneGraph = path->getTail();
01422
01423
01424 bool highlighted = false;
01425 {SoSearchAction searchAction;
01426 searchAction.setFind(SoSearchAction::TYPE);
01427 searchAction.setType(SoHighlightMaterial::getClassTypeId());
01428 searchAction.apply(sep_sceneGraph);
01429 SoPath* path = searchAction.getPath();
01430 if(path) {
01431 SoHighlightMaterial* material = (SoHighlightMaterial*)path->getTail();
01432 if(material->getSavedMaterial()) highlighted = true;
01433 }}
01434
01435 if(highlighted) {
01436 SoSearchAction searchAction;
01437 searchAction.setFind(SoSearchAction::TYPE);
01438 searchAction.setType(SoShape::getClassTypeId());
01439 searchAction.apply(sep_sceneGraph);
01440 SoPath* path = searchAction.getPath();
01441 std::string spath = path ? path->getTail()->getName().getString():"nil";
01442
01443 names.push_back(spath);
01444 }
01445
01446 }
01447
01448 return names;
01449 }
01451 std::vector<ContainedObject*> OnXSvc::getHighlightedContainedObject(
01452 )
01455 {
01456 MsgStream log(messageService(), Service::name());
01457
01458 std::vector<ContainedObject*> objs;
01459
01460 std::vector<std::string> names = getHighlightedSoShapeNames();
01461 std::vector<std::string>::const_iterator it;
01462 for(it=names.begin();it!=names.end(); it++) {
01463
01464 std::vector<std::string> fields;
01465 Lib::smanip::words(*it,"/",fields);
01466 if(fields.size()<=1) {
01467 log << MSG::INFO << " bad syntax in " << (*it) << "." << endreq;
01468 objs.clear();
01469 break;
01470 }
01471
01472
01473
01474 std::string sid = fields[1];
01475 void* id = 0;
01476 if(!Lib::smanip::topointer(sid,id)) {
01477 log << MSG::INFO << " bad syntax in " << sid << "." << endreq;
01478 objs.clear();
01479 break;
01480 }
01481
01482
01483
01484 objs.push_back((ContainedObject*)id);
01485
01486
01487 }
01488
01489 return objs;
01490 }
01491