CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/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);
00166 //<<watcher.lap();
00167 //std::cout<<watcher.lap() <<std::endl;
00168   int fedIndex = EcalRegionCabling::fedIndex(index);
00169 
00170   const FEDRawData & fedData = rawdata.FEDData(fedIndex);
00171 
00172   //remember where the iterators were before unpacking
00173    LogDebug("EcalRawToRecHit|Worker")
00174     <<"size of digi collections before unpacking: "
00175     <<(*unpacker_->ebDigisCollection())->size()
00176     <<" "<<(*unpacker_->eeDigisCollection())->size();
00177   //  <<watcher.lap();
00178 
00179   EcalDigiCollection::const_iterator beginDigiEB =  (*unpacker_->ebDigisCollection())->end();
00180   EcalDigiCollection::const_iterator beginDigiEE =  (*unpacker_->eeDigisCollection())->end();
00181   
00182   //###### get the digi #######
00183   // unpack first
00184   int smId =0;
00185   int length = fedData.size();
00186   if ( length >= EMPTYEVENTSIZE ){
00187     if(myMap_->setActiveDCC(fedIndex)){
00188       smId = myMap_->getActiveSM();
00189       uint64_t * pData = (uint64_t *)(fedData.data());
00190        LogDebug("EcalRawToRecHit|Worker")<<"calling the unpacker: "<<length<<" "<<smId<<" "<<fedIndex ;
00191 //                                            <<watcher.lap();
00192       unpacker_->unpack( pData, static_cast<unsigned int>(length),smId,fedIndex);
00193        LogDebug("EcalRawToRecHit|Worker")<<"unpacking done." ;
00194 //                                            <<watcher.lap();
00195     }
00196     else{
00197       edm::LogInfo("EcalUnpackerWorker")<<"cannot set: "<<fedIndex<<" to be an active DCC.";
00198        LogDebug("EcalRawToRecHit|Worker")<<"cannot set: "<<fedIndex<<" to be an active DCC.";
00199       return std::auto_ptr< EcalRecHitCollection >(new EcalRecHitCollection);
00200     }
00201   }
00202   else {
00203     edm::LogInfo("EcalUnpackerWorker")<<"empty event on this FED: "<<fedIndex<<" length: "<<length;
00204      LogDebug("EcalRawToRecHit|Worker")<<"empty event on this FED: "<<fedIndex<<" length: "<<length;
00205     return std::auto_ptr< EcalRecHitCollection >(new EcalRecHitCollection);
00206   }
00207 
00208    LogDebug("EcalRawToRecHit|Worker")
00209     <<"size of digi collections after unpacking: "
00210     <<(*unpacker_->ebDigisCollection())->size()
00211     <<" "<<(*unpacker_->eeDigisCollection())->size() ;
00212 //    <<watcher.lap();
00213   EcalDigiCollection::const_iterator endDigiEB = (*unpacker_->ebDigisCollection())->end();
00214   EcalDigiCollection::const_iterator endDigiEE = (*unpacker_->eeDigisCollection())->end();
00215 
00216   //collection for the rechits: uncalib and final
00217   std::auto_ptr< EcalRecHitCollection > ecalrechits( new EcalRecHitCollection );
00218   std::auto_ptr< EcalUncalibratedRecHitCollection > uncalibRecHits( new EcalUncalibratedRecHitCollection );
00219   
00220    LogDebug("EcalRawToRecHit|Worker")<<"going to work on EE rechits from: "<<endDigiEE-beginDigiEE<<" digis."
00221                                             <<"\ngoing to work on EB rechits from: "<<endDigiEB-beginDigiEB<<" digis." ;
00222 //                                        <<watcher.lap();
00223   // EB
00224   //make the uncalibrated rechits on the fly
00225   if (beginDigiEB!=endDigiEB){
00226     work<EBDetId>(beginDigiEB, endDigiEB, uncalibRecHits, ecalrechits);
00227   }
00228    LogDebug("EcalRawToRecHit|Worker")<<uncalibRecHits->size()<<" uncalibrated rechit created so far\n"
00229                                           <<ecalrechits->size()<<" rechit created so far." ;
00230 //                                        <<watcher.lap();
00231   
00232   // EE
00233   if (beginDigiEE!=endDigiEE){
00234     work<EEDetId>(beginDigiEE, endDigiEE, uncalibRecHits, ecalrechits);
00235   } 
00236    LogDebug("EcalRawToRecHit|Worker")<<uncalibRecHits->size()<<" uncalibrated rechit created eventually\n"
00237                                           <<ecalrechits->size()<<" rechit created eventually" ;
00238 //                                        <<watcher.lap();
00239 
00240   return ecalrechits;
00241 }