CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/EventFilter/EcalRawToDigi/src/DCCDataUnpacker.cc

Go to the documentation of this file.
00001 #include "EventFilter/EcalRawToDigi/interface/DCCDataUnpacker.h"
00002 #include "EventFilter/EcalRawToDigi/interface/DCCEBEventBlock.h"
00003 #include "EventFilter/EcalRawToDigi/interface/DCCEEEventBlock.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00006 #include "EventFilter/EcalRawToDigi/interface/EcalElectronicsMapper.h"
00007 #include <set>
00008 
00009 bool DCCDataUnpacker::silentMode_ = false;
00010 
00011 DCCDataUnpacker::DCCDataUnpacker( 
00012   EcalElectronicsMapper * mapper, bool hU, bool srpU, bool tccU, bool feU , bool memU, bool syncCheck, bool feIdCheck, bool forceToKeepFRdata
00013 ){ 
00014   electronicsMapper_ = mapper;
00015   ebEventBlock_   = new DCCEBEventBlock(this,mapper,hU,srpU,tccU,feU,memU,forceToKeepFRdata);
00016   eeEventBlock_   = new DCCEEEventBlock(this,mapper,hU,srpU,tccU,feU,memU,forceToKeepFRdata);
00017   if(syncCheck){
00018     ebEventBlock_->enableSyncChecks();  
00019     eeEventBlock_->enableSyncChecks();
00020   }
00021   if(feIdCheck){
00022     ebEventBlock_->enableFeIdChecks();  
00023     eeEventBlock_->enableFeIdChecks();
00024   }
00025 }
00026 
00027 
00028 void DCCDataUnpacker::unpack(const uint64_t* buffer, size_t bufferSize, unsigned int smId, unsigned int fedId){
00029   //buffer is pointer to binary data
00030   //See if this fed is on EB or in EE
00031 
00032   if(smId>9&&smId<46){ 
00033     
00034     currentEvent_      = ebEventBlock_;
00035     ebEventBlock_    ->updateCollectors();
00036     ebEventBlock_    ->unpack(buffer,bufferSize,fedId); 
00037          
00038   }
00039   else{               
00040    
00041     currentEvent_     = eeEventBlock_;
00042     eeEventBlock_    ->updateCollectors();
00043     eeEventBlock_    ->unpack(buffer,bufferSize,fedId); 
00044 
00045   }
00046     
00047 }
00048 
00049 DCCDataUnpacker::~DCCDataUnpacker(){
00050   delete ebEventBlock_;
00051   delete eeEventBlock_;
00052 }
00053 
00054 uint16_t DCCDataUnpacker::getChannelStatus(const DetId& id) const
00055 {
00056   // return code for situation of missing channel record
00057   // equal to "non responding isolated channel (dead of type other)":
00058   //   https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideEcalRecoLocalReco#Treatment_of_problematic_channel
00059   // TODO: think on a better way how to cover this case
00060   const uint16_t NO_DATA = 11;
00061   
00062   if (chdb_ == 0) {
00063     edm::LogError("IncorrectMapping")
00064       << "ECAL channel status database do not initialized";
00065     return NO_DATA;
00066   }
00067   
00068   EcalChannelStatus::const_iterator pCh = chdb_->find(id);
00069   
00070   if (pCh != chdb_->end()) {
00071     return pCh->getStatusCode();
00072   }
00073   else {
00074     edm::LogError("IncorrectMapping")
00075       << "No channel status record found for detit = " << id.rawId();
00076     return NO_DATA;
00077   }
00078 }
00079 
00080 uint16_t DCCDataUnpacker::getChannelValue(const DetId& id) const
00081 {
00082   return getChannelStatus(id) & 0x1F;
00083 }
00084 
00085 uint16_t DCCDataUnpacker::getChannelValue(const int fed, const int ccu, const int strip, const int xtal) const
00086 {
00087   // conversion FED ID [601 - 654] -> DCC ID [1 - 54]
00088   const int dcc = electronicsMapper_->getSMId(fed);
00089   
00090   // convert (dcc, ccu, strip, xtal) -> DetId
00091   const EcalElectronicsId eid(dcc, ccu, strip, xtal);
00092   const DetId id = electronicsMapper_->mapping()->getDetId(eid);
00093   
00094   return getChannelStatus(id) & 0x1F;
00095 }
00096 
00097 uint16_t DCCDataUnpacker::getCCUValue(const int fed, const int ccu) const
00098 {
00099   // get list of crystals (DetId) which correspond to given CCU
00100   const int dcc = electronicsMapper_->getSMId(fed);
00101   const std::vector<DetId> xtals = electronicsMapper_->mapping()->dccTowerConstituents(dcc, ccu);
00102   
00103   // collect set of status codes of given CCU
00104   std::set<uint16_t> set;
00105   for (size_t i = 0; i < xtals.size(); ++i) {
00106     const uint16_t val = getChannelValue(xtals[i]);
00107     set.insert(val);
00108   }
00109   
00110   // if all crystals in CCU have the same status
00111   // then this status is treated as CCU status
00112   if (set.size() == 1) return *set.begin();
00113   
00114   // if there are several statuses:
00115   return 0;
00116 }