00001
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "GaudiKernel/ISvcLocator.h"
00004 #include "GaudiKernel/IDataProviderSvc.h"
00005 #include "GaudiKernel/Bootstrap.h"
00006 #include "GaudiKernel/IMessageSvc.h"
00007 #include "GaudiKernel/StatusCode.h"
00008
00009 #include "GaudiKernel/SmartDataPtr.h"
00010 #include "ReconEvent/ReconEvent.h"
00011 #include "EmcRec/EmcRecTDS.h"
00012
00013 using namespace std;
00014
00015 StatusCode EmcRecTDS::RegisterToTDS(RecEmcHitMap& aHitMap,
00016 RecEmcClusterMap& aClusterMap, RecEmcShowerMap& aShowerMap)
00017 {
00018 RegisterCluster(aClusterMap);
00019 RegisterShower(aShowerMap);
00020 RegisterHit(aHitMap);
00021 return StatusCode::SUCCESS;
00022 }
00023
00024 StatusCode EmcRecTDS::RegisterReconEvent()
00025 {
00026 IMessageSvc* msgSvc;
00027 Gaudi::svcLocator()->service("MessageSvc", msgSvc);
00028 MsgStream log(msgSvc, "EmcRecTDS");
00029
00030 IDataProviderSvc* eventSvc;
00031 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
00032
00033
00034 DataObject *aReconEvent;
00035 eventSvc->findObject("/Event/Recon",aReconEvent);
00036 if(aReconEvent==NULL) {
00037 log << MSG::INFO << "EmcRecTDS::RegisterReconEvent()" << endreq;
00038
00039 aReconEvent = new ReconEvent();
00040 StatusCode sc = eventSvc->registerObject("/Event/Recon",aReconEvent);
00041 if(sc!=StatusCode::SUCCESS) {
00042 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
00043 return StatusCode::FAILURE;
00044 }
00045 }
00046
00047 return StatusCode::SUCCESS;
00048 }
00049
00050 StatusCode EmcRecTDS::RegisterHit(RecEmcHitMap& aHitMap)
00051 {
00052 RegisterReconEvent();
00053
00054 IMessageSvc* msgSvc;
00055 Gaudi::svcLocator()->service("MessageSvc", msgSvc);
00056 MsgStream log(msgSvc, "EmcRecTDS");
00057 log << MSG::INFO << "EmcRecTDS::RegisterHit()" << endreq;
00058
00059 IDataProviderSvc* eventSvc;
00060 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
00061
00062 RecEmcHitCol *aRecEmcHitCol = new RecEmcHitCol;
00063 RecEmcHitMap::iterator iHitMap;
00064 for(iHitMap=aHitMap.begin();
00065 iHitMap!=aHitMap.end();
00066 iHitMap++){
00067 aRecEmcHitCol->add(new RecEmcHit(iHitMap->second));
00068 }
00069
00070
00071 StatusCode sc;
00072 DataObject *aRecEmcHitEvent;
00073 eventSvc->findObject("/Event/Recon/RecEmcHitCol", aRecEmcHitEvent);
00074 if(aRecEmcHitEvent!=NULL) {
00075
00076 sc = eventSvc->unregisterObject("/Event/Recon/RecEmcHitCol");
00077 delete aRecEmcHitEvent;
00078 if(sc!=StatusCode::SUCCESS) {
00079 log << MSG::FATAL << "Could not unregister EMC shower collection" << endreq;
00080 return( StatusCode::FAILURE);
00081 }
00082 }
00083
00084 sc = eventSvc->registerObject("/Event/Recon/RecEmcHitCol", aRecEmcHitCol);
00085 if(sc!=StatusCode::SUCCESS) {
00086 log << MSG::FATAL << "Could not register EMC hit collection" << endreq;
00087 return( StatusCode::FAILURE);
00088 }
00089
00090 return StatusCode::SUCCESS;
00091 }
00092
00093 StatusCode EmcRecTDS::RegisterCluster(RecEmcClusterMap& aClusterMap)
00094 {
00095 RegisterReconEvent();
00096
00097 IMessageSvc* msgSvc;
00098 Gaudi::svcLocator()->service("MessageSvc", msgSvc);
00099 MsgStream log(msgSvc, "EmcRecTDS");
00100 log << MSG::INFO << "EmcRecTDS::RegisterCluster()" << endreq;
00101
00102 IDataProviderSvc* eventSvc;
00103 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
00104
00105 RecEmcClusterCol *aRecEmcClusterCol = new RecEmcClusterCol;
00106 RecEmcClusterMap::iterator iClusterMap;
00107 for(iClusterMap=aClusterMap.begin();
00108 iClusterMap!=aClusterMap.end();
00109 iClusterMap++){
00110 aRecEmcClusterCol->add(new RecEmcCluster(iClusterMap->second));
00111 }
00112
00113
00114 StatusCode sc;
00115 DataObject *aRecEmcClusterEvent;
00116 eventSvc->findObject("/Event/Recon/RecEmcClusterCol", aRecEmcClusterEvent);
00117 if(aRecEmcClusterEvent!=NULL) {
00118
00119 sc = eventSvc->unregisterObject("/Event/Recon/RecEmcClusterCol");
00120 delete aRecEmcClusterEvent;
00121 if(sc!=StatusCode::SUCCESS) {
00122 log << MSG::FATAL << "Could not unregister EMC cluster collection" << endreq;
00123 return( StatusCode::FAILURE);
00124 }
00125 }
00126
00127 sc = eventSvc->registerObject("/Event/Recon/RecEmcClusterCol", aRecEmcClusterCol);
00128 if(sc!=StatusCode::SUCCESS) {
00129 log << MSG::FATAL << "Could not register EMC cluster collection" << endreq;
00130 return( StatusCode::FAILURE);
00131 }
00132
00133 return StatusCode::SUCCESS;
00134 }
00135
00136 StatusCode EmcRecTDS::RegisterShower(RecEmcShowerMap& aShowerMap)
00137 {
00138 RegisterReconEvent();
00139
00140 IMessageSvc* msgSvc;
00141 Gaudi::svcLocator()->service("MessageSvc", msgSvc);
00142 MsgStream log(msgSvc, "EmcRecTDS");
00143 log << MSG::INFO << "EmcRecTDS::RegisterShower()" << endreq;
00144
00145 IDataProviderSvc* eventSvc;
00146 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
00147
00148 SmartDataPtr<RecEmcClusterCol> aClusterCol(eventSvc,"/Event/Recon/RecEmcClusterCol");
00149 if (!aClusterCol) {
00150 log << MSG::INFO << "Could not find emcRecClusterCol" << endreq;
00151 }
00152
00153
00154 RecEmcShowerCol *aRecEmcShowerCol = new RecEmcShowerCol;
00155 RecEmcShowerVec aShowerVec;
00156
00157 RecEmcShowerMap::iterator iShowerMap;
00158 for(iShowerMap=aShowerMap.begin();
00159 iShowerMap!=aShowerMap.end();
00160 iShowerMap++) {
00161
00162 if(aClusterCol) {
00163 RecEmcID clusterId(iShowerMap->second.getClusterId());
00164 RecEmcClusterCol::iterator iClusterCol;
00165 for(iClusterCol=aClusterCol->begin();
00166 iClusterCol!=aClusterCol->end();
00167 iClusterCol++){
00168 if(clusterId==(*iClusterCol)->getClusterId()) {
00169 iShowerMap->second.Cluster(*iClusterCol);
00170 break;
00171
00172 }
00173 }
00174 }
00175 aShowerVec.push_back(iShowerMap->second);
00176 }
00177 sort(aShowerVec.begin(), aShowerVec.end(), greater<RecEmcShower>());
00178 RecEmcShowerVec::iterator iShowerVec;
00179 for(iShowerVec=aShowerVec.begin();
00180 iShowerVec!=aShowerVec.end();
00181 iShowerVec++) {
00182 aRecEmcShowerCol->add(new RecEmcShower(*iShowerVec));
00183 }
00184
00185
00186 StatusCode sc;
00187 DataObject *aRecEmcShowerEvent;
00188 eventSvc->findObject("/Event/Recon/RecEmcShowerCol", aRecEmcShowerEvent);
00189 if(aRecEmcShowerEvent!=NULL) {
00190
00191 StatusCode sc = eventSvc->unregisterObject("/Event/Recon/RecEmcShowerCol");
00192 delete aRecEmcShowerEvent;
00193 if(sc!=StatusCode::SUCCESS) {
00194 log << MSG::FATAL << "Could not unregister EMC shower collection" << endreq;
00195 return( StatusCode::FAILURE);
00196 }
00197 }
00198
00199 sc = eventSvc->registerObject("/Event/Recon/RecEmcShowerCol", aRecEmcShowerCol);
00200 if(sc!=StatusCode::SUCCESS) {
00201 log << MSG::FATAL << "Could not register EMC shower collection" << endreq;
00202 return( StatusCode::FAILURE);
00203 }
00204
00205 return StatusCode::SUCCESS;
00206 }
00207
00208 StatusCode EmcRecTDS::CheckRegister()
00209 {
00210 IMessageSvc* msgSvc;
00211 Gaudi::svcLocator()->service("MessageSvc", msgSvc);
00212 MsgStream log(msgSvc, "EmcRecTDS");
00213 log << MSG::INFO << "EmcRecTDS::CheckRegister()" << endreq;
00214
00215 IDataProviderSvc* eventSvc;
00216 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
00217
00218
00219 SmartDataPtr<RecEmcHitCol> aHitCol(eventSvc,"/Event/Recon/RecEmcHitCol");
00220 if (!aHitCol) {
00221 log << MSG::FATAL << "Could not find emcRecHitCol" << endreq;
00222 return( StatusCode::FAILURE);
00223 }
00224
00225 RecEmcHitCol::iterator iHitCol;
00226 for(iHitCol=aHitCol->begin();
00227 iHitCol!=aHitCol->end();
00228 iHitCol++){
00229
00230 }
00231
00232
00233 SmartDataPtr<RecEmcClusterCol> aClusterCol(eventSvc,"/Event/Recon/RecEmcClusterCol");
00234 if (!aClusterCol) {
00235 log << MSG::FATAL << "Could not find emcRecClusterCol" << endreq;
00236 return( StatusCode::FAILURE);
00237 }
00238
00239 RecEmcClusterCol::iterator iClusterCol;
00240 for(iClusterCol=aClusterCol->begin();
00241 iClusterCol!=aClusterCol->end();
00242 iClusterCol++){
00243
00244 }
00245
00246
00247 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc,"/Event/Recon/RecEmcShowerCol");
00248 if (!aShowerCol) {
00249 log << MSG::FATAL << "Could not find emcRecShowerCol" << endreq;
00250 return( StatusCode::FAILURE);
00251 }
00252
00253 RecEmcShowerCol::iterator iShowerCol;
00254 for(iShowerCol=aShowerCol->begin();
00255 iShowerCol!=aShowerCol->end();
00256 iShowerCol++){
00257
00258 }
00259
00260 return StatusCode::SUCCESS;
00261 }