Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

HistogramSvc.cpp

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiSvc/src/HistogramSvc/HistogramSvc.cpp,v 1.1.1.3 2001/04/18 18:32:50 tlindner Exp $
00002 #define HISTOGRAMSVC_HISTOGRAMSVC_CPP
00003 
00004 
00005 // Include files
00006 #include <cstdlib>
00007 #include "GaudiKernel/DataObject.h"
00008 #include "GaudiKernel/SvcFactory.h"
00009 #include "GaudiKernel/GaudiException.h"
00010 #include "GaudiKernel/RegistryEntry.h"
00011 #include "GaudiKernel/ISvcLocator.h"
00012 #include "GaudiKernel/IConversionSvc.h"
00013 #include "GaudiKernel/IHistogram1D.h"
00014 #include "GaudiKernel/IHistogram2D.h"
00015 #include "GaudiKernel/IAppMgrUI.h"
00016 #include "GaudiKernel/IProperty.h"
00017 #include "GaudiKernel/MsgStream.h"
00018 #include "GaudiKernel/Property.h"
00019 #include "HistogramSvc.h"
00020 #include "H1D.h"
00021 #include "H1DVar.h"
00022 #include "H2D.h"
00023 
00024 //------------------------------------------------------------------------------
00025 //
00026 // Implementation of class :  HistogramSvc
00027 //
00028 // Author :                   Pavel Binko
00029 //
00030 //------------------------------------------------------------------------------
00031 
00032 
00033 // Instantiation of a static factory class used by clients to create
00034 //   instances of this service
00035 static SvcFactory<HistogramSvc> s_factory;
00036 const ISvcFactory& HistogramSvcFactory = s_factory;
00037 
00038 
00042 
00043 IHistogram1D* HistogramSvc::book( const std::string& fullPath,
00044                                   const std::string& title,
00045                                   int binsX, double lowX, double highX )         {
00046   int sep = fullPath.rfind(IDataDirectory::SEPARATOR);
00047   if ( sep > 0 )    {
00048     std::string dirPath( fullPath, 0, sep );
00049     std::string relPath( fullPath, sep+1, fullPath.length() );
00050     return book( dirPath, relPath, title, binsX, lowX, highX );
00051   }
00052   throw GaudiException("Invalid name " + fullPath ,"HistogramSvc", StatusCode::FAILURE);
00053 }
00055 IHistogram1D* HistogramSvc::book( const std::string& dirPath,
00056                                   const std::string& relPath,
00057                                   const std::string& title,
00058                                   int binsX, double lowX, double highX )         {
00059   DataObject* pParent = createPath( dirPath );
00060 
00061   if ( 0 != pParent )   {
00062     return book( pParent, relPath, title, binsX, lowX, highX );
00063   }
00064   throw GaudiException("Unable to create directory " + dirPath ,"HistogramSvc", StatusCode::FAILURE);
00065 }
00067 IHistogram1D* HistogramSvc::book( const std::string& dirPath,
00068                                   int hID,
00069                                   const std::string& title,
00070                                   int binsX, double lowX, double highX )         {
00071   char txt[32];
00072   // Set the histogram title
00073   return book( dirPath, ::_itoa(hID, txt, 10), title, binsX, lowX, highX );
00074 }
00076 IHistogram1D* HistogramSvc::book( DataObject* pParent,
00077                                   const std::string& relPath,
00078                                   const std::string& title,
00079                                   int binsX, double lowX, double highX )         {
00080   IHistogram1D* hObj = 0;
00081   // Check if object is already present
00082   StatusCode status = findObject(pParent, relPath, hObj);
00083   // No ? Then create it!
00084   if ( !status.isSuccess() )    {
00085     hObj = new H1D( title, relPath, binsX, lowX, highX );
00086     if ( 0 != hObj )   {
00087       // Finally register the created histogram with the store
00088       status = DataSvc::registerObject( pParent,
00089                                         relPath,
00090                                         dynamic_cast<DataObject*>(hObj) );
00091       if ( !status.isSuccess() )    {
00092         MsgStream log( msgSvc(), name() );
00093         log << MSG::ERROR << "Unable to book the histogram: "
00094                           << title << endreq;
00095         delete hObj;
00096         throw GaudiException("Unable to register histogram "+pParent->fullpath()+"/" + relPath,"HistogramSvc", status);
00097       }
00098       return hObj;
00099     }
00100   }
00101   throw GaudiException("Unable to locate " + pParent->fullpath(),"HistogramSvc", status);
00102 }
00104 IHistogram1D* HistogramSvc::book( DataObject* pParent,
00105                                   int hID,
00106                                   const std::string& title,
00107                                   int binsX, double lowX, double highX )         {
00108   char txt[32];
00109   return book( pParent, ::_itoa(hID, txt, 10), title, binsX, lowX, highX );
00110 }
00111 
00112 
00116 
00117 IHistogram1D* HistogramSvc::book( const std::string& fullPath,
00118                                   const std::string& title,
00119                                   std::vector<double> edges )                  {
00120   int sep = fullPath.rfind(IDataDirectory::SEPARATOR);
00121   if ( sep > 0 )    {
00122     std::string dirPath( fullPath, 0, sep );
00123     std::string relPath( fullPath, sep+1, fullPath.length() );
00124     return book( dirPath, relPath, title, edges );
00125   }
00126   return 0;
00127 }
00129 IHistogram1D* HistogramSvc::book( const std::string& dirPath,
00130                                   const std::string& relPath,
00131                                   const std::string& title,
00132                                   std::vector<double> edges )                  {
00133   DataObject* pParent = createPath( dirPath );
00134   if ( 0 != pParent )   {
00135     return book( pParent, relPath, title, edges );
00136   }
00137   return 0;
00138 }
00140 IHistogram1D* HistogramSvc::book( const std::string& dirPath,
00141                                   int hID,
00142                                   const std::string& title,
00143                                   std::vector<double> edges )                  {
00144   char txt[32];
00145   return book( dirPath, ::_itoa(hID, txt, 10), title, edges );
00146 }
00148 IHistogram1D* HistogramSvc::book( DataObject* pParent,
00149                                   const std::string& relPath,
00150                                   const std::string& title,
00151                                   std::vector<double> edges )                  {
00152   IHistogram1D* hObj = 0;
00153   // Check if object is already present
00154   StatusCode status = findObject(pParent, relPath, hObj);
00155   // No ? Then create it!
00156   if ( !status.isSuccess() )    {
00157     hObj = new H1DVar( title, relPath, edges );
00158     if ( 0 != hObj )   {
00159       // Finally register the created histogram with the store
00160       status = DataSvc::registerObject( pParent,
00161                                         relPath,
00162                                         dynamic_cast<DataObject*>(hObj) );
00163       if ( !status.isSuccess() )    {
00164         MsgStream log( msgSvc(), name() );
00165         log << MSG::ERROR << "Unable to book the histogram: "
00166                           << title << endreq;
00167         delete hObj;
00168         return 0;
00169       }
00170 
00171       return hObj;
00172     }
00173   }
00174   return 0;
00175 }
00177 IHistogram1D* HistogramSvc::book( DataObject* pParent,
00178                                   int hID,
00179                                   const std::string& title,
00180                                   std::vector<double> edges )                  {
00181   char txt[32];
00182   return book( pParent, ::_itoa(hID, txt, 10), title, edges );
00183 }
00184 
00185 
00189 
00190 IHistogram2D* HistogramSvc::book( const std::string& fullPath,
00191                                   const std::string& title,
00192                                   int binsX, double lowX, double highX,
00193                                   int binsY, double lowY, double highY )         {
00194   int sep = fullPath.rfind(IDataDirectory::SEPARATOR);
00195   if ( sep > 0 )    {
00196     std::string dirPath( fullPath, 0, sep );
00197     std::string relPath( fullPath, sep+1, fullPath.length() );
00198     return book( dirPath, relPath, title, binsX, lowX, highX,
00199                                           binsY, lowY, highY );
00200   }
00201   return 0;
00202 }
00204 IHistogram2D* HistogramSvc::book( const std::string& dirPath,
00205                                   const std::string& relPath,
00206                                   const std::string& title,
00207                                   int binsX, double lowX, double highX,
00208                                   int binsY, double lowY, double highY )         {
00209   DataObject* pParent = createPath( dirPath );
00210   if ( 0 != pParent )   {
00211     return book( pParent, relPath, title, binsX, lowX, highX,
00212                                           binsY, lowY, highY );
00213   }
00214   return 0;
00215 }
00217 IHistogram2D* HistogramSvc::book( const std::string& dirPath,
00218                                   int hID,
00219                                   const std::string& title,
00220                                   int binsX, double lowX, double highX,
00221                                   int binsY, double lowY, double highY )         {
00222   char txt[32];
00223   return book( dirPath, ::_itoa(hID, txt,10), title, binsX, lowX, highX,
00224                                       binsY, lowY, highY );
00225 }
00227 IHistogram2D* HistogramSvc::book( DataObject* pParent,
00228                                   const std::string& relPath,
00229                                   const std::string& title,
00230                                   int binsX, double lowX, double highX,
00231                                   int binsY, double lowY, double highY )         {
00232   IHistogram2D* hObj = 0;
00233   // Check if object is already present
00234   StatusCode status = findObject(pParent, relPath, hObj);
00235   // No ? Then create it!
00236   if ( !status.isSuccess() )    {
00237     hObj = new H2D( title, relPath, binsX, lowX, highX,
00238                                     binsY, lowY, highY );
00239     if ( 0 != hObj )   {
00240       // Finally register the created histogram with the store
00241       status = DataSvc::registerObject( pParent,
00242                                         relPath,
00243                                         dynamic_cast<DataObject*>(hObj) );
00244       if ( !status.isSuccess() )    {
00245         MsgStream log( msgSvc(), name() );
00246         log << MSG::ERROR << "Unable to book the histogram: "
00247                           << title << endreq;
00248         delete hObj;
00249         return 0;
00250       }
00251 
00252       return hObj;
00253     }
00254   }
00255   return 0;
00256 }
00258 IHistogram2D* HistogramSvc::book( DataObject* pParent,
00259                                   int hID,
00260                                   const std::string& title,
00261                                   int binsX, double lowX, double highX,
00262                                   int binsY, double lowY, double highY )         {
00263   char txt[32];
00264   return book( pParent, ::_itoa(hID, txt,10), title, binsX, lowX, highX,
00265                                       binsY, lowY, highY );
00266 }
00267 
00268 
00272 
00273 StatusCode HistogramSvc::registerObject( const std::string& fullPath,
00274                                          IHistogram* hObj )                    {
00275   // Find the most right separator
00276   int sep = fullPath.rfind(IDataDirectory::SEPARATOR);
00277   // Create the path (without the last field (cut out all after the last "/"))
00278   std::string subPath( fullPath, 0, sep );
00279   createPath( subPath );
00280   // Get the histogram number (the last field in the fullPath)
00281   std::string rest( fullPath, sep+1, fullPath.length()-sep );
00282   // Set the histogram title
00283   hObj->setTitle( rest + "|" + hObj->title() );
00284   // Register the histogram in the histogram data store
00285   StatusCode sc = DataSvc::registerObject( fullPath,
00286                                            dynamic_cast<DataObject*>(hObj) );
00287   return sc;
00288 }
00290 StatusCode HistogramSvc::registerObject( const std::string& parentPath,
00291                                          const std::string& objPath,
00292                                          IHistogram* hObj )                    {
00293   // Create the parent path
00294   createPath( parentPath );
00295   // Set the histogram title
00296   hObj->setTitle( objPath + "|" + hObj->title() );
00297   // Register the histogram in the histogram data store
00298   StatusCode sc = DataSvc::registerObject( parentPath,
00299                                            objPath,
00300                                            dynamic_cast<DataObject*>(hObj) );
00301   return sc;
00302 }
00304 StatusCode HistogramSvc::registerObject( const std::string& parentPath,
00305                                          int item,
00306                                          IHistogram* hObj )                    {
00307   char txt[32];
00308   // Create the parent path
00309   createPath( parentPath );
00310   // Set the histogram title
00311   std::string objPath = ::_itoa(item, txt, 10);
00312   hObj->setTitle( objPath + "|" + hObj->title() );
00313   // Register the histogram in the histogram data store
00314   StatusCode sc = DataSvc::registerObject( parentPath,
00315                                            item,
00316                                            dynamic_cast<DataObject*>(hObj) );
00317   return sc;
00318 }
00320 StatusCode HistogramSvc::registerObject( DataObject* parentObj,
00321                                          const std::string& objPath,
00322                                          IHistogram* hObj )                    {
00323   // Set the histogram title
00324   hObj->setTitle( objPath + "|" + hObj->title() );
00325   // Register the histogram in the histogram data store
00326   StatusCode sc = DataSvc::registerObject( parentObj,
00327                                            objPath,
00328                                            dynamic_cast<DataObject*>(hObj) );
00329   return sc;
00330 }
00331 StatusCode HistogramSvc::registerObject( IHistogram* parentObj,
00332                                          const std::string& objPath,
00333                                          IHistogram* hObj )                    {
00334   // Set the histogram title
00335   hObj->setTitle( objPath + "|" + hObj->title() );
00336   // Register the histogram in the histogram data store
00337   StatusCode sc = DataSvc::registerObject( dynamic_cast<DataObject*>(parentObj),
00338                                            objPath,
00339                                            dynamic_cast<DataObject*>(hObj) );
00340   return sc;
00341 }
00343 StatusCode HistogramSvc::registerObject( DataObject* parentObj,
00344                                          int item,
00345                                          IHistogram* hObj )                    {
00346   // Convert the item (number) into an objPath (string)
00347   char txt[32];
00348   // Set the histogram title
00349   std::string objPath = ::_itoa(item, txt, 10);
00350   hObj->setTitle( objPath + "|" + hObj->title() );
00351   // Register the histogram in the histogram data store
00352   StatusCode sc = DataSvc::registerObject( parentObj,
00353                                            item,
00354                                            dynamic_cast<DataObject*>(hObj) );
00355   return sc;
00356 }
00357 StatusCode HistogramSvc::registerObject( IHistogram* parentObj,
00358                                          int item,
00359                                          IHistogram* hObj )                    {
00360   // Convert the item (number) into an objPath (string)
00361   char txt[32];
00362   // Set the histogram title
00363   std::string objPath = ::_itoa(item, txt, 10);
00364   hObj->setTitle( objPath + "|" + hObj->title() );
00365   // Register the histogram in the histogram data store
00366   StatusCode sc = DataSvc::registerObject( dynamic_cast<DataObject*>(parentObj),
00367                                            item,
00368                                            dynamic_cast<DataObject*>(hObj) );
00369   return sc;
00370 }
00371 
00372 
00376 
00377 StatusCode HistogramSvc::unregisterObject( IHistogram* hObj )                  {
00378   StatusCode sc = DataSvc::unregisterObject( dynamic_cast<DataObject*>(hObj) );
00379   return sc;
00380 }
00382 StatusCode HistogramSvc::unregisterObject( IHistogram* hObj,
00383                                            const std::string& objectPath )     {
00384   StatusCode sc = DataSvc::unregisterObject( dynamic_cast<DataObject*>(hObj),
00385                                              objectPath );
00386   return sc;
00387 }
00389 StatusCode HistogramSvc::unregisterObject( IHistogram* hObj,
00390                                            int item )                          {
00391   StatusCode sc = DataSvc::unregisterObject( dynamic_cast<DataObject*>(hObj),
00392                                              item );
00393   return sc;
00394 }
00395 
00396 
00400 
00401 StatusCode HistogramSvc::retrieveObject( IDataDirectory* pDirectory,
00402                                          const std::string& path,
00403                                          IHistogram1D*& h1dObj )               {
00404   DataObject*  pObject  = 0;
00405   StatusCode sc = DataSvc::retrieveObject( pDirectory, path, pObject );
00406   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00407   return sc;
00408 }
00409 StatusCode HistogramSvc::retrieveObject( IDataDirectory* pDirectory,
00410                                          const std::string& path,
00411                                          IHistogram2D*& h2dObj )               {
00412   DataObject*  pObject  = 0;
00413   StatusCode sc = DataSvc::retrieveObject( pDirectory, path, pObject );
00414   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00415   return sc;
00416 }
00418 StatusCode HistogramSvc::retrieveObject( const std::string& fullPath,
00419                                          IHistogram1D*& h1dObj )               {
00420   DataObject*  pObject  = 0;
00421   StatusCode sc = DataSvc::retrieveObject( fullPath, pObject );
00422   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00423   return sc;
00424 }
00425 StatusCode HistogramSvc::retrieveObject( const std::string& fullPath,
00426                                          IHistogram2D*& h2dObj )               {
00427   DataObject*  pObject  = 0;
00428   StatusCode sc = DataSvc::retrieveObject( fullPath, pObject );
00429   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00430   return sc;
00431 }
00433 StatusCode HistogramSvc::retrieveObject( const std::string& parentPath,
00434                                          const std::string& objPath,
00435                                          IHistogram1D*& h1dObj )               {
00436   DataObject*  pObject  = 0;
00437   StatusCode sc = DataSvc::retrieveObject( parentPath, objPath, pObject );
00438   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00439   return sc;
00440 }
00441 StatusCode HistogramSvc::retrieveObject( const std::string& parentPath,
00442                                          const std::string& objPath,
00443                                          IHistogram2D*& h2dObj )               {
00444   DataObject*  pObject  = 0;
00445   StatusCode sc = DataSvc::retrieveObject( parentPath, objPath, pObject );
00446   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00447   return sc;
00448 }
00450 StatusCode HistogramSvc::retrieveObject( const std::string& parentPath,
00451                                          int item,
00452                                          IHistogram1D*& h1dObj )               {
00453   DataObject*  pObject  = 0;
00454   StatusCode sc = DataSvc::retrieveObject( parentPath, item, pObject );
00455   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00456   return sc;
00457 }
00458 StatusCode HistogramSvc::retrieveObject( const std::string& parentPath,
00459                                          int item,
00460                                          IHistogram2D*& h2dObj )               {
00461   DataObject*  pObject  = 0;
00462   StatusCode sc = DataSvc::retrieveObject( parentPath, item, pObject );
00463   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00464   return sc;
00465 }
00467 StatusCode HistogramSvc::retrieveObject( DataObject* parentObj,
00468                                          const std::string& objPath,
00469                                          IHistogram1D*& h1dObj )               {
00470   DataObject*  pObject  = 0;
00471   StatusCode sc = DataSvc::retrieveObject( parentObj, objPath, pObject );
00472   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00473   return sc;
00474 }
00475 StatusCode HistogramSvc::retrieveObject( DataObject* parentObj,
00476                                          const std::string& objPath,
00477                                          IHistogram2D*& h2dObj )               { 
00478   DataObject*  pObject  = 0;
00479   StatusCode sc = DataSvc::retrieveObject( parentObj, objPath, pObject );
00480   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00481   return sc;
00482 }
00483 StatusCode HistogramSvc::retrieveObject( IHistogram* parentObj,
00484                                          const std::string& objPath,
00485                                          IHistogram1D*& h1dObj )               {
00486   DataObject*  pObject  = 0;
00487   StatusCode sc = DataSvc::retrieveObject( dynamic_cast<DataObject*>(parentObj),
00488                                            objPath,
00489                                            pObject );
00490   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00491   return sc;
00492 }
00493 StatusCode HistogramSvc::retrieveObject( IHistogram* parentObj,
00494                                          const std::string& objPath,
00495                                          IHistogram2D*& h2dObj )               {
00496   DataObject*  pObject  = 0;
00497   StatusCode sc = DataSvc::retrieveObject( dynamic_cast<DataObject*>(parentObj),
00498                                            objPath,
00499                                            pObject );
00500   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00501   return sc;
00502 }
00504 StatusCode HistogramSvc::retrieveObject( DataObject* parentObj,
00505                                          int item,
00506                                          IHistogram1D*& h1dObj )               {
00507   DataObject*  pObject  = 0;
00508   StatusCode sc = DataSvc::retrieveObject( parentObj, item, pObject );
00509   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00510   return sc;
00511 }
00512 StatusCode HistogramSvc::retrieveObject( DataObject* parentObj,
00513                                          int item,
00514                                          IHistogram2D*& h2dObj )               {
00515   DataObject*  pObject  = 0;
00516   StatusCode sc = DataSvc::retrieveObject( parentObj, item, pObject );
00517   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00518   return sc;
00519 }
00520 StatusCode HistogramSvc::retrieveObject( IHistogram* parentObj,
00521                                          int item,
00522                                          IHistogram1D*& h1dObj )               {
00523   DataObject*  pObject  = 0;
00524   StatusCode sc = DataSvc::retrieveObject( dynamic_cast<DataObject*>(parentObj),
00525                                            item,
00526                                            pObject );
00527   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00528   return sc;
00529 }
00530 StatusCode HistogramSvc::retrieveObject( IHistogram* parentObj,
00531                                          int item,
00532                                          IHistogram2D*& h2dObj )               {
00533   DataObject*  pObject  = 0;
00534   StatusCode sc = DataSvc::retrieveObject( dynamic_cast<DataObject*>(parentObj),
00535                                            item,
00536                                            pObject );
00537   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00538   return sc;
00539 }
00540 
00541 
00545 
00546 StatusCode HistogramSvc::findObject( const std::string& fullPath,
00547                                      IHistogram1D*& h1dObj )                   {
00548   DataObject*  pObject  = 0;
00549   StatusCode sc = DataSvc::findObject( fullPath, pObject );
00550   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00551   return sc;
00552 }
00553 StatusCode HistogramSvc::findObject( const std::string& fullPath,
00554                                      IHistogram2D*& h2dObj )                   {
00555   DataObject*  pObject  = 0;
00556   StatusCode sc = DataSvc::findObject( fullPath, pObject );
00557   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00558   return sc;
00559 }
00561 StatusCode HistogramSvc::findObject( IDataDirectory* pDirectory,
00562                                      const std::string& path,
00563                                      IHistogram1D*& h1dObj )                   {
00564   DataObject*  pObject  = 0;
00565   StatusCode sc = DataSvc::findObject( pDirectory, path, pObject );
00566   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00567   return sc;
00568 }
00569 StatusCode HistogramSvc::findObject( IDataDirectory* pDirectory,
00570                                      const std::string& path,
00571                                      IHistogram2D*& h2dObj )                   {
00572   DataObject*  pObject  = 0;
00573   StatusCode sc = DataSvc::findObject( pDirectory, path, pObject );
00574   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00575   return sc;
00576 }
00578 StatusCode HistogramSvc::findObject( const std::string& parentPath,
00579                                      const std::string& objPath,
00580                                      IHistogram1D*& h1dObj )                   {
00581   DataObject*  pObject  = 0;
00582   StatusCode sc = DataSvc::findObject( parentPath, objPath, pObject );
00583   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00584   return sc;
00585 }
00586 StatusCode HistogramSvc::findObject( const std::string& parentPath,
00587                                      const std::string& objPath,
00588                                      IHistogram2D*& h2dObj )                   {
00589   DataObject*  pObject  = 0;
00590   StatusCode sc = DataSvc::findObject( parentPath, objPath, pObject );
00591   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00592   return sc;
00593 }
00595 StatusCode HistogramSvc::findObject( const std::string& parentPath,
00596                                      int item,
00597                                      IHistogram1D*& h1dObj )                   {
00598   DataObject*  pObject  = 0;
00599   StatusCode sc = DataSvc::findObject( parentPath, item, pObject );
00600   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00601   return sc;
00602 }
00603 StatusCode HistogramSvc::findObject( const std::string& parentPath,
00604                                      int item,
00605                                      IHistogram2D*& h2dObj )                   {
00606   DataObject*  pObject  = 0;
00607   StatusCode sc = DataSvc::findObject( parentPath, item, pObject );
00608   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00609   return sc;
00610 }
00612 StatusCode HistogramSvc::findObject( DataObject* parentObj,
00613                                      const std::string& objPath,
00614                                      IHistogram1D*& h1dObj )                   {
00615   DataObject*  pObject  = 0;
00616   StatusCode sc = DataSvc::findObject( parentObj, objPath, pObject );
00617   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00618   return sc;
00619 }
00620 StatusCode HistogramSvc::findObject( DataObject* parentObj,
00621                                      const std::string& objPath,
00622                                      IHistogram2D*& h2dObj )                   {
00623   DataObject*  pObject  = 0;
00624   StatusCode sc = DataSvc::findObject( parentObj, objPath, pObject );
00625   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00626   return sc;
00627 }
00628 StatusCode HistogramSvc::findObject( IHistogram* parentObj,
00629                                      const std::string& objPath,
00630                                      IHistogram1D*& h1dObj )                   {
00631   DataObject*  pObject  = 0;
00632   StatusCode sc = DataSvc::findObject( dynamic_cast<DataObject*>(parentObj),
00633                                        objPath,
00634                                        pObject );
00635   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00636   return sc;
00637 }
00638 StatusCode HistogramSvc::findObject( IHistogram* parentObj,
00639                                      const std::string& objPath,
00640                                      IHistogram2D*& h2dObj )                   {
00641   DataObject*  pObject  = 0;
00642   StatusCode sc = DataSvc::findObject( dynamic_cast<DataObject*>(parentObj),
00643                                        objPath,
00644                                        pObject );
00645   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00646   return sc;
00647 }
00649 StatusCode HistogramSvc::findObject( DataObject* parentObj,
00650                                      int item,
00651                                      IHistogram1D*& h1dObj )                   {
00652   DataObject*  pObject  = 0;
00653   StatusCode sc = DataSvc::findObject( parentObj, item, pObject );
00654   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00655   return sc;
00656 }
00657 StatusCode HistogramSvc::findObject( DataObject* parentObj,
00658                                      int item,
00659                                      IHistogram2D*& h2dObj )                   {
00660   DataObject*  pObject  = 0;
00661   StatusCode sc = DataSvc::findObject( parentObj, item, pObject );
00662   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00663   return sc;
00664 }
00665 StatusCode HistogramSvc::findObject( IHistogram* parentObj,
00666                                      int item,
00667                                      IHistogram1D*& h1dObj )                   {
00668   DataObject*  pObject  = 0;
00669   StatusCode sc = DataSvc::findObject( dynamic_cast<DataObject*>(parentObj),
00670                                        item,
00671                                        pObject );
00672   h1dObj = dynamic_cast<IHistogram1D*>(pObject);
00673   return sc;
00674 }
00675 StatusCode HistogramSvc::findObject( IHistogram* parentObj,
00676                                      int item,
00677                                      IHistogram2D*& h2dObj )                   {
00678   DataObject*  pObject  = 0;
00679   StatusCode sc = DataSvc::findObject( dynamic_cast<DataObject*>(parentObj),
00680                                        item,
00681                                        pObject );
00682   h2dObj = dynamic_cast<IHistogram2D*>(pObject);
00683   return sc;
00684 }
00685 
00686 
00690 
00693   
00695 std::ostream& HistogramSvc::print( IHistogram* h, std::ostream& s ) const      {
00696   H1D* concreteH1D = dynamic_cast<H1D*>( h );
00697   if( 0 != concreteH1D ) {
00698     concreteH1D->print( s );
00699     return s;
00700   }
00701   H1DVar* concreteH1DVar = dynamic_cast<H1DVar*>( h );
00702   if( 0 != concreteH1DVar ) {
00703     concreteH1DVar->print( s );
00704     return s;
00705   }
00706   H2D* concreteH2D = dynamic_cast<H2D*>( h );
00707   if( 0 != concreteH2D ) {
00708     concreteH2D->print( s );
00709     return s;
00710   }
00711   // Unknown histogram type
00712   std::cout << "Unknown histogram type" << std::endl;
00713   return s;
00714 }
00715 
00718 
00720 std::ostream& HistogramSvc::write( IHistogram* h, std::ostream& s ) const      {
00721   H1D* concreteH1D = dynamic_cast<H1D*>( h );
00722   if( 0 != concreteH1D ) {
00723     concreteH1D->write( s );
00724     return s;
00725   }
00726   H1DVar* concreteH1DVar = dynamic_cast<H1DVar*>( h );
00727   if( 0 != concreteH1DVar ) {
00728     concreteH1DVar->write( s );
00729     return s;
00730   }
00731   H2D* concreteH2D = dynamic_cast<H2D*>( h );
00732   if( 0 != concreteH2D ) {
00733     concreteH2D->write( s );
00734     return s;
00735   }
00736   // Unknown histogram type
00737   std::cout << "Unknown histogram type" << std::endl;
00738   return s;
00739 }
00740 
00742 int HistogramSvc::write( IHistogram* h, const char* file_name ) const          {
00743   H1D* concreteH1D = dynamic_cast<H1D*>( h );
00744   if( 0 != concreteH1D ) {
00745     return concreteH1D->write( file_name );
00746   }
00747   H1DVar* concreteH1DVar = dynamic_cast<H1DVar*>( h );
00748   if( 0 != concreteH1DVar ) {
00749     return concreteH1DVar->write( file_name );
00750   }
00751   H2D* concreteH2D = dynamic_cast<H2D*>( h );
00752   if( 0 != concreteH2D ) {
00753     return concreteH2D->write( file_name );
00754   }
00755   // Unknown histogram type
00756   std::cout << "Unknown histogram type" << std::endl;
00757   return 0;
00758 }
00759 
00760 
00761 //------------------------------------------------------------------------------
00763 DataObject* HistogramSvc::createPath( const std::string& newPath )             {
00764 
00765   std::string tmpPath = newPath;
00766   // Remove trailing "/" from newPath if it exists
00767   if (tmpPath.rfind("/") == tmpPath.length()-1) {
00768     tmpPath.erase(tmpPath.rfind("/"),1);
00769   }
00770 
00771   DataObject* pObject = 0;
00772   StatusCode sc = DataSvc::findObject( tmpPath, pObject );
00773   if( sc.isSuccess() ) {
00774     return pObject;
00775   }
00776 
00777   int sep = tmpPath.rfind(IDataDirectory::SEPARATOR);
00778   std::string rest( tmpPath, sep+1, tmpPath.length()-sep );
00779   std::string subPath( tmpPath, 0, sep );
00780   if( 0 != sep ) {
00781     createPath( subPath );
00782   }
00783   else {
00784     MsgStream log( msgSvc(), name() );
00785     log << MSG::ERROR << "Unable to create the histogram path" << endreq;
00786     return 0;
00787   }
00788 
00789   pObject = createDirectory( subPath, rest );
00790 
00791   return pObject;
00792 }
00793 
00794 //------------------------------------------------------------------------------
00796 DataObject* HistogramSvc::createDirectory( const std::string& parentDir,
00797                                            const std::string& subDir )         {
00798 
00799   StatusCode   status    = StatusCode::FAILURE;
00800   DataObject*  directory = new DataObject( subDir );
00801 
00802   if ( 0 != directory )  {
00803     DataObject* pnode;
00804     status = DataSvc::retrieveObject( parentDir, pnode );
00805     if( status.isSuccess() ) {
00806       status = DataSvc::registerObject( pnode, subDir, directory );
00807       if ( !status.isSuccess() )   {
00808         MsgStream log( msgSvc(), name() );
00809         log << MSG::ERROR << "Unable to create the directory: "
00810                           << parentDir << "/" << subDir << endreq;
00811         delete directory;
00812         return 0;
00813       }
00814     }
00815     else {
00816       MsgStream log( msgSvc(), name() );
00817       log << MSG::ERROR << "Unable to create the directory: "
00818                         << parentDir << "/" << subDir << endreq;
00819       delete directory;
00820       return 0;
00821     }
00822   }
00823   return directory;
00824 }
00825 
00826 
00827 //------------------------------------------------------------------------------
00828 // Standard Constructor
00829 HistogramSvc::HistogramSvc( const std::string& name, ISvcLocator* svc ) 
00830   : DataSvc( name, svc )                                                       {
00831   // Properties can be declared here
00832   //  declareProperty("Type",   m_storageType = HBOOK_StorageType);
00833 }
00834 
00835 
00836 //------------------------------------------------------------------------------
00838 HistogramSvc::~HistogramSvc()                                                  {
00839   setDataLoader( 0 );
00840   clearStore();
00841 }
00842 
00843 
00844 //------------------------------------------------------------------------------
00846 StatusCode HistogramSvc::initialize()                                          {
00847 
00848   // Nothing to do: just call base class initialisation
00849   DataObject*     rootObj     = new DataObject( "/stat" );
00850   StatusCode      status      = DataSvc::initialize();
00851   ISvcLocator*    svc_loc     = serviceLocator();
00852   IConversionSvc* cnv_svc     = 0;
00853 
00854   MsgStream log( msgSvc(), name() );
00855 
00856   //  log << MSG::INFO << "In HistogramSvc::intialize()" << endreq;
00857 
00858   // Set root object
00859   if ( rootObj ) {
00860     StatusCode status = setRoot( "/stat", rootObj );
00861     if ( ! status.isSuccess() ) {
00862       log << MSG::ERROR << "Unable to set histogram data store root" << endreq;
00863       delete rootObj;
00864       return status;
00865     }
00866   }
00867 
00868   // CGL: set the storage type
00869   // Get the value of the Stat persistancy mechanism from the AppMgr
00870 
00871   IAppMgrUI*   appMgr;
00872   IProperty*   appPropMgr;
00873   StatusCode sts;
00874 
00875   sts = serviceLocator()-> queryInterface(IID_IAppMgrUI,(void**)&appMgr );
00876 
00877   if( sts.isFailure() ) {
00878     // Report an error and return the FAILURE status code
00879     log << MSG::ERROR << "Could not get AppMgrUI" << endreq;
00880     return sts;
00881   }
00882 
00883   sts = appMgr->queryInterface(IID_IProperty,(void **)&appPropMgr );
00884 
00885   if( sts.isFailure() ) {
00886     // Report an error and return the FAILURE status code
00887     log << MSG::ERROR << "Could not get PropMgr" << endreq;
00888     return sts;
00889   }
00890 
00891   StringProperty sp("HistogramPersistency","");
00892   sts = appPropMgr->getProperty( &sp );
00893   if (sts.isFailure()) {
00894     log << MSG::ERROR << "Could not get Histogram Persistency format"
00895         << " from ApplicationMgr properties" << endreq;
00896     return sts;
00897   }
00898 
00899   //  log << MSG::DEBUG << "Histogram Persistency: " << sp.value() << endreq;
00900 
00901   //if (sp.value() != "HBOOK" && sp.value() != "ROOT") {
00902   //  log << MSG::ERROR << "Unknown Histogram Persistency format: "<< sp.value() << endreq;
00903   //  return StatusCode::FAILURE;
00904   //}
00905 
00906   // Clean up
00907   appPropMgr->release();
00908   appMgr->release();
00909 
00910   status = svc_loc->getService( "HistogramPersistencySvc",
00911                                    IID_IConversionSvc,
00912                                    (IInterface*&) cnv_svc );
00913   if ( status.isSuccess() )   {
00914     setDataLoader( cnv_svc );
00915   }
00916   return StatusCode::SUCCESS;
00917 }
00918 
00919 
00920 //------------------------------------------------------------------------------
00921 // Access to various interfaces of the service
00922 StatusCode HistogramSvc::queryInterface( const IID& riid,
00923                                          void** ppvInterface )                 {
00924   if( riid == IID_IHistogramSvc ) {
00925     *ppvInterface = static_cast<IHistogramSvc*>(this);
00926   }
00927   else {
00928     // Interface is not directly availible: try out a base class
00929     return DataSvc::queryInterface( riid, ppvInterface );
00930   }
00931   addRef();
00932   return StatusCode::SUCCESS;
00933 }

Generated at Wed Nov 21 12:22:30 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000