BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
DTag.cxx
Go to the documentation of this file.
1#include "GaudiKernel/SmartIF.h"
2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/AlgFactory.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/IDataManagerSvc.h"
6#include "GaudiKernel/SmartDataPtr.h"
7#include "GaudiKernel/IDataProviderSvc.h"
8#include "GaudiKernel/PropertyMgr.h"
10#include "EventModel/Event.h"
13#include "DTagAlg/DTag.h"
14#include <vector>
15
16DECLARE_COMPONENT(DTag)
17//**************************************************************************************
18DTag::DTag(const std::string& name, ISvcLocator* pSvcLocator) :
19 Algorithm(name, pSvcLocator) {
20 //Declare the properties
21 declareProperty("NeutralDReconstruction", m_recD0 = true);
22 declareProperty("ChargedDReconstruction", m_recDp = true);
23 declareProperty("DsReconstruction", m_recDs = true);
24 declareProperty("LambdaCReconstruction", m_recLc = true);
25 // declareProperty("RawDstOnly", m_rawdstonly = true);
26}
27
28// ***********************************************************************************
29StatusCode DTag::initialize() {
30
31 MsgStream log(msgSvc(), name());
32
33 log << MSG::INFO << "creating DTag sub Algorithm" << endreq;
34
35 StatusCode sc;
36
37
38
39
40 if(m_recD0) {
41 sc = createSubAlgorithm("NeutralDReconstruction", "NeutralDReconstruction", m_NeutralDReconstruction);
42 if(sc.isFailure()) {
43 log << MSG::ERROR << "Error while creating D0Reconstruction" << endreq;
44 return StatusCode::FAILURE;
45 }
46 }
47
48 if(m_recDp) {
49 sc = createSubAlgorithm("ChargedDReconstruction", "ChargedDReconstruction", m_ChargedDReconstruction);
50 if(sc.isFailure()) {
51 log << MSG::ERROR << "Error while creating D+Reconstruction" << endreq;
52 return StatusCode::FAILURE;
53 }
54 }
55
56 if(m_recDs) {
57 sc = createSubAlgorithm("DsReconstruction", "DsReconstruction", m_DsReconstruction);
58 if(sc.isFailure()) {
59 log << MSG::ERROR << "Error while creating DsReconstruction" << endreq;
60 return StatusCode::FAILURE;
61 }
62 }
63
64
65 if(m_recLc) {
66 sc = createSubAlgorithm("LambdaCReconstruction", "LambdaCReconstruction", m_LambdaCReconstruction);
67 if(sc.isFailure()) {
68 log << MSG::ERROR << "Error while creating LcReconstruction" << endreq;
69 return StatusCode::FAILURE;
70 }
71 }
72
73 log << MSG::INFO << "successfully return from initialize()" <<endmsg;
74 return StatusCode::SUCCESS;
75
76}
77
78StatusCode DTag::registerParent(MsgStream& log) {
79 DataObject *aEvtRecEvent;
80 eventSvc()->findObject("/Event/EvtRec",aEvtRecEvent);
81 if (aEvtRecEvent == NULL) {
82 aEvtRecEvent = new EvtRecEvent();
83 StatusCode sc = eventSvc()->registerObject("/Event/EvtRec",aEvtRecEvent);
84 if (sc != StatusCode::SUCCESS) {
85 log << MSG::FATAL << "Could not register EvtRecEvent" <<endreq;
86 return StatusCode::FAILURE;
87 }
88 }
89 return StatusCode::SUCCESS;
90}
91
92StatusCode DTag::clearEvtRecDTagCol(MsgStream& log) {
93 StatusCode sc = registerParent(log);
94 if (sc != StatusCode::SUCCESS) {
95 return sc;
96 }
97
98 DataObject* aEvtRecDTagCol;
99 eventSvc()->findObject("/Event/EvtRec/EvtRecDTagCol",aEvtRecDTagCol);
100 if (aEvtRecDTagCol != NULL) {
101 //IDataManagerSvc* dataManSvc = dynamic_cast<IDataManagerSvc*>(eventSvc());
102 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
103 dataManSvc->clearSubTree("/Event/EvtRec/EvtRecDTagCol");
104 eventSvc()->unregisterObject("/Event/EvtRec/EvtRecDTagCol");
105 }
106
107 SmartDataPtr<EvtRecDTagCol> evtRecDTagCol(eventSvc(), EventModel::EvtRec::EvtRecDTagCol);
108 if( evtRecDTagCol != NULL){
109 //IDataManagerSvc* dataManSvc = dynamic_cast<IDataManagerSvc*>(eventSvc());
110 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
111 dataManSvc->clearSubTree("/Event/EvtRec/EvtRecDTagCol");
112 eventSvc()->unregisterObject("/Event/EvtRec/EvtRecDTagCol");
113 }
114
115 return StatusCode::SUCCESS;
116}
117
118void DTag::registerEvtRecDTagCol(MsgStream& log) {
119 EvtRecDTagCol* aNewEvtRecDTagCol = new EvtRecDTagCol;
120 StatusCode sc = eventSvc()->registerObject("/Event/EvtRec/EvtRecDTagCol",
121 aNewEvtRecDTagCol);
122 if (sc != StatusCode::SUCCESS) {
123 log << MSG::FATAL << "Could not register EvtRecDTagCol in TDS!" << endreq;
124 }
125}
126
127// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
128StatusCode DTag::execute() {
129
130
131 //check if DTagList exists
132 //if true, will exit the program
133 SmartDataPtr<EvtRecDTagCol> evtRecDTagCol(eventSvc(), EventModel::EvtRec::EvtRecDTagCol);
134 if( evtRecDTagCol != NULL ){
135 if ( evtRecDTagCol->size()>0 ) {
136 cout << "************************************************"<<endl;
137 cout << "EvtRecDTagCol already exists in this file!" << endl;
138 cout << " Please run this program on a raw dst file!" << endl;
139 cout << " *** This job is now being killed. ***" << endl;
140 cout << "************************************************"<<endl;
141 return StatusCode::FAILURE;
142 } /// End of "evtRecDTagCol->size()>0" IF
143 } /// End of "evtRecDTagCol != NULL" IF
144
145
146 MsgStream log(msgSvc(), name());
147 StatusCode sc = clearEvtRecDTagCol(log);
148 if (sc != StatusCode::SUCCESS) {
149 return sc;
150 }
151
152 DataObject* aEvtRecDTagCol;
153 eventSvc()->findObject("/Event/EvtRec/EvtRecDTagCol", aEvtRecDTagCol);
154 if (aEvtRecDTagCol == NULL) {
155 registerEvtRecDTagCol(log);
156 }
157
158 std::vector<Algorithm*>::const_iterator it = subAlgorithms()->begin();
159 std::vector<Algorithm*>::const_iterator end = subAlgorithms()->end();
160 for(; it != end; it++) {
161 sc = (*it)->execute();
162 if(sc.isFailure()) {
163 log << "Error executing selection " << (*it)->name() << endreq;
164 }
165 }
166
167 return StatusCode::SUCCESS;
168}
169
170// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
171StatusCode DTag::finalize() {
172
173 MsgStream log(msgSvc(), name());
174 log << MSG::INFO << "in finalize()" << endmsg;
175 return StatusCode::SUCCESS;
176}
177
ObjectVector< EvtRecDTag > EvtRecDTagCol
Definition EvtRecDTag.h:286
IMessageSvc * msgSvc()
#define NULL
Definition DTag.h:8
StatusCode execute()
Definition DTag.cxx:128
StatusCode finalize()
Definition DTag.cxx:171
StatusCode initialize()
Definition DTag.cxx:29
_EXTERN_ std::string EvtRecDTagCol
Definition EventModel.h:122