CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/EventFilter/EcalRawToDigi/src/EcalUnpackerWorker.cc

Go to the documentation of this file.
00001 #include "EventFilter/EcalRawToDigi/interface/EcalUnpackerWorker.h"
00002 
00003 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalRecHitSimpleAlgo.h"
00004 
00005 
00006 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
00007 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
00008 #include "CondFormats/DataRecord/interface/EcalWeightXtalGroupsRcd.h"
00009 #include "CondFormats/DataRecord/interface/EcalTBWeightsRcd.h"
00010 
00011 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00012 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
00013 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"
00014 
00015 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerFactory.h"
00016 #include "RecoLocalCalo/EcalRecProducers/interface/EcalRecHitWorkerFactory.h"
00017 
00018 EcalUnpackerWorker::EcalUnpackerWorker(const edm::ParameterSet & conf){
00020   edm::ParameterSet DCCpset = conf.getParameter<edm::ParameterSet>("DCCDataUnpacker");
00021   edm::ParameterSet EEMpset = conf.getParameter<edm::ParameterSet>("ElectronicsMapper");
00022 
00023   unsigned int numbXtalTSamples_ = EEMpset.getParameter<unsigned int>("numbXtalTSamples");
00024   unsigned int numbTriggerTSamples_ = EEMpset.getParameter<unsigned int>("numbTriggerTSamples");
00025   
00026   if( numbXtalTSamples_ <6 || numbXtalTSamples_>64 || (numbXtalTSamples_-2)%4 ){
00027     edm::LogError("IncorrectConfiguration")<<"Unsuported number of xtal time samples : "<<numbXtalTSamples_
00028                                            <<"\n Valid Number of xtal time samples are : 6,10,14,18,...,62"; 
00029   }
00030   
00031   if( numbTriggerTSamples_ !=1 && numbTriggerTSamples_ !=4 && numbTriggerTSamples_ !=8  ){
00032     edm::LogError("IncorrectConfiguration")<<"Unsuported number of trigger time samples : "<<numbTriggerTSamples_
00033                                            <<"\n Valid number of trigger time samples are :  1, 4 or 8"; 
00034   }
00035   
00036   myMap_ = new EcalElectronicsMapper(numbXtalTSamples_, numbTriggerTSamples_);
00037   std::vector<int> oFl = DCCpset.getParameter<std::vector<int> >("orderedFedList");
00038   std::vector<int> oDl = DCCpset.getParameter<std::vector<int> >("orderedDCCIdList");
00039   bool readResult = myMap_->makeMapFromVectors(oFl,oDl);
00040   
00041   if(!readResult){
00042     edm::LogError("IncorrectConfiguration")<<"\n unable to configure EcalElectronicsMapper from vectors.";
00043   }
00044     
00045   unpacker_ = new DCCDataUnpacker(myMap_,
00046                                   DCCpset.getParameter<bool>("headerUnpacking"),
00047                                   DCCpset.getParameter<bool>("srpUnpacking"),
00048                                   DCCpset.getParameter<bool>("tccUnpacking"),
00049                                   DCCpset.getParameter<bool>("feUnpacking"),
00050                                   DCCpset.getParameter<bool>("memUnpacking"),
00051                                   DCCpset.getParameter<bool>("syncCheck"),
00052                                   DCCpset.getParameter<bool>("feIdCheck"),
00053                                   DCCpset.getParameter<bool>("forceKeepFRData") 
00054                                   );
00055   edm::LogInfo("EcalRawToRecHit")
00056     <<"\n ECAL RawToDigi within RawToRecHit configuration:"
00057     <<"\n Header  unpacking is "<<DCCpset.getParameter<bool>("headerUnpacking")
00058     <<"\n SRP Bl. unpacking is "<<DCCpset.getParameter<bool>("srpUnpacking")
00059     <<"\n TCC Bl. unpacking is "<<DCCpset.getParameter<bool>("tccUnpacking")
00060     <<"\n FE  Bl. unpacking is "<<DCCpset.getParameter<bool>("feUnpacking")
00061     <<"\n MEM Bl. unpacking is "<<DCCpset.getParameter<bool>("memUnpacking")
00062     <<"\n sync check is "<<DCCpset.getParameter<bool>("syncCheck")
00063     <<"\n feID check is "<<DCCpset.getParameter<bool>("feIdCheck")
00064     <<"\n force keep FR data is "<<DCCpset.getParameter<bool>("forceKeepFRData")
00065     <<"\n";
00066   
00067   unpacker_->setEBDigisCollection(&productDigisEB);
00068   unpacker_->setEEDigisCollection(&productDigisEE);
00069   unpacker_->setDccHeadersCollection(&productDccHeaders); 
00070   unpacker_->setInvalidGainsCollection(&productInvalidGains); 
00071   unpacker_->setInvalidGainsSwitchCollection(&productInvalidGainsSwitch);
00072   unpacker_->setInvalidChIdsCollection(&productInvalidChIds);
00073   unpacker_->setInvalidEEGainsCollection(&productInvalidEEGains);
00074   unpacker_->setInvalidEEGainsSwitchCollection(&productInvalidEEGainsSwitch);
00075   unpacker_->setInvalidEEChIdsCollection(&productInvalidEEChIds);
00076   unpacker_->setEBSrFlagsCollection(&productEBSrFlags);
00077   unpacker_->setEESrFlagsCollection(&productEESrFlags);
00078   unpacker_->setEcalTpsCollection(&productTps);
00079   unpacker_->setEcalPSsCollection(&productPSs);
00080   unpacker_->setInvalidTTIdsCollection(&productInvalidTTIds);  
00081   unpacker_->setInvalidZSXtalIdsCollection(&productInvalidZSXtalIds);
00082   unpacker_->setInvalidBlockLengthsCollection(&productInvalidBlockLengths);
00083   unpacker_->setPnDiodeDigisCollection(&productPnDiodeDigis);
00084   unpacker_->setInvalidMemTtIdsCollection(& productInvalidMemTtIds);
00085   unpacker_->setInvalidMemBlockSizesCollection(& productInvalidMemBlockSizes);
00086   unpacker_->setInvalidMemChIdsCollection(& productInvalidMemChIds);
00087   unpacker_->setInvalidMemGainsCollection(& productInvalidMemGains);
00088 
00089   DCCDataUnpacker::silentMode_ = conf.getUntrackedParameter<bool> ("silentMode",true);
00090 
00091   edm::ParameterSet UncalibPSet = conf.getParameter<edm::ParameterSet>("UncalibRHAlgo");
00092   std::string UncaliComponentName = UncalibPSet.getParameter<std::string>("Type");
00093   UncalibWorker_ = EcalUncalibRecHitWorkerFactory::get()->create(UncaliComponentName, UncalibPSet);
00094 
00095   edm::ParameterSet CalibPSet = conf.getParameter<edm::ParameterSet>("CalibRHAlgo");
00096   std::string CaliComponentName = CalibPSet.getParameter<std::string>("Type");
00097   CalibWorker_ = EcalRecHitWorkerFactory::get()->create(CaliComponentName, CalibPSet);
00098 
00099 }
00100 
00101 EcalUnpackerWorker::~EcalUnpackerWorker(){
00102   //delete everything that is own by the EcalUnpackerWorker
00103   delete myMap_;
00104   delete unpacker_;
00105   delete UncalibWorker_;
00106   delete CalibWorker_;
00107 
00108 }
00109 
00110 void EcalUnpackerWorker::setHandles(const EcalUnpackerWorkerRecord & iRecord) {
00111   iRecord.getRecord<EcalRegionCablingRecord>().get(cabling);  
00112   //the mapping is set as long as the mapping is valid. 
00113   myMap_->setEcalElectronicsMapping(cabling->mapping()); 
00114 }
00115 
00116 void EcalUnpackerWorker::set(const edm::EventSetup & es) const {
00117   UncalibWorker_->set(es);
00118   CalibWorker_->set(es);
00119 }
00120 
00121 void EcalUnpackerWorker::write(edm::Event & e) const{
00122   //write the collection in the event as requested.
00123 }
00124 
00125 void EcalUnpackerWorker::update(const edm::Event & e)const{
00127   evt=&e;
00128 
00129   const bool reserveMem =true;
00130 
00132   productDigisEB.reset(new EBDigiCollection);
00133   productDigisEE.reset(new EEDigiCollection);
00134   productDccHeaders.reset(new EcalRawDataCollection);
00135   productInvalidGains.reset(new EBDetIdCollection);
00136   productInvalidGainsSwitch.reset(new EBDetIdCollection);
00137   productInvalidChIds.reset(new EBDetIdCollection);
00138   productInvalidEEGains.reset(new EEDetIdCollection);
00139   productInvalidEEGainsSwitch.reset(new EEDetIdCollection);
00140   productInvalidEEChIds.reset(new EEDetIdCollection);
00141   productEBSrFlags.reset(new EBSrFlagCollection);
00142   productEESrFlags.reset(new EESrFlagCollection);
00143   productTps.reset(new EcalTrigPrimDigiCollection);
00144   productPSs.reset(new EcalPSInputDigiCollection);
00145   productInvalidTTIds.reset(new EcalElectronicsIdCollection);
00146   productInvalidZSXtalIds.reset(new EcalElectronicsIdCollection);
00147   productInvalidBlockLengths.reset(new EcalElectronicsIdCollection);
00148   productPnDiodeDigis.reset(new EcalPnDiodeDigiCollection);
00149   productInvalidMemTtIds.reset(new EcalElectronicsIdCollection);
00150   productInvalidMemBlockSizes.reset(new EcalElectronicsIdCollection);
00151   productInvalidMemChIds.reset(new EcalElectronicsIdCollection);
00152   productInvalidMemGains.reset(new EcalElectronicsIdCollection);
00153 
00154   if (reserveMem){
00155     productDigisEB->reserve(1700);
00156     productDigisEE->reserve(1700); 
00157   }
00158     
00159  }
00160 
00161 
00162 std::auto_ptr< EcalRecHitCollection > EcalUnpackerWorker::work(const uint32_t & index, const FEDRawDataCollection & rawdata)const{
00163   MyWatcher watcher("Worker");
00164   LogDebug("EcalRawToRecHit|Worker")<<"is going to work on index: "<<index
00165                                     <<"for fed Id: "<<EcalRegionCabling::fedIndex(index)<<watcher.lap();
00166 
00167   int fedIndex = EcalRegionCabling::fedIndex(index);
00168 
00169   const FEDRawData & fedData = rawdata.FEDData(fedIndex);
00170 
00171   //remember where the iterators were before unpacking
00172    LogDebug("EcalRawToRecHit|Worker")
00173     <<"size of digi collections before unpacking: "
00174     <<(*unpacker_->ebDigisCollection())->size()
00175     <<" "<<(*unpacker_->eeDigisCollection())->size()
00176     <<watcher.lap();
00177 
00178   EcalDigiCollection::const_iterator beginDigiEB =  (*unpacker_->ebDigisCollection())->end();
00179   EcalDigiCollection::const_iterator beginDigiEE =  (*unpacker_->eeDigisCollection())->end();
00180   
00181   //###### get the digi #######
00182   // unpack first
00183   int smId =0;
00184   int length = fedData.size();
00185   if ( length >= EMPTYEVENTSIZE ){
00186     if(myMap_->setActiveDCC(fedIndex)){
00187       smId = myMap_->getActiveSM();
00188       uint64_t * pData = (uint64_t *)(fedData.data());
00189        LogDebug("EcalRawToRecHit|Worker")<<"calling the unpacker: "<<length<<" "<<smId<<" "<<fedIndex
00190                                               <<watcher.lap();
00191       unpacker_->unpack( pData, static_cast<unsigned int>(length),smId,fedIndex);
00192        LogDebug("EcalRawToRecHit|Worker")<<"unpacking done."
00193                                               <<watcher.lap();
00194     }
00195     else{
00196       edm::LogInfo("EcalUnpackerWorker")<<"cannot set: "<<fedIndex<<" to be an active DCC.";
00197        LogDebug("EcalRawToRecHit|Worker")<<"cannot set: "<<fedIndex<<" to be an active DCC.";
00198       return std::auto_ptr< EcalRecHitCollection >(new EcalRecHitCollection);
00199     }
00200   }
00201   else {
00202     edm::LogInfo("EcalUnpackerWorker")<<"empty event on this FED: "<<fedIndex<<" length: "<<length;
00203      LogDebug("EcalRawToRecHit|Worker")<<"empty event on this FED: "<<fedIndex<<" length: "<<length;
00204     return std::auto_ptr< EcalRecHitCollection >(new EcalRecHitCollection);
00205   }
00206 
00207    LogDebug("EcalRawToRecHit|Worker")
00208     <<"size of digi collections after unpacking: "
00209     <<(*unpacker_->ebDigisCollection())->size()
00210     <<" "<<(*unpacker_->eeDigisCollection())->size()
00211     <<watcher.lap();
00212   EcalDigiCollection::const_iterator endDigiEB = (*unpacker_->ebDigisCollection())->end();
00213   EcalDigiCollection::const_iterator endDigiEE = (*unpacker_->eeDigisCollection())->end();
00214 
00215   //collection for the rechits: uncalib and final
00216   std::auto_ptr< EcalRecHitCollection > ecalrechits( new EcalRecHitCollection );
00217   std::auto_ptr< EcalUncalibratedRecHitCollection > uncalibRecHits( new EcalUncalibratedRecHitCollection );
00218   
00219    LogDebug("EcalRawToRecHit|Worker")<<"going to work on EE rechits from: "<<endDigiEE-beginDigiEE<<" digis."
00220                                             <<"\ngoing to work on EB rechits from: "<<endDigiEB-beginDigiEB<<" digis."
00221                                           <<watcher.lap();
00222   // EB
00223   //make the uncalibrated rechits on the fly
00224   if (beginDigiEB!=endDigiEB){
00225     work<EBDetId>(beginDigiEB, endDigiEB, uncalibRecHits, ecalrechits);
00226   }
00227    LogDebug("EcalRawToRecHit|Worker")<<uncalibRecHits->size()<<" uncalibrated rechit created so far\n"
00228                                           <<ecalrechits->size()<<" rechit created so far."
00229                                           <<watcher.lap();
00230   
00231   // EE
00232   if (beginDigiEE!=endDigiEE){
00233     work<EEDetId>(beginDigiEE, endDigiEE, uncalibRecHits, ecalrechits);
00234   } 
00235    LogDebug("EcalRawToRecHit|Worker")<<uncalibRecHits->size()<<" uncalibrated rechit created eventually\n"
00236                                           <<ecalrechits->size()<<" rechit created eventually"
00237                                           <<watcher.lap();
00238 
00239   return ecalrechits;
00240 }