00001 #include "RawDataProviderSvc/RawDataProviderSvc.h"
00002 #include "RawDataProviderSvc/MdcRawDataProvider.h"
00003 #include "GaudiKernel/Kernel.h"
00004 #include "GaudiKernel/IInterface.h"
00005 #include "GaudiKernel/IIncidentSvc.h"
00006 #include "GaudiKernel/Incident.h"
00007 #include "GaudiKernel/IIncidentListener.h"
00008 #include "GaudiKernel/StatusCode.h"
00009 #include "GaudiKernel/SvcFactory.h"
00010 #include "GaudiKernel/MsgStream.h"
00011 #include "GaudiKernel/IDataProviderSvc.h"
00012 #include "GaudiKernel/SmartDataPtr.h"
00013 #include "GaudiKernel/DataSvc.h"
00014 #include "MdcRecEvent/RecMdcHit.h"
00015 #include "Identifier/MdcID.h"
00016 #include "MdcCalibFunSvc/MdcCalibFunSvc.h"
00017 #include "RawEvent/RawDataUtil.h"
00018 #include "EvTimeEvent/RecEsTime.h"
00019
00020
00021 #include "GaudiKernel/ThreadGaudi.h"
00022
00023 #include <stdint.h>
00024 #include <vector>
00025
00026 using namespace std;
00027
00028 MdcRawDataProvider::MdcRawDataProvider() :
00029 RawDataProviderBase(),
00030 digiRef(0),
00031 m_mdcCalibFunSvc(0)
00032 {}
00033
00034
00035 MdcRawDataProvider::MdcRawDataProvider( const char* name ) :
00036 RawDataProviderBase( name ),
00037 digiRef(0),
00038 m_mdcCalibFunSvc(0)
00039 {}
00040
00041 MdcRawDataProvider::~MdcRawDataProvider() {
00042 }
00043
00044 StatusCode MdcRawDataProvider::initialize( ISvcLocator* pSvcLoc, IMessageSvc* pMsg ) {
00045 RawDataProviderBase::initialize( pSvcLoc,pMsg );
00046 return StatusCode::SUCCESS;
00047 }
00048
00049 void MdcRawDataProvider::handle(const Incident& inc){
00050 MsgStream log( m_msgSvc, m_name );
00051 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
00052 if ( inc.type() == "BeginEvent" ){
00053 digiRef.clear();
00054 }
00055 return;
00056 }
00057
00058 MdcDigiVec& MdcRawDataProvider::getMdcDigiVec(uint32_t control){
00059 MsgStream log(m_msgSvc, m_name);
00060 StatusCode sc;
00061 bool unRedo = ((control&b_unRedo)==b_unRedo);
00062 if(!unRedo) digiRef.clear();
00063 else if(digiRef.size()>0) return digiRef;
00064
00065 IDataProviderSvc* evtSvc;
00066
00067 std::string evtDataSvc_name("EventDataSvc");
00068 if(isGaudiThreaded(m_name)){
00069 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
00070 }
00071
00072 sc = m_svcLocator->service(evtDataSvc_name.c_str(),evtSvc,true);
00073 if (!sc.isSuccess()){
00074 log << MSG::FATAL << "Could not load EventDataSvc" << endreq;
00075 return digiRef;
00076 }
00077
00078
00079 int maxMdcDigi = control&i_maxMdcDigi;
00080
00081
00082 bool keepBadTdc = ((control&b_keepBadTdc)!=0x10000);
00083 double t0 = 0.;
00084 if (keepBadTdc){
00085
00086 sc = m_svcLocator->service("MdcCalibFunSvc", m_mdcCalibFunSvc);
00087 if ( sc.isFailure() ){
00088 log << MSG::FATAL << "Could not load MdcCalibFunSvc!" << endreq;
00089 return digiRef;
00090 }
00091
00092
00093 SmartDataPtr<RecEsTimeCol> esTimeCol(evtSvc,"/Event/Recon/RecEsTimeCol");
00094 if (!esTimeCol){
00095 log << MSG::INFO<< " Could not retrieve RecEsTimeCol"<< endreq;
00096 keepBadTdc = false;
00097 }else if( (esTimeCol->size()==0)) {
00098 log << MSG::INFO<< " Could not retrieve RecEsTimeCol"<< endreq;
00099 keepBadTdc = false;
00100 }else{
00101 RecEsTimeCol::iterator iter= esTimeCol->begin();
00102 for(; iter!=esTimeCol->end(); iter++){
00103 t0 = (*iter)->getTest();
00104 }
00105 }
00106 }
00107
00108
00109 bool m_hitInUse[43][288];
00110 for (int i=0; i<43; i++){
00111 for (int j=0; j<288; j++) m_hitInUse[i][j]=false;
00112 }
00113 bool dropHot = ((control&b_dropHot)==0x4000);
00114 if (dropHot){
00115 SmartDataPtr<RecMdcHitCol> recHitCol(evtSvc, "/Event/Recon/RecMdcHitCol");
00116 if (!recHitCol) {
00117 log << MSG::INFO << "Could not retrieve RecMdcHitCol" << endreq;
00118 dropHot = false;
00119 }else{
00120 RecMdcHitCol::iterator iter = recHitCol->begin();
00121 for ( ; iter != recHitCol->end(); iter++) {
00122 Identifier id = (*iter)->getMdcId();
00123 m_hitInUse[MdcID::layer(id)][MdcID::wire(id)] = true;
00124 }
00125 }
00126 }
00127
00128
00129 bool isSkipLayers = ((control&b_keepSkipped)!=0x8000) && (m_skipLayers.size()>0);
00130
00131 bool skipLayer[43];
00132 for (int i=0; i<43; i++){skipLayer[i]= false;}
00133 for(unsigned iSkip =0; iSkip < m_skipLayers.size(); iSkip++){
00134 skipLayer[m_skipLayers[iSkip]]=true;
00135 }
00136
00137
00138 int iDigi=0;
00139 int nMatchedDigi=0;
00140
00141 SmartDataPtr<MdcDigiCol> mdcDigiCol(evtSvc,"/Event/Digi/MdcDigiCol");
00142 if (sc!=StatusCode::SUCCESS) {
00143 log << MSG::FATAL << "Could not find MdcDigiCol!" << endreq;
00144 return digiRef;
00145 }
00146 MdcDigiCol::iterator iter = mdcDigiCol->begin();
00147 for (;iter != mdcDigiCol->end(); iter++,iDigi++ ) {
00148 MdcDigi *aDigi = (*iter);
00149 Identifier id = aDigi->identify();
00150 int layer = MdcID::layer(id);
00151 int wire = MdcID::wire(id);
00152 unsigned tdc = aDigi->getTimeChannel();
00153 unsigned adc = aDigi->getChargeChannel();
00154 unsigned overflow = aDigi->getOverflow();
00155
00156
00157 if ( ((control&b_keepAllChannel)!=0x40000) && m_mdcCalibFunSvc
00158 && m_mdcCalibFunSvc->getWireEff(layer,wire) < m_effThreshold) continue;
00159
00160
00161 if ( isSkipLayers && skipLayer[layer] ) continue;
00162
00163
00164 if ( dropHot && m_hitInUse[layer][wire]) continue;
00165
00166
00167
00168
00169
00170
00171
00172 if ( ((control&b_keepUnmatch)!=0x2000) &&
00173 (((overflow & 1)>0) ||
00174 (((overflow&12)!=12)&&((overflow&12)!=0)) ||
00175 (tdc==0x7FFFFFFF) || (adc== 0x7FFFFFFF) ) ) { continue; }
00176
00177
00178
00179
00180 if (keepBadTdc) {
00181
00182 double T0Walk = 0.;
00183 if (m_mdcCalibFunSvc) { T0Walk = m_mdcCalibFunSvc->getT0(layer,wire)
00184 + m_mdcCalibFunSvc->getTimeWalk(layer,adc); }
00185 if((RawDataUtil::MdcTime(tdc) - T0Walk - t0)<-10.) continue;
00186 }
00187
00188
00189 nMatchedDigi++;
00190 if ((maxMdcDigi>0) && (nMatchedDigi > maxMdcDigi)){
00191 digiRef.clear();
00192 return digiRef;
00193 }
00194
00195 digiRef.push_back(aDigi);
00196 }
00197 return digiRef;
00198 }