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 }
00105
00106 edm::LogInfo("EcalRawToDigi")
00107 <<"\n ECAL RawToDigi configuration:"
00108 <<"\n Header unpacking is "<<headerUnpacking_
00109 <<"\n SRP Bl. unpacking is "<<srpUnpacking_
00110 <<"\n TCC Bl. unpacking is "<<tccUnpacking_
00111 <<"\n FE Bl. unpacking is "<<feUnpacking_
00112 <<"\n MEM Bl. unpacking is "<<memUnpacking_<<"\n";
00113
00114
00115 produces<EBDigiCollection>("ebDigis");
00116 produces<EEDigiCollection>("eeDigis");
00117 produces<EBSrFlagCollection>();
00118 produces<EESrFlagCollection>();
00119 produces<EcalRawDataCollection>();
00120 produces<EcalPnDiodeDigiCollection>();
00121 produces<EcalTrigPrimDigiCollection>("EcalTriggerPrimitives");
00122 produces<EcalPSInputDigiCollection>("EcalPseudoStripInputs");
00123
00124
00125 produces<EBDetIdCollection>("EcalIntegrityGainErrors");
00126 produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
00127 produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
00128
00129
00130 produces<EEDetIdCollection>("EcalIntegrityGainErrors");
00131 produces<EEDetIdCollection>("EcalIntegrityGainSwitchErrors");
00132 produces<EEDetIdCollection>("EcalIntegrityChIdErrors");
00133
00134
00135 produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
00136 produces<EcalElectronicsIdCollection>("EcalIntegrityZSXtalIdErrors");
00137 produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
00138
00139
00140 produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
00141 produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSizeErrors");
00142 produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
00143 produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
00144
00145
00146
00147
00148 myMap_ = new EcalElectronicsMapper(numbXtalTSamples_,numbTriggerTSamples_);
00149
00150
00151
00152
00153
00154 bool readResult = myMap_->makeMapFromVectors(orderedFedUnpackList_, orderedDCCIdList_);
00155
00156
00157
00158 if(!readResult){
00159 edm::LogWarning("IncorrectConfiguration")
00160 << "Arrays orderedFedList and orderedDCCIdList are emply. "
00161 "Hard coded correspondence for DCCId:FedId will be used.";
00162
00163
00164 }
00165
00166
00167 theUnpacker_ = new DCCDataUnpacker(myMap_,headerUnpacking_,srpUnpacking_,tccUnpacking_,feUnpacking_,memUnpacking_,syncCheck_,feIdCheck_,forceToKeepFRdata_);
00168
00169 }
00170
00171
00172
00173
00174 void printStatusRecords(const DCCDataUnpacker* unpacker,
00175 const EcalElectronicsMapping* mapping)
00176 {
00177
00178 std::cout << "===> ENDCAP" << std::endl;
00179 for (int i = 0; i < EEDetId::kSizeForDenseIndexing; ++i) {
00180 const EEDetId id = EEDetId::unhashIndex(i);
00181 if (!id.null()) {
00182
00183 const uint16_t code = unpacker->getChannelValue(id);
00184
00185 if (code) {
00186 const EcalElectronicsId ei = mapping->getElectronicsId(id);
00187
00188
00189 const int fed_id = unpacker->electronicsMapper()->getDCCId(ei.dccId());
00190
00191 std::cout
00192 << " id " << id.rawId()
00193 << " -> (" << id.ix() << ", " << id.iy() << ", " << id.zside() << ") "
00194 << "(" << ei.dccId() << " : " << fed_id << ", " << ei.towerId() << ", " << ei.stripId() << ", " << ei.xtalId() << ") "
00195 << "status = " << code
00196 << std::endl;
00197 }
00198 }
00199 }
00200 std::cout << "<=== ENDCAP" << std::endl;
00201
00202 std::cout << "===> BARREL" << std::endl;
00203 for (int i = 0; i < EBDetId::kSizeForDenseIndexing; ++i) {
00204 const EBDetId id = EBDetId::unhashIndex(i);
00205 if (!id.null()) {
00206
00207 const uint16_t code = unpacker->getChannelValue(id);
00208
00209 if (code) {
00210 const EcalElectronicsId ei = mapping->getElectronicsId(id);
00211
00212
00213 const int fed_id = unpacker->electronicsMapper()->getDCCId(ei.dccId());
00214
00215 std::cout
00216 << " id " << id.rawId()
00217 << " -> (" << id.ieta() << ", " << id.iphi() << ", " << id.zside() << ") "
00218 << "(" << ei.dccId() << " : " << fed_id << ", " << ei.towerId() << ", " << ei.stripId() << ", " << ei.xtalId() << ") "
00219 << "status = " << code
00220 << std::endl;
00221 }
00222 }
00223 }
00224 std::cout << "<=== BARREL" << std::endl;
00225 }
00226
00227 void EcalRawToDigi::beginRun(edm::Run&, const edm::EventSetup& es)
00228 {
00229
00230 edm::ESHandle<EcalChannelStatusMap> pChStatus;
00231 es.get<EcalChannelStatusRcd>().get(pChStatus);
00232 theUnpacker_->setChannelStatusDB(pChStatus.product());
00233
00234
00235
00236
00237
00238
00239 }
00240
00241
00242 void EcalRawToDigi::produce(edm::Event& e, const edm::EventSetup& es)
00243 {
00244
00245
00246
00247
00248
00249 if (first_) {
00250 watcher_.check(es);
00251 edm::ESHandle< EcalElectronicsMapping > ecalmapping;
00252 es.get< EcalMappingRcd >().get(ecalmapping);
00253 myMap_ -> setEcalElectronicsMapping(ecalmapping.product());
00254
00255 first_ = false;
00256
00257 }else{
00258
00259 if ( watcher_.check(es) ) {
00260 edm::ESHandle< EcalElectronicsMapping > ecalmapping;
00261 es.get< EcalMappingRcd >().get(ecalmapping);
00262 myMap_ -> deletePointers();
00263 myMap_ -> resetPointers();
00264 myMap_ -> setEcalElectronicsMapping(ecalmapping.product());
00265 }
00266
00267 }
00268
00269
00270 std::vector<int> FEDS_to_unpack;
00271 if (REGIONAL_) {
00272 edm::Handle<EcalListOfFEDS> listoffeds;
00273 e.getByLabel(fedsLabel_, listoffeds);
00274 FEDS_to_unpack = listoffeds -> GetList();
00275 }
00276
00277
00278
00279
00280
00281 edm::Handle<FEDRawDataCollection> rawdata;
00282 e.getByLabel(dataLabel_,rawdata);
00283
00284
00285
00286
00287
00288 std::auto_ptr<EBDigiCollection> productDigisEB(new EBDigiCollection);
00289 productDigisEB->reserve(1700);
00290 theUnpacker_->setEBDigisCollection(&productDigisEB);
00291
00292
00293 std::auto_ptr<EEDigiCollection> productDigisEE(new EEDigiCollection);
00294 theUnpacker_->setEEDigisCollection(&productDigisEE);
00295
00296
00297 std::auto_ptr<EcalRawDataCollection> productDccHeaders(new EcalRawDataCollection);
00298 theUnpacker_->setDccHeadersCollection(&productDccHeaders);
00299
00300
00301 std::auto_ptr< EBDetIdCollection> productInvalidGains(new EBDetIdCollection);
00302 theUnpacker_->setInvalidGainsCollection(&productInvalidGains);
00303
00304
00305 std::auto_ptr< EBDetIdCollection> productInvalidGainsSwitch(new EBDetIdCollection);
00306 theUnpacker_->setInvalidGainsSwitchCollection(&productInvalidGainsSwitch);
00307
00308
00309 std::auto_ptr< EBDetIdCollection> productInvalidChIds(new EBDetIdCollection);
00310 theUnpacker_->setInvalidChIdsCollection(&productInvalidChIds);
00311
00313
00314
00315 std::auto_ptr<EEDetIdCollection> productInvalidEEGains(new EEDetIdCollection);
00316 theUnpacker_->setInvalidEEGainsCollection(&productInvalidEEGains);
00317
00318
00319 std::auto_ptr<EEDetIdCollection> productInvalidEEGainsSwitch(new EEDetIdCollection);
00320 theUnpacker_->setInvalidEEGainsSwitchCollection(&productInvalidEEGainsSwitch);
00321
00322
00323 std::auto_ptr<EEDetIdCollection> productInvalidEEChIds(new EEDetIdCollection);
00324 theUnpacker_->setInvalidEEChIdsCollection(&productInvalidEEChIds);
00325
00327
00328
00329 std::auto_ptr<EBSrFlagCollection> productEBSrFlags(new EBSrFlagCollection);
00330 theUnpacker_->setEBSrFlagsCollection(&productEBSrFlags);
00331
00332
00333 std::auto_ptr<EESrFlagCollection> productEESrFlags(new EESrFlagCollection);
00334 theUnpacker_->setEESrFlagsCollection(&productEESrFlags);
00335
00336
00337 std::auto_ptr<EcalTrigPrimDigiCollection> productEcalTps(new EcalTrigPrimDigiCollection);
00338 theUnpacker_->setEcalTpsCollection(&productEcalTps);
00340
00341
00342 std::auto_ptr<EcalPSInputDigiCollection> productEcalPSs(new EcalPSInputDigiCollection);
00343 theUnpacker_->setEcalPSsCollection(&productEcalPSs);
00345
00346
00347 std::auto_ptr<EcalElectronicsIdCollection> productInvalidTTIds(new EcalElectronicsIdCollection);
00348 theUnpacker_->setInvalidTTIdsCollection(&productInvalidTTIds);
00349
00350
00351 std::auto_ptr<EcalElectronicsIdCollection> productInvalidZSXtalIds(new EcalElectronicsIdCollection);
00352 theUnpacker_->setInvalidZSXtalIdsCollection(&productInvalidZSXtalIds);
00353
00354
00355
00356
00357 std::auto_ptr<EcalElectronicsIdCollection> productInvalidBlockLengths(new EcalElectronicsIdCollection);
00358 theUnpacker_->setInvalidBlockLengthsCollection(&productInvalidBlockLengths);
00359
00360
00361
00362 std::auto_ptr<EcalPnDiodeDigiCollection> productPnDiodeDigis(new EcalPnDiodeDigiCollection);
00363 theUnpacker_->setPnDiodeDigisCollection(&productPnDiodeDigis);
00364
00365
00366 std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemTtIds(new EcalElectronicsIdCollection);
00367 theUnpacker_->setInvalidMemTtIdsCollection(& productInvalidMemTtIds);
00368
00369
00370 std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemBlockSizes(new EcalElectronicsIdCollection);
00371 theUnpacker_->setInvalidMemBlockSizesCollection(& productInvalidMemBlockSizes);
00372
00373
00374 std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemChIds(new EcalElectronicsIdCollection);
00375 theUnpacker_->setInvalidMemChIdsCollection(& productInvalidMemChIds);
00376
00377
00378 std::auto_ptr<EcalElectronicsIdCollection> productInvalidMemGains(new EcalElectronicsIdCollection);
00379 theUnpacker_->setInvalidMemGainsCollection(& productInvalidMemGains);
00380
00381
00382
00383
00384 for (std::vector<int>::const_iterator i=fedUnpackList_.begin(); i!=fedUnpackList_.end(); i++) {
00385
00386 if (REGIONAL_) {
00387 std::vector<int>::const_iterator fed_it = find(FEDS_to_unpack.begin(), FEDS_to_unpack.end(), *i);
00388 if (fed_it == FEDS_to_unpack.end()) continue;
00389 }
00390
00391
00392
00393 const FEDRawData & fedData = rawdata->FEDData(*i);
00394 int length = fedData.size();
00395
00396 LogDebug("EcalRawToDigi") << "raw data length: " << length ;
00397
00398 if ( length >= EMPTYEVENTSIZE ){
00399
00400 if(myMap_->setActiveDCC(*i)){
00401
00402 int smId = myMap_->getActiveSM();
00403 LogDebug("EcalRawToDigi") << "Getting FED = " << *i <<"(SM = "<<smId<<")"<<" data size is: " << length;
00404
00405 uint64_t * pData = (uint64_t *)(fedData.data());
00406 theUnpacker_->unpack( pData, static_cast<unsigned int>(length),smId,*i);
00407 }
00408 }
00409
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 if(put_){
00421
00422 if( headerUnpacking_){
00423 e.put(productDccHeaders);
00424 }
00425
00426 if(feUnpacking_){
00427 productDigisEB->sort();
00428 e.put(productDigisEB,"ebDigis");
00429 productDigisEE->sort();
00430 e.put(productDigisEE,"eeDigis");
00431 e.put(productInvalidGains,"EcalIntegrityGainErrors");
00432 e.put(productInvalidGainsSwitch, "EcalIntegrityGainSwitchErrors");
00433 e.put(productInvalidChIds, "EcalIntegrityChIdErrors");
00434
00435 e.put(productInvalidEEGains,"EcalIntegrityGainErrors");
00436 e.put(productInvalidEEGainsSwitch, "EcalIntegrityGainSwitchErrors");
00437 e.put(productInvalidEEChIds, "EcalIntegrityChIdErrors");
00438
00439 e.put(productInvalidTTIds,"EcalIntegrityTTIdErrors");
00440 e.put(productInvalidZSXtalIds,"EcalIntegrityZSXtalIdErrors");
00441 e.put(productInvalidBlockLengths,"EcalIntegrityBlockSizeErrors");
00442 e.put(productPnDiodeDigis);
00443 }
00444 if(memUnpacking_){
00445 e.put(productInvalidMemTtIds,"EcalIntegrityMemTtIdErrors");
00446 e.put(productInvalidMemBlockSizes,"EcalIntegrityMemBlockSizeErrors");
00447 e.put(productInvalidMemChIds,"EcalIntegrityMemChIdErrors");
00448 e.put(productInvalidMemGains,"EcalIntegrityMemGainErrors");
00449 }
00450 if(srpUnpacking_){
00451 e.put(productEBSrFlags);
00452 e.put(productEESrFlags);
00453 }
00454 if(tccUnpacking_){
00455 e.put(productEcalTps,"EcalTriggerPrimitives");
00456 e.put(productEcalPSs,"EcalPseudoStripInputs");
00457 }
00458 }
00459
00460
00461
00462
00463
00464
00465 }
00466
00467 EcalRawToDigi::~EcalRawToDigi()
00468 {
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483 if(myMap_ ) delete myMap_;
00484 if(theUnpacker_) delete theUnpacker_;
00485
00486 }