00058 {
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 IMdcCalibFunSvc* imdcCalibSvc;
00087 sc = m_svcLocator->service("MdcCalibFunSvc", m_mdcCalibFunSvc);
00088 if ( sc.isFailure() ){
00089 log << MSG::FATAL << "Could not load MdcCalibFunSvc!" << endreq;
00090 return digiRef;
00091 }
00092
00093
00094 SmartDataPtr<RecEsTimeCol> esTimeCol(evtSvc,"/Event/Recon/RecEsTimeCol");
00095 if (!esTimeCol){
00096 log << MSG::INFO<< " Could not retrieve RecEsTimeCol"<< endreq;
00097 keepBadTdc = false;
00098 }else if( (esTimeCol->size()==0)) {
00099 log << MSG::INFO<< " Could not retrieve RecEsTimeCol"<< endreq;
00100 keepBadTdc = false;
00101 }else{
00102 RecEsTimeCol::iterator iter= esTimeCol->begin();
00103 for(; iter!=esTimeCol->end(); iter++){
00104 t0 = (*iter)->getTest();
00105 }
00106 }
00107 }
00108
00109
00110 bool m_hitInUse[43][288];
00111 for (int i=0; i<43; i++){
00112 for (int j=0; j<288; j++) m_hitInUse[i][j]=false;
00113 }
00114 bool dropHot = ((control&b_dropHot)==0x4000);
00115 if (dropHot){
00116 SmartDataPtr<RecMdcHitCol> recHitCol(evtSvc, "/Event/Recon/RecMdcHitCol");
00117 if (!recHitCol) {
00118 log << MSG::INFO << "Could not retrieve RecMdcHitCol" << endreq;
00119 dropHot = false;
00120 }else{
00121 RecMdcHitCol::iterator iter = recHitCol->begin();
00122 for ( ; iter != recHitCol->end(); iter++) {
00123 Identifier id = (*iter)->getMdcId();
00124 m_hitInUse[MdcID::layer(id)][MdcID::wire(id)] = true;
00125 }
00126 }
00127 }
00128
00129
00130 bool isSkipLayers = ((control&b_keepSkipped)!=0x8000) && (m_skipLayers.size()>0);
00131
00132 bool skipLayer[43];
00133 for (int i=0; i<43; i++){skipLayer[i]= false;}
00134 for(unsigned iSkip =0; iSkip < m_skipLayers.size(); iSkip++){
00135 skipLayer[m_skipLayers[iSkip]]=true;
00136 }
00137
00138
00139 int iDigi=0;
00140 int nMatchedDigi=0;
00141
00142 SmartDataPtr<MdcDigiCol> mdcDigiCol(evtSvc,"/Event/Digi/MdcDigiCol");
00143 if (sc!=StatusCode::SUCCESS) {
00144 log << MSG::FATAL << "Could not find MdcDigiCol!" << endreq;
00145 return digiRef;
00146 }
00147 MdcDigiCol::iterator iter = mdcDigiCol->begin();
00148 for (;iter != mdcDigiCol->end(); iter++,iDigi++ ) {
00149 MdcDigi *aDigi = (*iter);
00150 Identifier id = aDigi->identify();
00151 int layer = MdcID::layer(id);
00152 int wire = MdcID::wire(id);
00153 unsigned tdc = aDigi->getTimeChannel();
00154 unsigned adc = aDigi->getChargeChannel();
00155 unsigned overflow = aDigi->getOverflow();
00156
00157
00158 if( isSkipLayers && skipLayer[layer] ) continue;
00159
00160
00161 if ( dropHot && m_hitInUse[layer][wire]) continue;
00162
00163
00164
00165
00166
00167
00168
00169 if ( ((control&b_keepUnmatch)!=0x2000) &&
00170 (((overflow & 3)>0) ||
00171 (((overflow&12)!=12)&&((overflow&12)!=0)) ||
00172 (tdc==0x7FFFFFFF) || (adc== 0x7FFFFFFF) ) ) { continue; }
00173
00174
00175
00176
00177 if(keepBadTdc){
00178
00179 double T0Walk = 0.;
00180 if (m_mdcCalibFunSvc) { T0Walk = m_mdcCalibFunSvc->getT0(layer,wire)
00181 + m_mdcCalibFunSvc->getTimeWalk(layer,adc); }
00182 if((RawDataUtil::MdcTime(tdc) - T0Walk - t0)<-10.) continue;
00183 }
00184
00185
00186 nMatchedDigi++;
00187 if ((maxMdcDigi>0) && (nMatchedDigi > maxMdcDigi)){
00188 digiRef.clear();
00189 return digiRef;
00190 }
00191
00192 digiRef.push_back(aDigi);
00193 }
00194 return digiRef;
00195 }