![]() |
|
|
Generated: 18 Jul 2008 |
00001 //------------------------------------------------------------------------------ 00002 // 00003 // Implementation of class : HbookCnv::PersSvc 00004 // 00005 // Author : Pavel Binko 00006 // 00007 //------------------------------------------------------------------------------ 00008 // $Header: /local/reps/Gaudi/HbookCnv/src/PersSvc.cpp,v 1.13 2006/01/10 20:11:14 hmd Exp $ 00009 #define HBOOKCNV_PERSSVC_CPP 00010 00011 // Include files 00012 #include "GaudiKernel/DataObject.h" 00013 #include "GaudiKernel/SvcFactory.h" 00014 #include "GaudiKernel/CnvFactory.h" 00015 #include "GaudiKernel/MsgStream.h" 00016 #include "GaudiKernel/IDataSelector.h" 00017 #include "GaudiKernel/IConverter.h" 00018 #include "GaudiKernel/IHistogramSvc.h" 00019 #include "GaudiKernel/ISvcLocator.h" 00020 00021 #include "HbookDef.h" 00022 #include "PersSvc.h" 00023 00024 #include <iostream> 00025 #include <string> 00026 00027 // Instantiation of a static factory class used by clients to create 00028 // instances of this service 00029 DECLARE_NAMESPACE_SERVICE_FACTORY(HbookCnv,PersSvc) 00030 00031 static std::string stat_dir = "/stat"; 00032 static std::string undefFileName = "UndefinedHbookOutputFileName"; 00033 00034 00035 static long s_dataTypePolicy = FLOAT_ONLY; 00036 long dataTypePolicy() { 00037 return s_dataTypePolicy; 00038 } 00039 00041 StatusCode HbookCnv::PersSvc::initialize() { 00042 StatusCode status = ConversionSvc::initialize(); 00043 if ( status.isSuccess() ) { 00044 MsgStream log( messageService(), name() ); 00045 00046 // Report on size properties 00047 log << MSG::INFO << "Setting /PAWC/ common block size to " 00048 << m_NPAWC << endreq; 00049 if (m_NREC > 0) { 00050 log << MSG::INFO << "Setting IQUEST(10) to " << m_NREC << endreq; 00051 } 00052 00053 if (m_RECL != 1024) { 00054 log << MSG::INFO << "Setting Record Length to " << m_RECL << endreq; 00055 } 00056 00057 // Return an error if output file has not been specified 00058 if( undefFileName == m_defFileName ) { 00059 log << MSG::WARNING << "HBOOK output file name missing!!" << endreq; 00060 INIT_HBOOK( m_NPAWC ); 00061 } 00062 else { 00063 INIT_HBOOK( stat_dir.substr(1,stat_dir.size()), m_defFileName, 00064 m_NPAWC, m_NREC, m_RECL ); 00065 } 00066 00067 if ( ::toupper(m_rowWisePolicy[0]) == 'U' ) { 00068 s_dataTypePolicy = USE_DATA_TYPES; 00069 } 00070 else if ( ::toupper(m_rowWisePolicy[0]) == 'F' ) { 00071 if ( ::toupper(m_rowWisePolicy[1]) == 'O' ) { 00072 s_dataTypePolicy = FORTRAN_STYLE; 00073 } 00074 else { 00075 s_dataTypePolicy = FLOAT_ONLY; 00076 } 00077 } 00078 else if ( ::toupper(m_rowWisePolicy[0]) == 'H' ) { 00079 s_dataTypePolicy = HUNGARIAN_STYLE; 00080 } 00081 } 00082 return status; 00083 } 00084 00086 StatusCode HbookCnv::PersSvc::finalize() { 00087 // Close HBOOK only if the HBOOK output file name is defined 00088 if( undefFileName != m_defFileName ) { 00089 CLOSE_HBOOK( stat_dir.substr(1,stat_dir.size()), m_defFileName ); 00090 } 00091 return ConversionSvc::finalize(); 00092 } 00093 00095 StatusCode HbookCnv::PersSvc::createRep(DataObject* pObject, 00096 IOpaqueAddress*& refpAddr) { 00097 00098 StatusCode sc = StatusCode::SUCCESS; 00099 00100 // Convert histograms only if HBOOK output file name is defined 00101 if( undefFileName != m_defFileName ) { // Valid HBOOK output file name 00102 00103 // Manipulate global output level to switch on/off histogram printing 00104 IProperty* msgProp; 00105 msgSvc()->queryInterface( IID_IProperty, (void**)&msgProp ); 00106 std::string dfltLevel; 00107 StatusCode scl = msgProp->getProperty( "OutputLevel", dfltLevel ); 00108 if ( m_histDo && scl.isSuccess() ) { 00109 msgProp->setProperty( "OutputLevel", "3" ); 00110 } 00111 else { 00112 msgProp->setProperty( "OutputLevel", "4" ); 00113 } 00114 00115 //Save the histograms 00116 sc = ConversionSvc::createRep(pObject, refpAddr); 00117 00118 // Reset the global output level to its previous value 00119 if( scl.isSuccess() ) msgProp->setProperty( "OutputLevel", dfltLevel ); 00120 00121 } 00122 return sc; 00123 } 00124 00126 StatusCode HbookCnv::PersSvc::fillRepRefs(IOpaqueAddress* pAddr, DataObject* pObject) { 00127 // Convert histograms only if HBOOK output file name is defined 00128 if( undefFileName != m_defFileName ) { // Valid HBOOK output file name 00129 return ConversionSvc::fillRepRefs(pAddr, pObject); 00130 } 00131 return StatusCode::SUCCESS; 00132 } 00133 00135 HbookCnv::PersSvc::PersSvc(const std::string& name, ISvcLocator* svc) 00136 : ConversionSvc(name, svc, HBOOK_StorageType) 00137 { 00138 00139 declareProperty("OutputFile", m_defFileName = undefFileName); 00140 declareProperty("PersistencySvc", m_persistencySvc = "HistogramPersistencySvc"); 00141 declareProperty("RowWiseNtuplePolicy", m_rowWisePolicy = "FLOAT_ONLY"); 00142 declareProperty("PrintHistos", m_histDo = false ); 00143 declareProperty("NPAWC",m_NPAWC = 250000); // size of PAWC common block 00144 declareProperty("IQUEST10",m_NREC = -1); // IQUEST(10) 00145 declareProperty("RecordLength",m_RECL = 1024); // Record length in HROPEN 00146 } 00147 00149 HbookCnv::PersSvc::~PersSvc() { 00150 }