CMS 3D CMS Logo

EcalDigiToRaw.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EcalDigiToRaw
00004 // Class:      EcalDigiToRaw
00005 // 
00013 //
00014 // Original Author:  Emmanuelle Perez
00015 //         Created:  Sat Nov 25 13:59:51 CET 2006
00016 // $Id: EcalDigiToRaw.cc,v 1.9 2008/07/23 18:17:34 franzoni Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 
00023 
00024 // user include files
00025 #include "EventFilter/EcalDigiToRaw/interface/EcalDigiToRaw.h"
00026 
00027 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00028 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00029 #include "DataFormats/EcalDigi/interface/EcalSrFlag.h"
00030 
00031 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00032 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00033 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00034 
00035 
00036 // #include "DataFormats/Common/interface/Handle.h"
00037 #include "DataFormats/Common/interface/Handle.h"
00038 #include "FWCore/Framework/interface/EventSetup.h"
00039 #include "FWCore/Framework/interface/ESHandle.h"
00040 
00041 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00042 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00043 
00044 
00045 
00046 
00047 using namespace edm;
00048 using namespace std;
00049 
00050 EcalDigiToRaw::EcalDigiToRaw(const edm::ParameterSet& iConfig)
00051 {
00052 
00053    doTCC_    = iConfig.getUntrackedParameter<bool>("WriteTCCBlock");
00054    doSR_     = iConfig.getUntrackedParameter<bool>("WriteSRFlags");
00055    doTower_  = iConfig.getUntrackedParameter<bool>("WriteTowerBlock");
00056 
00057    doBarrel_ = iConfig.getUntrackedParameter<bool>("DoBarrel");
00058    doEndCap_ = iConfig.getUntrackedParameter<bool>("DoEndCap");
00059 
00060    listDCCId_ = iConfig.getUntrackedParameter< std::vector<int32_t> >("listDCCId");
00061    
00062    label_= iConfig.getParameter<string>("Label");
00063    instanceNameEB_ = iConfig.getParameter<string>("InstanceEB");
00064    instanceNameEE_ = iConfig.getParameter<string>("InstanceEE");
00065 
00066    labelTT_ = iConfig.getParameter<edm::InputTag>("labelTT");
00067 
00068    labelEBSR_ = iConfig.getParameter<edm::InputTag>("labelEBSRFlags");
00069    labelEESR_ = iConfig.getParameter<edm::InputTag>("labelEESRFlags");
00070 
00071    counter_ = 0;
00072    debug_ = iConfig.getUntrackedParameter<bool>("debug");
00073 
00074 
00075    Towerblockformatter_ = new TowerBlockFormatter;
00076    TCCblockformatter_   = new TCCBlockFormatter();
00077    SRblockformatter_    = new SRBlockFormatter();
00078    Headerblockformatter_= new BlockFormatter;
00079 
00080    produces<FEDRawDataCollection>();
00081 
00082 
00083 }
00084 
00085 
00086 EcalDigiToRaw::~EcalDigiToRaw()
00087 {
00088  
00089    // do anything here that needs to be done at desctruction time
00090    // (e.g. close files, deallocate resources etc.)
00091 
00092  delete Towerblockformatter_;
00093  delete TCCblockformatter_;
00094  delete SRblockformatter_;
00095  delete Headerblockformatter_;
00096 
00097 }
00098 
00099 
00100 //
00101 // member functions
00102 //
00103 
00104 // ------------ method called to for each event  ------------
00105 void
00106 EcalDigiToRaw::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00107 {
00108 
00109    if (debug_) cout << "Enter in EcalDigiToRaw::produce ... " << endl;
00110 
00111    ESHandle< EcalElectronicsMapping > ecalmapping;
00112    iSetup.get< EcalMappingRcd >().get(ecalmapping);
00113    const EcalElectronicsMapping* TheMapping = ecalmapping.product();
00114 
00115    Towerblockformatter_ -> StartEvent();
00116    SRblockformatter_ -> StartEvent();
00117 
00118   runnumber_ = iEvent.id().run();
00119 
00120   bx_ = (counter_ % BXMAX);
00121   orbit_number_ = counter_ / BXMAX;
00122   counter_ ++;
00123   lv1_ = counter_ % (0x1<<24);
00124 
00125   auto_ptr<FEDRawDataCollection> productRawData(new FEDRawDataCollection);
00126 
00127 
00128   pair<int,int> EcalFEDIds=FEDNumbering::getEcalFEDIds();
00129 
00130   Headerblockformatter_ -> DigiToRaw(productRawData.get());
00131 
00132 
00133 // ---------   Now the Trigger Block part
00134 
00135   Handle<EcalTrigPrimDigiCollection> ecalTrigPrim;
00136   
00137   Handle<EBSrFlagCollection> ebSrFlags;
00138   Handle<EESrFlagCollection> eeSrFlags;
00139 
00140 
00141   if (doTCC_) {
00142 
00143      if (debug_) cout << "Creation of the TCC block  " << endl;
00144      // iEvent.getByType(ecalTrigPrim);
00145         iEvent.getByLabel(labelTT_, ecalTrigPrim);
00146 
00147      for (EcalTrigPrimDigiCollection::const_iterator it = ecalTrigPrim -> begin();
00148                            it != ecalTrigPrim -> end(); it++) {
00149 
00150            const EcalTriggerPrimitiveDigi& trigprim = *it;
00151            const EcalTrigTowerDetId& detid = it -> id();
00152 
00153            if ( (detid.subDet() == EcalBarrel) && (! doBarrel_) ) continue;
00154            if ( (detid.subDet() == EcalEndcap) && (! doEndCap_) ) continue;
00155 
00156            int iDCC = TheMapping -> DCCid(detid);
00157            int FEDid = EcalFEDIds.first + iDCC;
00158 
00159            FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00160 
00161            TCCblockformatter_ -> DigiToRaw(trigprim, rawdata, TheMapping);
00162 
00163      }   // end loop on ecalTrigPrim
00164 
00165    }  // endif doTCC
00166 
00167 
00168    if (doSR_) { 
00169         if (debug_) cout << " Process the SR flags " << endl;
00170 
00171         if (doBarrel_) {
00172 
00173         // iEvent.getByType(ebSrFlags);
00174            iEvent.getByLabel(labelEBSR_, ebSrFlags);
00175                                                                                                                                                 
00176            for (EBSrFlagCollection::const_iterator it = ebSrFlags -> begin();
00177                         it != ebSrFlags -> end(); it++) {
00178                 const EcalSrFlag& srflag = *it;
00179                 int flag = srflag.value();
00180 
00181                 EcalTrigTowerDetId id = srflag.id();
00182                 int Dccid = TheMapping -> DCCid(id);
00183                 int DCC_Channel = TheMapping -> iTT(id);
00184                 int FEDid = EcalFEDIds.first + Dccid;
00185                 // if (Dccid == 10) cout << "Dcc " << Dccid << " DCC_Channel " << DCC_Channel << " flag " << flag << endl;
00186                 if (debug_) cout << "will process SRblockformatter_ for FEDid " << dec << FEDid << endl;
00187                 FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00188                 if (debug_) Headerblockformatter_ -> print(rawdata);
00189                 SRblockformatter_ -> DigiToRaw(Dccid,DCC_Channel,flag, rawdata);
00190 
00191            }
00192         }  // end DoBarrel
00193 
00194 
00195         if (doEndCap_) {
00196         // iEvent.getByType(eeSrFlags);
00197         iEvent.getByLabel(labelEESR_, eeSrFlags);
00198 
00199            for (EESrFlagCollection::const_iterator it = eeSrFlags -> begin();
00200                         it != eeSrFlags -> end(); it++) {
00201                 const EcalSrFlag& srflag = *it;
00202                 int flag = srflag.value();
00203                 EcalScDetId id = srflag.id();
00204                 pair<int, int> ind = TheMapping -> getDCCandSC(id);
00205                 int Dccid = ind.first;
00206                 int DCC_Channel = ind.second;
00207 
00208                 int FEDid = EcalFEDIds.first + Dccid;
00209                 FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00210                 SRblockformatter_ -> DigiToRaw(Dccid,DCC_Channel,flag, rawdata);
00211            }
00212         }  // end doEndCap
00213 
00214    }   // endif doSR
00215 
00216 
00217 // ---------  Now the Tower Block part
00218 
00219   Handle<EBDigiCollection> ebDigis;
00220   Handle<EEDigiCollection> eeDigis;
00221 
00222   if (doTower_) {
00223 
00224         if (doBarrel_) {
00225         if (debug_) cout << "Creation of the TowerBlock ... Barrel case " << endl;
00226         iEvent.getByLabel(label_,instanceNameEB_,ebDigis);
00227         for (EBDigiCollection::const_iterator it=ebDigis -> begin();
00228                                 it != ebDigis->end(); it++) {
00229                 const EBDataFrame& dataframe = *it;
00230                 const EBDetId& ebdetid = it -> id();
00231                 int DCCid = TheMapping -> DCCid(ebdetid);
00232                 int FEDid = EcalFEDIds.first + DCCid ;
00233                 FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00234                 Towerblockformatter_ -> DigiToRaw(dataframe, rawdata, TheMapping);
00235         }
00236 
00237         }
00238 
00239         if (doEndCap_) {
00240         if (debug_) cout << "Creation of the TowerBlock ... EndCap case " << endl;
00241         iEvent.getByLabel(label_,instanceNameEE_,eeDigis);
00242         for (EEDigiCollection::const_iterator it=eeDigis -> begin();
00243                                 it != eeDigis->end(); it++) {
00244                 const EEDataFrame& dataframe = *it;
00245                 const EEDetId& eedetid = it -> id();
00246                 EcalElectronicsId elid = TheMapping -> getElectronicsId(eedetid);
00247                 int DCCid = elid.dccId() ;   
00248                 int FEDid = EcalFEDIds.first + DCCid;
00249                 FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00250                 Towerblockformatter_ -> DigiToRaw(dataframe, rawdata, TheMapping);
00251         }
00252         }
00253 
00254   }  // endif doTower_
00255 
00256 
00257 
00258 // -------- Clean up things ...
00259 
00260   map<int, map<int,int> >* FEDorder = Towerblockformatter_ -> GetFEDorder();
00261 
00262   Headerblockformatter_ -> CleanUp(productRawData.get(), FEDorder);
00263 
00264 
00265 /*
00266    cout << "For FED 633 " << endl;
00267          FEDRawData& rawdata = productRawData -> FEDData(633);
00268          Headerblockformatter_ -> print(rawdata);
00269 */
00270 
00271  // Headerblockformatter_ -> PrintSizes(productRawData.get());
00272 
00273 
00274 
00275  Towerblockformatter_ -> EndEvent(productRawData.get());
00276 
00277  iEvent.put(productRawData);
00278 
00279 
00280  return;
00281 
00282 }
00283 
00284 
00285 // ------------ method called once each job just before starting event loop  ------------
00286 void 
00287 EcalDigiToRaw::beginJob(const edm::EventSetup&)
00288 {
00289         Headerblockformatter_ -> SetParam(this);
00290         Towerblockformatter_  -> SetParam(this);
00291         TCCblockformatter_  -> SetParam(this);
00292         SRblockformatter_   -> SetParam(this);
00293 }
00294 
00295 // ------------ method called once each job just after ending the event loop  ------------
00296 void 
00297 EcalDigiToRaw::endJob() {
00298 }
00299 
00300 
00301 
00302 
00303 
00304 
00305 

Generated on Tue Jun 9 17:34:30 2009 for CMSSW by  doxygen 1.5.4