00001 #include "EventFilter/EcalRawToDigi/plugins/EcalRawToDigi.h"
00002 #include "EventFilter/EcalRawToDigi/interface/EcalElectronicsMapper.h"
00003 #include "EventFilter/EcalRawToDigi/interface/DCCDataUnpacker.h"
00004
00005
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00009 #include "DataFormats/EcalRawData/interface/EcalListOfFEDS.h"
00010 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00011 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00012
00013 EcalRawToDigi::EcalRawToDigi(edm::ParameterSet const& conf):
00014
00015
00016 fedUnpackList_(conf.getParameter<std::vector<int> >("FEDs")),
00017
00018
00019 orderedFedUnpackList_(conf.getParameter<std::vector<int> >("orderedFedList")),
00020
00021
00022 orderedDCCIdList_(conf.getParameter<std::vector<int> >("orderedDCCIdList")),
00023
00024
00025 numbXtalTSamples_(conf.getParameter<int>("numbXtalTSamples")),
00026
00027
00028 numbTriggerTSamples_(conf.getParameter<int>("numbTriggerTSamples")),
00029
00030
00031 headerUnpacking_(conf.getParameter<bool>("headerUnpacking")),
00032
00033
00034 srpUnpacking_(conf.getParameter<bool>("srpUnpacking")),
00035
00036
00037 tccUnpacking_(conf.getParameter<bool>("tccUnpacking")),
00038
00039
00040 feUnpacking_(conf.getParameter<bool>("feUnpacking")),
00041
00042
00043 memUnpacking_(conf.getParameter<bool>("memUnpacking")),
00044
00045
00046 syncCheck_(conf.getParameter<bool>("syncCheck")),
00047
00048
00049 feIdCheck_(conf.getParameter<bool>("feIdCheck")),
00050
00051
00052 forceToKeepFRdata_(conf.getParameter<bool>("forceToKeepFRData")),
00053
00054
00055 put_(conf.getParameter<bool>("eventPut")),
00056
00057 dataLabel_(conf.getParameter<edm::InputTag>("InputLabel")),
00058
00059 REGIONAL_(conf.getParameter<bool>("DoRegional")),
00060
00061 fedsLabel_(conf.getParameter<edm::InputTag>("FedLabel")),
00062
00063 myMap_(0),
00064
00065 theUnpacker_(0)
00066
00067 {
00068
00069 first_ = true;
00070 DCCDataUnpacker::silentMode_ = conf.getUntrackedParameter<bool>("silentMode",false) ;
00071
00072 if( numbXtalTSamples_ <6 || numbXtalTSamples_>64 || (numbXtalTSamples_-2)%4 ){
00073 std::ostringstream output;
00074 output <<"\n Unsuported number of xtal time samples : "<<numbXtalTSamples_
00075 <<"\n Valid Number of xtal time samples are : 6,10,14,18,...,62";
00076 edm::LogError("IncorrectConfiguration")<< output.str();
00077
00078 }
00079
00080 if( numbTriggerTSamples_ !=1 && numbTriggerTSamples_ !=4 && numbTriggerTSamples_ !=8 ){
00081 std::ostringstream output;
00082 output <<"\n Unsuported number of trigger time samples : "<<numbTriggerTSamples_
00083 <<"\n Valid number of trigger time samples are : 1, 4 or 8";
00084 edm::LogError("IncorrectConfiguration")<< output.str();
00085
00086 }
00087
00088
00089
00090
00091
00092
00093
00094 if (fedUnpackList_.empty())
00095 for (int i=FEDNumbering::MINECALFEDID; i<=FEDNumbering::MAXECALFEDID; i++)
00096 fedUnpackList_.push_back(i);
00097
00098
00099 std::ostringstream loggerOutput_;
00100 if(fedUnpackList_.size()!=0){
00101 for (unsigned int i=0; i<fedUnpackList_.size(); i++)
00102 loggerOutput_ << fedUnpackList_[i] << " ";
00103 edm::LogInfo("EcalRawToDigi") << "EcalRawToDigi will unpack FEDs ( " << loggerOutput_.str() << ")";
00104 LogDebug("EcalRawToDigi") << "EcalRawToDigi will unpack FEDs ( " << loggerOutput_.str() << ")";
00105 }
00106
00107 edm::LogInfo("EcalRawToDigi")
00108 <<"\n ECAL RawToDigi configuration:"
00109 <<"\n Header unpacking is "<<headerUnpacking_
00110 <<"\n SRP Bl. unpacking is "<<srpUnpacking_
00111 <<"\n TCC Bl. unpacking is "<<tccUnpacking_
00112 <<"\n FE Bl. unpacking is "<<feUnpacking_
00113 <<"\n MEM Bl. unpacking is "<<memUnpacking_
00114 <<"\n sync check is "<<syncCheck_
00115 <<"\n feID check is "<<feIdCheck_
00116 <<"\n force keep FR data is "<<forceToKeepFRdata_
00117 <<"\n";
00118
00119
00120
00121 produces<EBDigiCollection>("ebDigis");
00122 produces<EEDigiCollection>("eeDigis");
00123 produces<EBSrFlagCollection>();
00124 produces<EESrFlagCollection>();
00125 produces<EcalRawDataCollection>();
00126 produces<EcalPnDiodeDigiCollection>();
00127 produces<EcalTrigPrimDigiCollection>("EcalTriggerPrimitives");
00128 produces<EcalPSInputDigiCollection>("EcalPseudoStripInputs");
00129
00130
00131 produces<EBDetIdCollection>("EcalIntegrityGainErrors");
00132 produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
00133 produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
00134
00135
00136 produces<EEDetIdCollection>("EcalIntegrityGainErrors");
00137 produces<EEDetIdCollection>("EcalIntegrityGainSwitchErrors");
00138 produces<EEDetIdCollection>("EcalIntegrityChIdErrors");
00139
00140
00141 produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
00142 produces<EcalElectronicsIdCollection>("EcalIntegrityZSXtalIdErrors");
00143 produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
00144
00145
00146 produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
00147 produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSizeErrors");
00148 produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
00149 produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
00150
00151
00152
00153
00154 myMap_ = new EcalElectronicsMapper(numbXtalTSamples_,numbTriggerTSamples_);
00155
00156
00157
00158
00159
00160 bool readResult = myMap_->makeMapFromVectors(orderedFedUnpackList_, orderedDCCIdList_);
00161
00162
00163
00164 if(!readResult){
00165 edm::LogWarning("IncorrectConfiguration")
00166 << "Arrays orderedFedList and orderedDCCIdList are emply. "
00167 "Hard coded correspondence for DCCId:FedId will be used.";
00168
00169
00170 }
00171
00172
00173 theUnpacker_ = new DCCDataUnpacker(myMap_,headerUnpacking_,srpUnpacking_,tccUnpacking_,feUnpacking_,memUnpacking_,syncCheck_,feIdCheck_,forceToKeepFRdata_);
00174
00175 }
00176
00177
00178
00179
00180 void printStatusRecords(const DCCDataUnpacker* unpacker,
00181 const EcalElectronicsMapping* mapping)
00182 {
00183
00184 std::cout << "===> ENDCAP" << std::endl;
00185 for (int i = 0; i < EEDetId::kSizeForDenseIndexing; ++i) {
00186 const EEDetId id = EEDetId::unhashIndex(i);
00187 if (!id.null()) {
00188
00189 const uint16_t code = unpacker->getChannelValue(id);
00190
00191 if (code) {
00192 const EcalElectronicsId ei = mapping->getElectronicsId(id);
00193
00194
00195 const int fed_id = unpacker->electronicsMapper()->getDCCId(ei.dccId());
00196
00197 std::cout
00198 << " id " << id.rawId()
00199 << " -> (" << id.ix() << ", " << id.iy() << ", " << id.zside() << ") "
00200 << "(" << ei.dccId() << " : " << fed_id << ", " << ei.towerId() << ", " << ei.stripId() << ", " << ei.xtalId() << ") "
00201 << "status = " << code
00202 << std::endl;
00203 }
00204 }
00205 }
00206 std::cout << "<=== ENDCAP" << std::endl;
00207
00208 std::cout << "===> BARREL" << std::endl;
00209 for (int i = 0; i < EBDetId::kSizeForDenseIndexing; ++i) {
00210 const EBDetId id = EBDetId::unhashIndex(i);
00211 if (!id.null()) {
00212
00213 const uint16_t code = unpacker->getChannelValue(id);
00214
00215 if (code) {
00216 const EcalElectronicsId ei = mapping->getElectronicsId(id);
00217
00218
00219 const int fed_id = unpacker->electronicsMapper()->getDCCId(ei.dccId());
00220
00221 std::cout
00222 << " id " << id.rawId()
00223 << " -> (" << id.ieta() << ", " << id.iphi() << ", " << id.zside() << ") "
00224 << "(" << ei.dccId() << " : " << fed_id << ", " << ei.towerId() << ", " << ei.stripId() << ", " << ei.xtalId() << ") "
00225 << "status = " << code
00226 << std::endl;
00227 }
00228 }
00229 }
00230 std::cout << "<=== BARREL" << std::endl;
00231 }
00232
00233 void EcalRawToDigi::beginRun(edm::Run&, const edm::EventSetup& es)
00234 {
00235
00236 edm::ESHandle<EcalChannelStatusMap> pChStatus;
00237 es.get<EcalChannelStatusRcd>().get(pChStatus);
00238 theUnpacker_->setChannelStatusDB(pChStatus.product());
00239
00240
00241
00242
00243
00244
00245 }
00246
00247
00248 void EcalRawToDigi::produce(edm::Event& e, const edm::EventSetup& es)
00249 {
00250
00251
00252
00253
00254
00255 if (first_) {
00256 watcher_.check(es);
00257 edm::ESHandle< EcalElectronicsMapping > ecalmapping;
00258 es.get< EcalMappingRcd >().get(ecalmapping);
00259 myMap_ -> setEcalElectronicsMapping(ecalmapping.product());
00260
00261 first_ = false;
00262
00263 }else{
00264
00265 if ( watcher_.check(es) ) {
00266 edm::ESHandle< EcalElectronicsMapping > ecalmapping;
00267 es.get< EcalMappingRcd >().get(ecalmapping);
00268 myMap_ -> deletePointers();
00269 myMap_ -> resetPointers();
00270 myMap_ -> setEcalElectronicsMapping(ecalmapping.product());
00271 }
00272
00273 }
00274
00275
00276 std::vector<int> FEDS_to_unpack;
00277 if (REGIONAL_) {
00278 edm::Handle<EcalListOfFEDS> listoffeds;
00279 e.getByLabel(fedsLabel_, listoffeds);
00280 FEDS_to_unpack = listoffeds -> GetList();
00281 }
00282
00283
00284
00285
00286
00287 edm::Handle<FEDRawDataCollection> rawdata;
00288 e.getByLabel(dataLabel_,rawdata);
00289
00290
00291
00292
00293
00294 std::auto_ptr<EBDigiCollection> productDigisEB(new EBDigiCollection);
00295 productDigisEB->reserve(1700);
00296 theUnpacker_->setEBDigisCollection(&productDigisEB);
00297
00298
00299 std::auto_ptr<EEDigiCollection> productDigisEE(new EEDigiCollection);
00300 theUnpacker_->setEEDigisCollection(&productDigisEE);
00301
00302
00303 std::auto_ptr<EcalRawDataCollection> productDccHeaders(new EcalRawDataCollection);
00304 theUnpacker_->setDccHeadersCollection(&productDccHeaders);
00305
00306
00307 std::auto_ptr< EBDetIdCollection> productInvalidGains(new EBDetIdCollection);
00308 theUnpacker_->setInvalidGainsCollection(&productInvalidGains);
00309
00310
00311 std::auto_ptr< EBDetIdCollection> productInvalidGainsSwitch(new EBDetIdCollection);
00312 theUnpacker_->setInvalidGainsSwitchCollection(&productInvalidGainsSwitch);
00313
00314
00315 std::auto_ptr< EBDetIdCollection> productInvalidChIds(new EBDetIdCollection);
00316 theUnpacker_->setInvalidChIdsCollection(&productInvalidChIds);
00317
00319
00320
00321 std::auto_ptr<EEDetIdCollection> productInvalidEEGains(new EEDetIdCollection);
00322 theUnpacker_->setInvalidEEGainsCollection(&productInvalidEEGains);
00323
00324
00325 std::auto_ptr<EEDetIdCollection> productInvalidEEGainsSwitch(new EEDetIdCollection);
00326 theUnpacker_->setInvalidEEGainsSwitchCollection(&productInvalidEEGainsSwitch);
00327
00328
00329 std::auto_ptr<EEDetIdCollection> productInvalidEEChIds(new EEDetIdCollection);
00330 theUnpacker_->setInvalidEEChIdsCollection(&productInvalidEEChIds);
00331
00333
00334
00335 std::auto_ptr<EBSrFlagCollection> productEBSrFlags(new EBSrFlagCollection);
00336 theUnpacker_->setEBSrFlagsCollection(&productEBSrFlags);
00337
00338
00339 std::auto_ptr<EESrFlagCollection> productEESrFlags(new EESrFlagCollection);
00340 theUnpacker_->setEESrFlagsCollection(&productEESrFlags);
00341
00342
00343 std::auto_ptr<EcalTrigPrimDigiCollection> productEcalTps(new EcalTrigPrimDigiCollection);
00344 theUnpacker_->setEcalTpsCollection(&productEcalTps);
00346
00347
00348 std::auto_ptr<EcalPSInputDigiCollection> productEcalPSs(new EcalPSInputDigiCollection);
00349 theUnpacker_->setEcalPSsCollection(&productEcalPSs);
00351
00352
00353 std::auto_ptr<EcalElectronicsIdCollection> productInvalidTTIds(new EcalElectronicsIdCollection);
00354 theUnpacker_->setInvalidTTIdsCollection(&productInvalidTTIds);
00355
00356
00357 std::auto_ptr<EcalElectronicsIdCollection> productInvalidZSXtalIds(new EcalElectronicsIdCollection);
00358 theUnpacker_->setInvalidZSXtalIdsCollection(&productInvalidZSXtalIds);
00359
00360
00361
00362
00363 std::auto_ptr<EcalElectronicsIdCollection> productInvalidBlockLengths(new EcalElectronicsIdCollection);
00364 theUnpacker_->setInvalidBlockLengthsCollection(&productInvalidBlockLengths);
00365
00366
00367
00368 std::auto_ptr<EcalPnDiodeDigiCollection> productPnDiodeDigis(new EcalPnDiodeDigiCollection);
00369 theUnpacker_->setPnDiodeDigisCollection(&productPnDiodeDigis);
00370
00371
00372 std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemTtIds(new EcalElectronicsIdCollection);
00373 theUnpacker_->setInvalidMemTtIdsCollection(& productInvalidMemTtIds);
00374
00375
00376 std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemBlockSizes(new EcalElectronicsIdCollection);
00377 theUnpacker_->setInvalidMemBlockSizesCollection(& productInvalidMemBlockSizes);
00378
00379
00380 std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemChIds(new EcalElectronicsIdCollection);
00381 theUnpacker_->setInvalidMemChIdsCollection(& productInvalidMemChIds);
00382
00383
00384 std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemGains(new EcalElectronicsIdCollection);
00385 theUnpacker_->setInvalidMemGainsCollection(& productInvalidMemGains);
00386
00387
00388
00389
00390 for (std::vector<int>::const_iterator i=fedUnpackList_.begin(); i!=fedUnpackList_.end(); i++) {
00391
00392 if (REGIONAL_) {
00393 std::vector<int>::const_iterator fed_it = find(FEDS_to_unpack.begin(), FEDS_to_unpack.end(), *i);
00394 if (fed_it == FEDS_to_unpack.end()) continue;
00395 }
00396
00397
00398
00399 const FEDRawData& fedData = rawdata->FEDData(*i);
00400 const size_t length = fedData.size();
00401
00402 LogDebug("EcalRawToDigi") << "raw data length: " << length ;
00403
00404 if ( length >= EMPTYEVENTSIZE ){
00405
00406 if(myMap_->setActiveDCC(*i)){
00407
00408 const int smId = myMap_->getActiveSM();
00409 LogDebug("EcalRawToDigi") << "Getting FED = " << *i <<"(SM = "<<smId<<")"<<" data size is: " << length;
00410
00411 const uint64_t* data = (uint64_t*) fedData.data();
00412 theUnpacker_->unpack(data, length, smId, *i);
00413
00414 LogDebug("EcalRawToDigi") <<" in EE :"<<productDigisEE->size()
00415 <<" in EB :"<<productDigisEB->size();
00416 }
00417 }
00418
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 if(put_){
00430
00431 if( headerUnpacking_){
00432 e.put(productDccHeaders);
00433 }
00434
00435 if(feUnpacking_){
00436 productDigisEB->sort();
00437 e.put(productDigisEB,"ebDigis");
00438 productDigisEE->sort();
00439 e.put(productDigisEE,"eeDigis");
00440 e.put(productInvalidGains,"EcalIntegrityGainErrors");
00441 e.put(productInvalidGainsSwitch, "EcalIntegrityGainSwitchErrors");
00442 e.put(productInvalidChIds, "EcalIntegrityChIdErrors");
00443
00444 e.put(productInvalidEEGains,"EcalIntegrityGainErrors");
00445 e.put(productInvalidEEGainsSwitch, "EcalIntegrityGainSwitchErrors");
00446 e.put(productInvalidEEChIds, "EcalIntegrityChIdErrors");
00447
00448 e.put(productInvalidTTIds,"EcalIntegrityTTIdErrors");
00449 e.put(productInvalidZSXtalIds,"EcalIntegrityZSXtalIdErrors");
00450 e.put(productInvalidBlockLengths,"EcalIntegrityBlockSizeErrors");
00451 e.put(productPnDiodeDigis);
00452 }
00453 if(memUnpacking_){
00454 e.put(productInvalidMemTtIds,"EcalIntegrityMemTtIdErrors");
00455 e.put(productInvalidMemBlockSizes,"EcalIntegrityMemBlockSizeErrors");
00456 e.put(productInvalidMemChIds,"EcalIntegrityMemChIdErrors");
00457 e.put(productInvalidMemGains,"EcalIntegrityMemGainErrors");
00458 }
00459 if(srpUnpacking_){
00460 e.put(productEBSrFlags);
00461 e.put(productEESrFlags);
00462 }
00463 if(tccUnpacking_){
00464 e.put(productEcalTps,"EcalTriggerPrimitives");
00465 e.put(productEcalPSs,"EcalPseudoStripInputs");
00466 }
00467 }
00468
00469
00470
00471
00472
00473
00474 }
00475
00476 EcalRawToDigi::~EcalRawToDigi()
00477 {
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 if(myMap_ ) delete myMap_;
00493 if(theUnpacker_) delete theUnpacker_;
00494
00495 }