Gaudi Framework, version v20r2

Generated: 18 Jul 2008

HFileCnv.cpp

Go to the documentation of this file.
00001 // $Header: /local/reps/Gaudi/HbookCnv/src/HFileCnv.cpp,v 1.10 2006/01/10 20:11:14 hmd Exp $
00002 #define HBOOKCNV_HFILECNV_CPP
00003 
00004 
00005 // Include files
00006 #include "GaudiKernel/CnvFactory.h"
00007 #include "GaudiKernel/GenericAddress.h"
00008 #include "GaudiKernel/IRegistry.h"
00009 #include "GaudiKernel/IToolSvc.h"
00010 #include "GaudiKernel/IAlgTool.h"
00011 #include "GaudiKernel/IProperty.h"
00012 #include "GaudiKernel/ServiceLocatorHelper.h"
00013 #include "GaudiKernel/MsgStream.h"
00014 #include "GaudiKernel/NTuple.h"
00015 #include "HbookDef.h"
00016 #include "HFileCnv.h"
00017 
00018 //------------------------------------------------------------------------------
00019 //
00020 // Implementation of class :  HbookCnv::HFileCnv
00021 //
00022 // Author :                   Markus Frank
00023 //
00024 //------------------------------------------------------------------------------
00025 
00026 
00027 // Instantiation of a static factory class used by clients to create
00028 // instances of this service
00029 DECLARE_NAMESPACE_CONVERTER_FACTORY(HbookCnv,HFileCnv)
00030 
00031 StatusCode HbookCnv::HFileCnv::initialize() 
00032 { 
00033   StatusCode sc = HbookCnv::HDirectoryCnv::initialize() ;
00034   if ( sc.isFailure() ) { return sc ; }
00035   
00036   // Get Tool Service 
00037   IToolSvc* tSvc = 0  ;
00038   MsgStream log ( msgSvc() , "HbookNFileCnv" ) ;
00039   ServiceLocatorHelper hlp( *serviceLocator() , log , "HbookNFileCnv" ) ;
00040   sc = hlp.getService( "ToolSvc", 
00041                        true     , 
00042                        IToolSvc::interfaceID() , 
00043                        (void**)&tSvc ) ;
00044   if ( sc.isSuccess() &&  0 != tSvc ) 
00045   {
00046     IAlgTool* tool = 0 ;
00047     sc = tSvc->retrieve( "HbookTool" , IAlgTool::interfaceID() , tool ) ;
00048     if ( sc.isSuccess() && 0 != tool ) 
00049     {
00050       IntegerProperty lrecl ( "LRECL" , m_LRECL ) ;
00051       IntegerProperty nrecl ( "NRECL" , m_NRECL ) ;
00052       StringProperty  mode  ( "MODE"  , m_MODE  ) ;
00053       IProperty* prop = 0 ;
00054       sc = tool->queryInterface( IProperty::interfaceID() , 
00055                                  (void**)&prop ) ;
00056       if ( sc.isSuccess() && 0 != prop ) 
00057       {
00058         if ( prop->getProperty ( &lrecl ).isSuccess() )
00059         { m_LRECL = lrecl.value() ; }
00060         if ( prop->getProperty ( &nrecl ).isSuccess() )
00061         { m_NRECL = nrecl.value() ; }
00062         if ( prop->getProperty ( &mode  ).isSuccess() ) 
00063         { m_MODE  = mode.value() ; }
00064         prop->release() ; 
00065         prop = 0 ;
00066       }
00067       tSvc->releaseTool( tool ) ;
00068       tool = 0 ;
00069     }
00070     tSvc->release() ; 
00071   };                     
00072 
00073   return StatusCode::SUCCESS ;
00074 };
00075 
00076 StatusCode HbookCnv::HFileCnv::createObj(IOpaqueAddress* pAddress, DataObject*& refpObject)   {
00077   MsgStream log(msgSvc(), "HbookNFileCnv");
00078   unsigned long* ipar = (unsigned long*)pAddress->ipar();
00079   std::string fname = pAddress->par()[0];
00080   std::string oname = pAddress->registry()->name().c_str()+1;
00081   // V.B.:  char mode[3] = { char(ipar[1]), 'P', 0 };
00082   // V.B.: long istat, lrec=1024, lun = ::F77GETLUN();
00083   std::string mode ( 1 , char(ipar[1]) ) ;
00084   mode += m_MODE ;
00085   long istat, lrec=m_LRECL, lun = ::F77GETLUN();
00086   // Do the init
00087   ::INIT_HBOOK(250000);
00088   // Do not forget to remove the first "/"
00089   if ( mode[0] == 'O' ) mode[0] = ' ';  
00090   if ( std::string::npos != mode.find('Q')  && 0 < m_NRECL ) 
00091   { ::SETQUEST( 10 , m_NRECL ) ; }
00092   ::HROPEN(lun, oname, fname, mode, lrec, istat);
00093   
00094   if ( istat != 0 )   {
00095     log << MSG::ERROR << "Error opening HBook RZ file:" << fname 
00096   << " as " << oname << endreq;
00097     return StatusCode::FAILURE;
00098   }
00099   else if ( mode[0] == 'N' )   {
00100     log << MSG::INFO << "Opened NEW HBook RZ file:" << fname 
00101   << " as " << oname << endreq;
00102   }
00103   else if ( mode[0] == 'U' )   {
00104     log << MSG::INFO << "Updating EXISTING HBook RZ file:" << fname
00105   << " as " << oname << endreq;
00106   }
00107   else   {
00108     log << MSG::INFO << "Opening EXISTING HBook RZ file:" << fname
00109   << " as " << oname << endreq;
00110   }
00111   NTuple::File* pFile = new NTuple::File((unsigned char)objType(), fname, oname);
00112   ipar[0] = lun;
00113   pFile->setOpen(true);
00114   refpObject = pFile;
00115   return StatusCode::SUCCESS;
00116 }
00117 
00118 
00120 StatusCode HbookCnv::HFileCnv::createRep( DataObject* pObject, IOpaqueAddress*& refpAddress )   {
00121   IRegistry* pRegistry = pObject->registry();
00122   if ( 0 != pRegistry )   {
00123     refpAddress = pRegistry->address();
00124     return HFileCnv::updateRep( refpAddress, pObject );
00125   }
00126   return StatusCode::FAILURE;
00127 }
00128 
00129 
00131 StatusCode HbookCnv::HFileCnv::updateRep( IOpaqueAddress* pAddress, DataObject* pObject )   {
00132   NTuple::File* pFile = dynamic_cast<NTuple::File*>(pObject);
00133   if ( pFile->isOpen() )    {
00134     MsgStream log(msgSvc(), "HbookNFileCnv");
00135     std::string oname = pFile->logicalName();
00136     long lun = pAddress->ipar()[0];
00137     ::HREND(oname.c_str(), oname.length());
00138     F77CLOSE(lun);
00139     log << MSG::INFO << "Closing HBook RZ file:" << pFile->name() 
00140                    << " as " << pObject->registry()->identifier() << endreq;
00141     pFile->setOpen(false);
00142     return StatusCode::SUCCESS;
00143   }
00144   return StatusCode::FAILURE;
00145 }

Generated at Fri Jul 18 11:59:26 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004