CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/EventFilter/EcalDigiToRaw/src/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.18 2010/01/13 21:55:15 wmtan 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    label_= iConfig.getParameter<string>("Label");
00062    instanceNameEB_ = iConfig.getParameter<string>("InstanceEB");
00063    instanceNameEE_ = iConfig.getParameter<string>("InstanceEE");
00064 
00065    labelTT_ = iConfig.getParameter<edm::InputTag>("labelTT");
00066 
00067    labelEBSR_ = iConfig.getParameter<edm::InputTag>("labelEBSRFlags");
00068    labelEESR_ = iConfig.getParameter<edm::InputTag>("labelEESRFlags");
00069 
00070    counter_ = 0;
00071    debug_ = iConfig.getUntrackedParameter<bool>("debug");
00072 
00073 
00074    Towerblockformatter_ = new TowerBlockFormatter;
00075    TCCblockformatter_   = new TCCBlockFormatter();
00076    SRblockformatter_    = new SRBlockFormatter();
00077    Headerblockformatter_= new BlockFormatter;
00078 
00079    produces<FEDRawDataCollection>();
00080 
00081 
00082 }
00083 
00084 
00085 EcalDigiToRaw::~EcalDigiToRaw()
00086 {
00087  
00088    // do anything here that needs to be done at desctruction time
00089    // (e.g. close files, deallocate resources etc.)
00090 
00091  delete Towerblockformatter_;
00092  delete TCCblockformatter_;
00093  delete SRblockformatter_;
00094  delete Headerblockformatter_;
00095 
00096 }
00097 
00098 
00099 //
00100 // member functions
00101 //
00102 
00103 // ------------ method called to for each event  ------------
00104 void
00105 EcalDigiToRaw::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00106 {
00107 
00108    if (debug_) cout << "Enter in EcalDigiToRaw::produce ... " << endl;
00109 
00110    ESHandle< EcalElectronicsMapping > ecalmapping;
00111    iSetup.get< EcalMappingRcd >().get(ecalmapping);
00112    const EcalElectronicsMapping* TheMapping = ecalmapping.product();
00113 
00114    Towerblockformatter_ -> StartEvent();
00115    SRblockformatter_ -> StartEvent();
00116 
00117   runnumber_ = iEvent.id().run();
00118 
00119   // bx_ = (counter_ % BXMAX);
00120   // orbit_number_ = counter_ / BXMAX;
00121   // counter_ ++;
00122 
00123   counter_ = iEvent.id().event();
00124   bx_ = iEvent.bunchCrossing();
00125   orbit_number_ = iEvent.orbitNumber();
00126 
00127   lv1_ = counter_ % (0x1<<24);
00128 
00129   auto_ptr<FEDRawDataCollection> productRawData(new FEDRawDataCollection);
00130 
00131 
00132   Headerblockformatter_ -> DigiToRaw(productRawData.get());
00133 
00134 
00135 // ---------   Now the Trigger Block part
00136 
00137   Handle<EcalTrigPrimDigiCollection> ecalTrigPrim;
00138   
00139   Handle<EBSrFlagCollection> ebSrFlags;
00140   Handle<EESrFlagCollection> eeSrFlags;
00141 
00142 
00143   if (doTCC_) {
00144 
00145      if (debug_) cout << "Creation of the TCC block  " << endl;
00146      // iEvent.getByType(ecalTrigPrim);
00147         iEvent.getByLabel(labelTT_, ecalTrigPrim);
00148 
00149      // loop on TP's and add one by one to the block
00150      for (EcalTrigPrimDigiCollection::const_iterator it = ecalTrigPrim -> begin();
00151                            it != ecalTrigPrim -> end(); it++) {
00152 
00153            const EcalTriggerPrimitiveDigi& trigprim = *it;
00154            const EcalTrigTowerDetId& detid = it -> id();
00155 
00156            if ( (detid.subDet() == EcalBarrel) && (! doBarrel_) ) continue;
00157            if ( (detid.subDet() == EcalEndcap) && (! doEndCap_) ) continue;
00158 
00159            int iDCC = TheMapping -> DCCid(detid);
00160            int FEDid = FEDNumbering::MINECALFEDID + iDCC;
00161 
00162            FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00163            
00164            // adding the primitive to the block
00165            TCCblockformatter_ -> DigiToRaw(trigprim, rawdata, TheMapping);
00166 
00167      }   // end loop on ecalTrigPrim
00168 
00169    }  // endif doTCC
00170 
00171 
00172    if (doSR_) { 
00173         if (debug_) cout << " Process the SR flags " << endl;
00174 
00175         if (doBarrel_) {
00176 
00177         // iEvent.getByType(ebSrFlags);
00178            iEvent.getByLabel(labelEBSR_, ebSrFlags);
00179                                                                                                                                                 
00180            for (EBSrFlagCollection::const_iterator it = ebSrFlags -> begin();
00181                         it != ebSrFlags -> end(); it++) {
00182                 const EcalSrFlag& srflag = *it;
00183                 int flag = srflag.value();
00184 
00185                 EcalTrigTowerDetId id = srflag.id();
00186                 int Dccid = TheMapping -> DCCid(id);
00187                 int DCC_Channel = TheMapping -> iTT(id);
00188                 int FEDid = FEDNumbering::MINECALFEDID + Dccid;
00189                 // if (Dccid == 10) cout << "Dcc " << Dccid << " DCC_Channel " << DCC_Channel << " flag " << flag << endl;
00190                 if (debug_) cout << "will process SRblockformatter_ for FEDid " << dec << FEDid << endl;
00191                 FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00192                 if (debug_) Headerblockformatter_ -> print(rawdata);
00193                 SRblockformatter_ -> DigiToRaw(Dccid,DCC_Channel,flag, rawdata);
00194 
00195            }
00196         }  // end DoBarrel
00197 
00198 
00199         if (doEndCap_) {
00200         // iEvent.getByType(eeSrFlags);
00201         iEvent.getByLabel(labelEESR_, eeSrFlags);
00202 
00203            for (EESrFlagCollection::const_iterator it = eeSrFlags -> begin();
00204                         it != eeSrFlags -> end(); it++) {
00205                 const EcalSrFlag& srflag = *it;
00206                 int flag = srflag.value();
00207                 EcalScDetId id = srflag.id();
00208                 pair<int, int> ind = TheMapping -> getDCCandSC(id);
00209                 int Dccid = ind.first;
00210                 int DCC_Channel = ind.second;
00211 
00212                 int FEDid = FEDNumbering::MINECALFEDID + Dccid;
00213                 FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00214                 SRblockformatter_ -> DigiToRaw(Dccid,DCC_Channel,flag, rawdata);
00215            }
00216         }  // end doEndCap
00217 
00218    }   // endif doSR
00219 
00220 
00221 // ---------  Now the Tower Block part
00222 
00223   Handle<EBDigiCollection> ebDigis;
00224   Handle<EEDigiCollection> eeDigis;
00225 
00226   if (doTower_) {
00227 
00228         if (doBarrel_) {
00229         if (debug_) cout << "Creation of the TowerBlock ... Barrel case " << endl;
00230         iEvent.getByLabel(label_,instanceNameEB_,ebDigis);
00231         for (EBDigiCollection::const_iterator it=ebDigis -> begin();
00232                                 it != ebDigis->end(); it++) {
00233                 const EBDataFrame& dataframe = *it;
00234                 const EBDetId& ebdetid = it -> id();
00235                 int DCCid = TheMapping -> DCCid(ebdetid);
00236                 int FEDid = FEDNumbering::MINECALFEDID + DCCid ;
00237                 FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00238                 Towerblockformatter_ -> DigiToRaw(dataframe, rawdata, TheMapping);
00239         }
00240 
00241         }
00242 
00243         if (doEndCap_) {
00244         if (debug_) cout << "Creation of the TowerBlock ... EndCap case " << endl;
00245         iEvent.getByLabel(label_,instanceNameEE_,eeDigis);
00246         for (EEDigiCollection::const_iterator it=eeDigis -> begin();
00247                                 it != eeDigis->end(); it++) {
00248                 const EEDataFrame& dataframe = *it;
00249                 const EEDetId& eedetid = it -> id();
00250                 EcalElectronicsId elid = TheMapping -> getElectronicsId(eedetid);
00251                 int DCCid = elid.dccId() ;   
00252                 int FEDid = FEDNumbering::MINECALFEDID + DCCid;
00253                 FEDRawData& rawdata = productRawData.get() -> FEDData(FEDid);
00254                 Towerblockformatter_ -> DigiToRaw(dataframe, rawdata, TheMapping);
00255         }
00256         }
00257 
00258   }  // endif doTower_
00259 
00260 
00261 
00262 // -------- Clean up things ...
00263 
00264   map<int, map<int,int> >* FEDorder = Towerblockformatter_ -> GetFEDorder();
00265 
00266   Headerblockformatter_ -> CleanUp(productRawData.get(), FEDorder);
00267 
00268 
00269 /*
00270    cout << "For FED 633 " << endl;
00271          FEDRawData& rawdata = productRawData -> FEDData(633);
00272          Headerblockformatter_ -> print(rawdata);
00273 */
00274 
00275  // Headerblockformatter_ -> PrintSizes(productRawData.get());
00276 
00277 
00278 
00279  Towerblockformatter_ -> EndEvent(productRawData.get());
00280 
00281  iEvent.put(productRawData);
00282 
00283 
00284  return;
00285 
00286 }
00287 
00288 
00289 // ------------ method called once each job just before starting event loop  ------------
00290 void 
00291 EcalDigiToRaw::beginJob()
00292 {
00293         Headerblockformatter_ -> SetParam(this);
00294         Towerblockformatter_  -> SetParam(this);
00295         TCCblockformatter_  -> SetParam(this);
00296         SRblockformatter_   -> SetParam(this);
00297 }
00298 
00299 // ------------ method called once each job just after ending the event loop  ------------
00300 void 
00301 EcalDigiToRaw::endJob() {
00302 }
00303 
00304 
00305 
00306 
00307 
00308 
00309