| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

SoHistogramCnv.cpp

Go to the documentation of this file.
00001 
00002 // this :
00003 #include "SoHistogramCnv.h"
00004 
00005 // AIDA :
00006 #include <AIDA/IHistogram1D.h>
00007 #include <AIDA/IHistogram2D.h>
00008 
00009 // Gaudi :
00010 #include <GaudiKernel/ISvcLocator.h>
00011 #include <GaudiKernel/IService.h>
00012 #include <GaudiKernel/MsgStream.h>
00013 #include <GaudiKernel/CnvFactory.h>
00014 #include <GaudiKernel/DataObject.h>
00015 
00016 // OnXSvc :
00017 #include <OnXSvc/IUserInterfaceSvc.h>
00018 #include <OnXSvc/ClassID.h>
00019 
00020 // RootSvc :
00021 //#601 #include <RootSvc/IRootSvc.h>
00022 
00023 // HEPVis :
00024 #include <HEPVis/nodekits/SoPlotterRegion.h>
00025 #include <HEPVis/nodekits/SoPlotter.h>
00026 
00027 // OnX :
00028 #include <OnX/Interfaces/IWidget.h>
00029 #include <OnX/Interfaces/IWidgetClass.h>
00030 
00031 #include <TVirtualPad.h>
00032 #include <TH1D.h>
00033 #include <TH2D.h>
00034 #include "GaudiKernel/HistogramBase.h"
00035 
00036 DECLARE_CONVERTER_FACTORY(SoHistogramCnv);
00037 
00039 SoHistogramCnv::SoHistogramCnv(
00040  ISvcLocator* aSvcLoc
00041 ) 
00042 :Converter(So_TechnologyType,CLID_Histogram,aSvcLoc) 
00043 ,fUISvc(0)
00044 //#601,fRootSvc(0)
00047 {
00048 }
00050 StatusCode SoHistogramCnv::initialize(
00051 ) 
00052 
00053 
00054 {
00055   StatusCode status = Converter::initialize();
00056   if( status.isFailure() ) return status;
00057 
00058   MsgStream log(messageService(), "SoHistogramCnv");
00059 
00060   {if(fUISvc) {
00061     fUISvc->release();
00062     fUISvc = 0;
00063   }
00064   StatusCode status = service("OnXSvc",fUISvc,true);
00065   if(status.isFailure() || !fUISvc) {
00066     log << MSG::INFO << " OnXSvc not found " << endreq;
00067     return StatusCode::FAILURE;
00068   }  
00069   fUISvc->addRef();}
00070 
00071   return StatusCode::SUCCESS;
00072 }
00074 StatusCode SoHistogramCnv::finalize() 
00075 
00076 
00077 {
00078   if(fUISvc) {
00079     fUISvc->release();
00080     fUISvc = 0;
00081   }
00082 //#601  if(fRootSvc) {
00083 //#601    fRootSvc->release();
00084 //#601    fRootSvc = 0;
00085 //#601  }
00086   return StatusCode::SUCCESS;
00087 }
00089 long SoHistogramCnv::repSvcType() const
00092 {
00093   return i_repSvcType();
00094 }
00096 const CLID& SoHistogramCnv::classID(
00097 ) 
00098 
00099 
00100 { 
00101   return CLID_Histogram;
00102 }
00104 const unsigned char SoHistogramCnv::storageType(
00105 ) 
00106 
00107 
00108 { 
00109   return So_TechnologyType; 
00110 }
00112 StatusCode SoHistogramCnv::createRep(
00113  DataObject* aObject
00114 ,IOpaqueAddress*&
00115 ) 
00116 
00117 
00118 {
00119   MsgStream log(messageService(), "SoHistogramCnv");
00120   log << MSG::INFO << "Histogram createReps" << endreq;
00121 
00122   if(!aObject) {
00123     log << MSG::INFO << " NULL object." << endreq;
00124     return StatusCode::FAILURE; 
00125   }
00126 
00127   if(!fUISvc) {
00128     log << MSG::INFO << " OnXSvc not found " << endreq;
00129     return StatusCode::FAILURE;
00130   }  
00131 
00132   IWidget* widget = fUISvc->currentWidget();
00133   if(!widget) {
00134     log << MSG::INFO << " can't get current widget." << endreq;
00135     return StatusCode::FAILURE; 
00136   }
00137 
00138   if(widget->widgetClass().name()=="PageViewer") {
00139 
00140     SoRegion* soRegion = fUISvc->currentSoRegion();
00141     if(!soRegion) {
00142       log << MSG::INFO << " can't get SoRegion." << endreq;
00143       return StatusCode::FAILURE; 
00144     }
00145     if(!soRegion->isOfType(SoPlotterRegion::getClassTypeId())) {
00146       log << MSG::INFO << " region is not a SoPlotterRegion." << endreq;
00147       return StatusCode::FAILURE; 
00148     }
00149 
00150     if(AIDA::IHistogram1D* histogram = 
00151        dynamic_cast<AIDA::IHistogram1D*>(aObject)) {
00152       SbPlottableObject* sbPlottable =  
00153         new SoHistogramRep1D(aObject->name(),histogram);
00154       soRegion->doIt(SbPlotterDoIt(sbPlottable));
00155   
00156     } else if(AIDA::IHistogram2D* histogram = 
00157               dynamic_cast<AIDA::IHistogram2D*>(aObject)) {
00158       SbPlottableObject* sbPlottable =  
00159         new SoHistogramRep2D(aObject->name(),histogram);
00160       soRegion->doIt(SbPlotterDoIt(sbPlottable));
00161   
00162     } else {
00163       log << MSG::INFO 
00164           << " today only plotting of AIDA::IHistogram1D,2D supported." 
00165           << endreq;
00166       return StatusCode::FAILURE; 
00167     }
00168 
00169   } else if(widget->widgetClass().name()=="TCanvas") {
00170 
00171 //#601    if(!fRootSvc) {
00172 //#601      StatusCode status = service("RootSvc",fRootSvc,true);
00173 //#601      if(status.isFailure()  || !fRootSvc) {
00174 //#601        log << MSG::INFO << " OnXSvc not found " << endreq;
00175 //#601        return StatusCode::SUCCESS; //Not fatal.
00176 //#601      }
00177 //#601      fRootSvc->addRef();
00178 //#601    }
00179 
00180     if(AIDA::IHistogram* histogram = 
00181        dynamic_cast<AIDA::IHistogram*>(aObject)) {
00182   
00183 //#601      fRootSvc->visualize(*histogram);
00184 
00185     } else {
00186       log << MSG::INFO 
00187           << " object not an AIDA::IHistogram." 
00188           << endreq;
00189       return StatusCode::FAILURE; 
00190     }
00191 
00192   } else {
00193     log << MSG::INFO 
00194         << " viewer not a PageViewer or a TCanvas." 
00195         << endreq;
00196     return StatusCode::FAILURE; 
00197   }
00198 
00199   return StatusCode::SUCCESS;
00200 }
00204 // AIDA :
00205 #include <AIDA/IHistogram1D.h>
00206 #include <AIDA/IHistogram2D.h>
00207 #include <AIDA/IAxis.h>
00208 #include <AIDA/IAnnotation.h>
00209 
00210 // HEPVis :
00211 #include <HEPVis/SbPlottableThings.h>
00212 
00213 // Lib:
00214 #include <Lib/smanip.h>
00215 
00217 SoHistogramRep1D::SoHistogramRep1D(
00218  const std::string& aName
00219 ,const AIDA::IHistogram1D* aHistogram
00220 )
00221 :fName(aName)
00222 ,fHistogram(aHistogram)
00223 ,fDataClass("AIDA::IHistogram1D")
00226 {
00227 }
00229 SoHistogramRep1D::~SoHistogramRep1D(
00230 )
00233 {
00234 }
00236 bool SoHistogramRep1D::isValid(
00237 ) const
00240 {
00241   return true;
00242 }
00244 const char* SoHistogramRep1D::getName(
00245 )
00248 {
00249   return fName.c_str();
00250 }
00252 const char* SoHistogramRep1D::getLabel(
00253 )
00256 {
00257   fTitle = fHistogram->title(); 
00258   return fTitle.c_str(); 
00259 }
00261 int SoHistogramRep1D::getDimension(
00262 ) const
00265 {
00266   return fHistogram->dimension();
00267 }
00269 void* SoHistogramRep1D::cast(
00270  const char* aClass
00271 ) const
00274 {
00275   if(std::string(aClass)=="SbPlottableObject") {
00276     return (SbPlottableObject*)this;
00277   } else if(std::string(aClass)=="SbPlottableBins1D") {
00278     return (SbPlottableBins1D*)this;
00279   } else {
00280     return 0;
00281   }
00282 }
00284 void* SoHistogramRep1D::nativeObject(
00285 ) const
00288 {
00289   return (void*)fHistogram; 
00290 }
00292 const char* SoHistogramRep1D::nativeObjectClass(
00293 ) const
00296 {
00297   return fDataClass.c_str(); 
00298 }
00302 int SoHistogramRep1D::getAxisNumberOfBins(
00303 ) const
00306 {
00307   return fHistogram->axis().bins();
00308 }
00310 float SoHistogramRep1D::getAxisMinimum(
00311 ) const
00314 {
00315   return (float)fHistogram->axis().lowerEdge();
00316 }
00318 float SoHistogramRep1D::getAxisMaximum(
00319 ) const
00322 {
00323   return (float)fHistogram->axis().upperEdge();
00324 }
00326 void SoHistogramRep1D::getBinsSumOfWeightsRange(
00327  float& aMin
00328 ,float& aMax
00329 ) const
00332 {
00333   aMin = (float)fHistogram->minBinHeight();
00334   aMax = (float)fHistogram->maxBinHeight();
00335 }
00337 int SoHistogramRep1D::getBinNumberOfEntries(
00338  int aI
00339 ) const
00342 {
00343   return fHistogram->binEntries(aI);
00344 }
00346 float SoHistogramRep1D::getBinLowerEdge(
00347  int aI
00348 ) const
00351 {
00352   return (float)fHistogram->axis().binLowerEdge(aI);
00353 }
00355 float SoHistogramRep1D::getBinUpperEdge(
00356  int aI
00357 ) const
00360 {
00361   return (float)fHistogram->axis().binUpperEdge(aI);
00362 }
00364 float SoHistogramRep1D::getBinSumOfWeights(
00365  int aI
00366 ) const
00369 {
00370   return (float)fHistogram->binHeight(aI);
00371 }
00373 float SoHistogramRep1D::getBinBar(
00374  int aI
00375 ) const
00378 {
00379   return (float)fHistogram->binError(aI);
00380 }
00382 const char* SoHistogramRep1D::getInfos(
00383  const char* /* aOptions */
00384 )
00387 {
00388   Lib::smanip::printf(fInfos,6 * 64,
00389 "\
00390 N %d\n\
00391 I %d\n\
00392 m %g\n\
00393 r %g\n\
00394 u %d\n\
00395 o %d",fHistogram->allEntries()
00396      ,fHistogram->entries()
00397      ,fHistogram->mean()
00398      ,fHistogram->rms()
00399      ,fHistogram->binEntries(AIDA::IAxis::UNDERFLOW_BIN)
00400      ,fHistogram->binEntries(AIDA::IAxis::OVERFLOW_BIN));
00401   return fInfos.c_str();
00402 }
00404 const char* SoHistogramRep1D::getLegend(
00405 )
00408 {
00409   fLegend = fHistogram->annotation().value("Legend");
00410   return fLegend.c_str();
00411 }
00415 SoHistogramRep2D::SoHistogramRep2D(
00416  const std::string& aName
00417 ,const AIDA::IHistogram2D* aHistogram
00418 )
00419 :fName(aName)
00420 ,fHistogram(aHistogram)
00421 ,fDataClass("AIDA::IHistogram2D")
00424 {
00425 }
00427 SoHistogramRep2D::~SoHistogramRep2D(
00428 )
00431 {
00432 }
00434 bool SoHistogramRep2D::isValid(
00435 ) const
00438 {
00439   return true;
00440 }
00442 const char* SoHistogramRep2D::getName(
00443 )
00446 {
00447   return fName.c_str();
00448 }
00450 const char* SoHistogramRep2D::getLabel(
00451 )
00454 {
00455   fTitle = fHistogram->title(); 
00456   return fTitle.c_str(); 
00457 }
00459 int SoHistogramRep2D::getDimension(
00460 ) const
00463 {
00464   return fHistogram->dimension();
00465 }
00467 void* SoHistogramRep2D::nativeObject(
00468 ) const
00471 {
00472   return (void*)fHistogram; 
00473 }
00475 const char* SoHistogramRep2D::nativeObjectClass(
00476 ) const
00479 {
00480   return fDataClass.c_str(); 
00481 }
00483 void* SoHistogramRep2D::cast(
00484  const char* aClass
00485 ) const
00488 {
00489   if(std::string(aClass)=="SbPlottableObject") {
00490     return (SbPlottableObject*)this;
00491   } else if(std::string(aClass)=="SbPlottableBins2D") {
00492     return (SbPlottableBins2D*)this;
00493   } else {
00494     return 0;
00495   }
00496 }
00500 int SoHistogramRep2D::getAxisNumberOfBinsX(
00501 ) const
00504 {
00505   return fHistogram->xAxis().bins();
00506 }
00508 float SoHistogramRep2D::getAxisMinimumX(
00509 ) const
00512 {
00513   return (float)fHistogram->xAxis().lowerEdge();
00514 }
00516 float SoHistogramRep2D::getAxisMaximumX(
00517 ) const
00520 {
00521   return (float)fHistogram->xAxis().upperEdge();
00522 }
00524 int SoHistogramRep2D::getAxisNumberOfBinsY(
00525 ) const
00528 {
00529   return fHistogram->yAxis().bins();
00530 }
00532 float SoHistogramRep2D::getAxisMinimumY(
00533 ) const
00536 {
00537   return (float)fHistogram->yAxis().lowerEdge();
00538 }
00540 float SoHistogramRep2D::getAxisMaximumY(
00541 ) const
00544 {
00545   return (float)fHistogram->yAxis().upperEdge();
00546 }
00548 void SoHistogramRep2D::getBinsSumOfWeightsRange(
00549  float& aMin
00550 ,float& aMax
00551 ) const
00554 {
00555   aMin = (float)fHistogram->minBinHeight();
00556   aMax = (float)fHistogram->maxBinHeight();
00557 }
00559 int SoHistogramRep2D::getBinNumberOfEntries(
00560  int aI
00561 ,int aJ
00562 ) const
00565 {
00566   return fHistogram->binEntries(aI,aJ);
00567 }
00569 float SoHistogramRep2D::getBinLowerEdgeX(
00570  int aI
00571 ) const
00574 {
00575   return (float)fHistogram->xAxis().binLowerEdge(aI);
00576 }
00578 float SoHistogramRep2D::getBinUpperEdgeX(
00579  int aI
00580 ) const
00583 {
00584   return (float)fHistogram->xAxis().binUpperEdge(aI);
00585 }
00587 float SoHistogramRep2D::getBinLowerEdgeY(
00588  int aJ
00589 ) const
00592 {
00593   return (float)fHistogram->yAxis().binLowerEdge(aJ);
00594 }
00596 float SoHistogramRep2D::getBinUpperEdgeY(
00597  int aJ
00598 ) const
00601 {
00602   return (float)fHistogram->yAxis().binUpperEdge(aJ);
00603 }
00605 float SoHistogramRep2D::getBinSumOfWeights(
00606  int aI
00607 ,int aJ
00608 ) const
00611 {
00612   return (float)fHistogram->binHeight(aI,aJ);
00613 }
00615 float SoHistogramRep2D::getBinBar(
00616  int aI
00617 ,int aJ
00618 ) const
00621 {
00622   return (float)fHistogram->binError(aI,aJ);
00623 }
00625 const char* SoHistogramRep2D::getInfos(
00626  const char* /* aOptions */
00627 )
00630 {
00631   Lib::smanip::printf(fInfos,5 * 64,
00632 "\
00633 I %d\n\
00634 mx %g\n\
00635 rx %g\n\
00636 my %g\n\
00637 ry %g",fHistogram->entries()
00638        ,fHistogram->meanX()
00639        ,fHistogram->rmsX()
00640        ,fHistogram->meanY()
00641        ,fHistogram->rmsY());
00642   return fInfos.c_str();
00643 }
00645 const char* SoHistogramRep2D::getLegend(
00646 )
00649 {
00650   fLegend = fHistogram->annotation().value("Legend");
00651   return fLegend.c_str();
00652 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:17 2011 for SoStat by doxygen 1.4.7