00001 #include "GaudiKernel/SmartIF.h"
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "GaudiKernel/AlgFactory.h"
00004 #include "GaudiKernel/ISvcLocator.h"
00005 #include "GaudiKernel/IDataManagerSvc.h"
00006 #include "GaudiKernel/SmartDataPtr.h"
00007 #include "GaudiKernel/IDataProviderSvc.h"
00008 #include "GaudiKernel/PropertyMgr.h"
00009 #include "EventModel/EventModel.h"
00010 #include "EventModel/Event.h"
00011 #include "EvtRecEvent/EvtRecDTag.h"
00012 #include "EvtRecEvent/EvtRecEvent.h"
00013 #include "DTagAlg/DTag.h"
00014 #include <vector>
00015
00016
00017
00018 DTag::DTag(const std::string& name, ISvcLocator* pSvcLocator) :
00019 Algorithm(name, pSvcLocator) {
00020
00021 declareProperty("NeutralDReconstruction", m_recD0 = true);
00022 declareProperty("ChargedDReconstruction", m_recDp = true);
00023 declareProperty("DsReconstruction", m_recDs = true);
00024
00025 }
00026
00027
00028 StatusCode DTag::initialize() {
00029
00030 MsgStream log(msgSvc(), name());
00031
00032 log << MSG::INFO << "creating DTag sub Algorithm" << endreq;
00033
00034 StatusCode sc;
00035
00036
00037
00038
00039 if(m_recD0) {
00040 sc = createSubAlgorithm("NeutralDReconstruction", "NeutralDReconstruction", m_NeutralDReconstruction);
00041 if(sc.isFailure()) {
00042 log << MSG::ERROR << "Error while creating D0Reconstruction" << endreq;
00043 return StatusCode::FAILURE;
00044 }
00045 }
00046
00047 if(m_recDp) {
00048 sc = createSubAlgorithm("ChargedDReconstruction", "ChargedDReconstruction", m_ChargedDReconstruction);
00049 if(sc.isFailure()) {
00050 log << MSG::ERROR << "Error while creating D+Reconstruction" << endreq;
00051 return StatusCode::FAILURE;
00052 }
00053 }
00054
00055 if(m_recDs) {
00056 sc = createSubAlgorithm("DsReconstruction", "DsReconstruction", m_DsReconstruction);
00057 if(sc.isFailure()) {
00058 log << MSG::ERROR << "Error while creating DsReconstruction" << endreq;
00059 return StatusCode::FAILURE;
00060 }
00061 }
00062
00063 log << MSG::INFO << "successfully return from initialize()" <<endmsg;
00064 return StatusCode::SUCCESS;
00065
00066 }
00067
00068 StatusCode DTag::registerParent(MsgStream& log) {
00069 DataObject *aEvtRecEvent;
00070 eventSvc()->findObject("/Event/EvtRec",aEvtRecEvent);
00071 if (aEvtRecEvent == NULL) {
00072 aEvtRecEvent = new EvtRecEvent();
00073 StatusCode sc = eventSvc()->registerObject("/Event/EvtRec",aEvtRecEvent);
00074 if (sc != StatusCode::SUCCESS) {
00075 log << MSG::FATAL << "Could not register EvtRecEvent" <<endreq;
00076 return StatusCode::FAILURE;
00077 }
00078 }
00079 return StatusCode::SUCCESS;
00080 }
00081
00082 StatusCode DTag::clearEvtRecDTagCol(MsgStream& log) {
00083 StatusCode sc = registerParent(log);
00084 if (sc != StatusCode::SUCCESS) {
00085 return sc;
00086 }
00087
00088 DataObject* aEvtRecDTagCol;
00089 eventSvc()->findObject("/Event/EvtRec/EvtRecDTagCol",aEvtRecDTagCol);
00090 if (aEvtRecDTagCol != NULL) {
00091
00092 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
00093 dataManSvc->clearSubTree("/Event/EvtRec/EvtRecDTagCol");
00094 eventSvc()->unregisterObject("/Event/EvtRec/EvtRecDTagCol");
00095 }
00096
00097 SmartDataPtr<EvtRecDTagCol> evtRecDTagCol(eventSvc(), EventModel::EvtRec::EvtRecDTagCol);
00098 if( evtRecDTagCol != NULL){
00099
00100 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
00101 dataManSvc->clearSubTree("/Event/EvtRec/EvtRecDTagCol");
00102 eventSvc()->unregisterObject("/Event/EvtRec/EvtRecDTagCol");
00103 }
00104
00105 return StatusCode::SUCCESS;
00106 }
00107
00108 void DTag::registerEvtRecDTagCol(MsgStream& log) {
00109 EvtRecDTagCol* aNewEvtRecDTagCol = new EvtRecDTagCol;
00110 StatusCode sc = eventSvc()->registerObject("/Event/EvtRec/EvtRecDTagCol",
00111 aNewEvtRecDTagCol);
00112 if (sc != StatusCode::SUCCESS) {
00113 log << MSG::FATAL << "Could not register EvtRecDTagCol in TDS!" << endreq;
00114 }
00115 }
00116
00117
00118 StatusCode DTag::execute() {
00119
00120
00121
00122
00123 SmartDataPtr<EvtRecDTagCol> evtRecDTagCol(eventSvc(), EventModel::EvtRec::EvtRecDTagCol);
00124 if( evtRecDTagCol != NULL ){
00125 if ( evtRecDTagCol->size()>0 ) {
00126 cout << "************************************************"<<endl;
00127 cout << "EvtRecDTagCol already exists in this file!" << endl;
00128 cout << " Please run this program on a raw dst file!" << endl;
00129 cout << " *** This job is now being killed. ***" << endl;
00130 cout << "************************************************"<<endl;
00131 return StatusCode::FAILURE;
00132 }
00133 }
00134
00135
00136 MsgStream log(msgSvc(), name());
00137 StatusCode sc = clearEvtRecDTagCol(log);
00138 if (sc != StatusCode::SUCCESS) {
00139 return sc;
00140 }
00141
00142 DataObject* aEvtRecDTagCol;
00143 eventSvc()->findObject("/Event/EvtRec/EvtRecDTagCol", aEvtRecDTagCol);
00144 if (aEvtRecDTagCol == NULL) {
00145 registerEvtRecDTagCol(log);
00146 }
00147
00148 std::vector<Algorithm*>::const_iterator it = subAlgorithms()->begin();
00149 std::vector<Algorithm*>::const_iterator end = subAlgorithms()->end();
00150 for(; it != end; it++) {
00151 sc = (*it)->execute();
00152 if(sc.isFailure()) {
00153 log << "Error executing selection " << (*it)->name() << endreq;
00154 }
00155 }
00156
00157
00158 return StatusCode::SUCCESS;
00159 }
00160
00161
00162 StatusCode DTag::finalize() {
00163
00164 MsgStream log(msgSvc(), name());
00165 log << MSG::INFO << "in finalize()" << endmsg;
00166 return StatusCode::SUCCESS;
00167 }
00168