00001 #define ntupleWriter_writeJunkAlg_CPP
00002
00003
00004
00005 #include "GaudiKernel/MsgStream.h"
00006 #include "GaudiKernel/AlgFactory.h"
00007 #include "GaudiKernel/IDataProviderSvc.h"
00008 #include "GaudiKernel/SmartDataPtr.h"
00009 #include "GaudiKernel/Algorithm.h"
00010
00011
00012 #include "GaudiKernel/INTupleSvc.h"
00013 #include "GaudiKernel/INTuple.h"
00014 #include "GaudiKernel/NTuple.h"
00015 #include "GaudiKernel/SmartDataPtr.h"
00016 #include "GaudiKernel/StatusCode.h"
00017
00018 #include "ntupleWriterSvc/INTupleWriterSvc.h"
00019
00020
00029 class writeJunkAlg : public Algorithm {
00030
00031 public:
00033 writeJunkAlg(const std::string& name, ISvcLocator* pSvcLocator);
00034
00035 StatusCode initialize();
00036 StatusCode execute();
00037 StatusCode finalize();
00038
00039 private:
00040 std::string m_tupleName;
00041 float m_float;
00042
00043 INTupleWriterSvc *m_ntupleWriteSvc;
00044
00045 };
00046
00047
00048 static const AlgFactory<writeJunkAlg> Factory;
00049 const IAlgFactory& writeJunkAlgFactory = Factory;
00050
00052
00053 Algorithm(name, pSvcLocator){
00054
00055 declareProperty("tupleName", m_tupleName="");
00056
00057 }
00058
00059
00062 StatusCode writeJunkAlg::initialize() {
00063
00064 StatusCode sc = StatusCode::SUCCESS;
00065
00066 MsgStream log(msgSvc(), name());
00067
00068
00069 setProperties();
00070
00071
00072 sc = service("ntupleWriterSvc", m_ntupleWriteSvc);
00073
00074 if( sc.isFailure() ) {
00075 log << MSG::ERROR << "writeJunkAlg failed to get the ntupleWriterSvc" << endreq;
00076 return sc;
00077 }
00078
00079 return sc;
00080 }
00081
00082
00083
00084
00085 StatusCode writeJunkAlg::execute() {
00086
00087 static int callCount = 0;
00088
00089 StatusCode sc = StatusCode::SUCCESS;
00090 MsgStream log( msgSvc(), name() );
00091
00092 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "CallCount", callCount);
00093
00094 m_float = 700.05f;
00095 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "MyFirstItem", m_float);
00096
00097 float zero = 0.0;
00098
00099 float bad = 100.0/zero;
00100 sc = m_ntupleWriteSvc->addItem(m_tupleName.c_str(), "BadValue", bad);
00101
00102
00103 if (callCount == 5) m_ntupleWriteSvc->storeRowFlag(false);
00104
00105 if (callCount%10 == 0)
00106 m_ntupleWriteSvc->saveNTuples();
00107
00108 ++callCount;
00109
00110 return sc;
00111 }
00112
00113
00114
00115 StatusCode writeJunkAlg::finalize() {
00116 StatusCode sc = StatusCode::SUCCESS;
00117
00118 MsgStream log(msgSvc(), name());
00119 log << MSG::INFO << "finalize writeJunkAlg " << endreq;
00120
00121 return StatusCode::SUCCESS;
00122 }
00123
00124
00125
00126
00127