CMS 3D CMS Logo

Public Member Functions | Private Attributes

SiPixelRawToDigi Class Reference

#include <SiPixelRawToDigi.h>

Inheritance diagram for SiPixelRawToDigi:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

virtual void endJob ()
 dummy end of job
virtual void produce (edm::Event &, const edm::EventSetup &)
 get data, convert to digis attach againe to Event
 SiPixelRawToDigi (const edm::ParameterSet &)
 ctor
virtual ~SiPixelRawToDigi ()
 dtor

Private Attributes

const SiPixelQualitybadPixelInfo_
const SiPixelFedCablingcabling_
edm::ParameterSet config_
bool debug
std::vector< unsigned int > fedIds
TH1D * hCPU
TH1D * hDigi
bool includeErrors
edm::InputTag label
int ndigis
int nwords
edm::ESWatcher< SiPixelQualityRcdqualityWatcher
edm::ESWatcher
< SiPixelFedCablingMapRcd
recordWatcher
PixelUnpackingRegionsregions_
R2DTimerObservertheTimer
std::vector< int > tkerrorlist
bool useCablingTree_
bool useQuality
std::vector< int > usererrorlist

Detailed Description

Definition at line 23 of file SiPixelRawToDigi.h.


Constructor & Destructor Documentation

SiPixelRawToDigi::SiPixelRawToDigi ( const edm::ParameterSet conf) [explicit]

ctor

Definition at line 39 of file SiPixelRawToDigi.cc.

References config_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), edm::ParameterSet::getUntrackedParameter(), hCPU, hDigi, includeErrors, ndigis, nwords, regions_, theTimer, tkerrorlist, useCablingTree_, useQuality, and usererrorlist.

  : config_(conf), 
    cabling_(0), 
    badPixelInfo_(0),
    regions_(0),
    hCPU(0), hDigi(0), theTimer(0)
{

  includeErrors = config_.getParameter<bool>("IncludeErrors");
  useQuality = config_.getParameter<bool>("UseQualityInfo");
  useCablingTree_ = config_.getUntrackedParameter<bool>("UseCablingTree",true);
  if (config_.exists("ErrorList")) {
    tkerrorlist = config_.getParameter<std::vector<int> > ("ErrorList");
  }
  if (config_.exists("UserErrorList")) {
    usererrorlist = config_.getParameter<std::vector<int> > ("UserErrorList");
  }

  //start counters
  ndigis = 0;
  nwords = 0;

  // Products
  produces< edm::DetSetVector<PixelDigi> >();
  if(includeErrors){
    produces< edm::DetSetVector<SiPixelRawDataError> >();
    produces<DetIdCollection>();
    produces<DetIdCollection>("UserErrorModules");
  }

  // regions
  if (config_.exists("Regions")) {
    if(config_.getParameter<edm::ParameterSet>("Regions").getParameterNames().size() > 0)
    {
      regions_ = new PixelUnpackingRegions(config_);
    }
  }

  // Timing
  bool timing = config_.getUntrackedParameter<bool>("Timing",false);
  if (timing) {
    theTimer = new R2DTimerObserver("**** MY TIMING REPORT ***");
    hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
    hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
  }
}
SiPixelRawToDigi::~SiPixelRawToDigi ( ) [virtual]

dtor

Definition at line 88 of file SiPixelRawToDigi.cc.

References cabling_, hCPU, hDigi, regions_, theTimer, and useCablingTree_.

                                    {
  edm::LogInfo("SiPixelRawToDigi")  << " HERE ** SiPixelRawToDigi destructor!";

  if (useCablingTree_) delete cabling_;
  if (regions_) delete regions_;

  if (theTimer) {
    TFile rootFile("analysis.root", "RECREATE", "my histograms");
    hCPU->Write();
    hDigi->Write();
    delete theTimer;
  }

}

Member Function Documentation

virtual void SiPixelRawToDigi::endJob ( void  ) [inline, virtual]

dummy end of job

Reimplemented from edm::EDProducer.

Definition at line 34 of file SiPixelRawToDigi.h.

{}
void SiPixelRawToDigi::produce ( edm::Event ev,
const edm::EventSetup es 
) [virtual]

get data, convert to digis attach againe to Event

Implements edm::EDProducer.

Definition at line 108 of file SiPixelRawToDigi.cc.

References badPixelInfo_, edm::DetSet< T >::begin(), cabling_, edm::ESWatcher< T >::check(), runEdmFileComparison::collection, config_, edm::DetSet< T >::data, debug, cond::rpcobgas::detid, edm::DetSet< T >::end(), benchmark_cfg::errors, fedIds, spr::find(), edm::EventSetup::get(), edm::Event::getByLabel(), edm::ParameterSet::getParameter(), hCPU, hDigi, includeErrors, instance, PixelDataFormatter::interpretRawData(), label, R2DTimerObserver::lastMeasurement(), LogDebug, PixelUnpackingRegions::mayUnpackFED(), PixelUnpackingRegions::modulesToUnpack(), PixelUnpackingRegions::nBarrelFEDs(), PixelUnpackingRegions::nBarrelModules(), PixelDataFormatter::nDigis(), ndigis, PixelUnpackingRegions::nFEDs(), PixelUnpackingRegions::nForwardFEDs(), PixelUnpackingRegions::nForwardModules(), PixelUnpackingRegions::nModules(), nwords, PixelDataFormatter::nWords(), edm::ESHandle< T >::product(), edm::Event::put(), qualityWatcher, recordWatcher, regions_, PixelUnpackingRegions::run(), PixelDataFormatter::setErrorStatus(), PixelDataFormatter::setModulesToUnpack(), PixelDataFormatter::setQualityStatus(), R2DTimerObserver::start(), R2DTimerObserver::stop(), theTimer, tkerrorlist, useCablingTree_, useQuality, usererrorlist, and SiPixelFedCabling::version().

{
  const uint32_t dummydetid = 0xffffffff;
  debug = edm::MessageDrop::instance()->debugEnabled;

// initialize cabling map or update if necessary
  if (recordWatcher.check( es )) {
    // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
    if (useCablingTree_) {
      delete cabling_;
      // we are going to make our own copy so safe to let the map be deleted early
      edm::ESTransientHandle<SiPixelFedCablingMap> cablingMap;
      es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
      fedIds   = cablingMap->fedIds();
      cabling_ = cablingMap->cablingTree();
    } else {
      // we are going to hold the pointer so we need the map to stick around
      edm::ESHandle<SiPixelFedCablingMap> cablingMap;
      es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
      fedIds   = cablingMap->fedIds();
      cabling_ = cablingMap.product();
    }
    LogDebug("map version:")<< cabling_->version();
  }
// initialize quality record or update if necessary
  if (qualityWatcher.check( es )&&useQuality) {
    // quality info for dead pixel modules or ROCs
    edm::ESHandle<SiPixelQuality> qualityInfo;
    es.get<SiPixelQualityRcd>().get( qualityInfo );
    badPixelInfo_ = qualityInfo.product();
    if (!badPixelInfo_) {
      edm::LogError("**SiPixelRawToDigi**")<<" Configured to use SiPixelQuality, but SiPixelQuality not present"<<endl;
    }
  }

  edm::Handle<FEDRawDataCollection> buffers;
  label = config_.getParameter<edm::InputTag>("InputLabel");
  ev.getByLabel( label, buffers);

// create product (digis & errors)
  std::auto_ptr< edm::DetSetVector<PixelDigi> > collection( new edm::DetSetVector<PixelDigi> );
  std::auto_ptr< edm::DetSetVector<SiPixelRawDataError> > errorcollection( new edm::DetSetVector<SiPixelRawDataError> );
  std::auto_ptr< DetIdCollection > tkerror_detidcollection(new DetIdCollection());
  std::auto_ptr< DetIdCollection > usererror_detidcollection(new DetIdCollection());

  PixelDataFormatter formatter(cabling_);
  formatter.setErrorStatus(includeErrors);

  if (useQuality) formatter.setQualityStatus(useQuality, badPixelInfo_);

  if (theTimer) theTimer->start();
  bool errorsInEvent = false;
  PixelDataFormatter::DetErrors nodeterrors;

  if (regions_) {
    regions_->run(ev, es);
    formatter.setModulesToUnpack(regions_->modulesToUnpack());
    LogDebug("SiPixelRawToDigi") << "region2unpack #feds (BPIX,EPIX,total): "<<regions_->nBarrelFEDs()<<" "<<regions_->nForwardFEDs()<<" "<<regions_->nFEDs();
    LogDebug("SiPixelRawToDigi") << "region2unpack #modules (BPIX,EPIX,total): "<<regions_->nBarrelModules()<<" "<<regions_->nForwardModules()<<" "<<regions_->nModules();
  }

  typedef std::vector<unsigned int>::const_iterator IF;
  for (IF aFed = fedIds.begin(); aFed != fedIds.end(); ++aFed) {
    int fedId = *aFed;

    if (regions_ && !regions_->mayUnpackFED(fedId)) continue;

    if(debug) LogDebug("SiPixelRawToDigi")<< " PRODUCE DIGI FOR FED: " <<  fedId << endl;
    PixelDataFormatter::Digis digis;
    PixelDataFormatter::Errors errors;

    //get event data for this fed
    const FEDRawData& fedRawData = buffers->FEDData( fedId );

    //convert data to digi and strip off errors
    formatter.interpretRawData( errorsInEvent, fedId, fedRawData, digis, errors);

    //pack digi into collection
    typedef PixelDataFormatter::Digis::iterator ID;
    for (ID it = digis.begin(); it != digis.end(); it++) {
      uint32_t detid = it->first;
      edm::DetSet<PixelDigi>& detSet = collection->find_or_insert(detid);
      detSet.data.insert(detSet.data.end(), it->second.begin(), it->second.end());
    }

    //pack errors into collection
    if(includeErrors) {
      typedef PixelDataFormatter::Errors::iterator IE;
      for (IE is = errors.begin(); is != errors.end(); is++) {
        uint32_t errordetid = is->first;
        if (errordetid==dummydetid) {           // errors given dummy detId must be sorted by Fed
          nodeterrors.insert( nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end() );
        } else {
          edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(errordetid);
          errorDetSet.data.insert(errorDetSet.data.end(), is->second.begin(), is->second.end());
          // Fill detid of the detectors where there is error AND the error number is listed
          // in the configurable error list in the job option cfi.
          // Code needs to be here, because there can be a set of errors for each 
          // entry in the for loop over PixelDataFormatter::Errors
          if(!tkerrorlist.empty() || !usererrorlist.empty()){
            DetId errorDetId(errordetid);
            edm::DetSet<SiPixelRawDataError>::const_iterator itPixelError=errorDetSet.begin();
            for(; itPixelError!=errorDetSet.end(); ++itPixelError){
              // fill list of detIds to be turned off by tracking
              if(!tkerrorlist.empty()) {
                std::vector<int>::iterator it_find = find(tkerrorlist.begin(), tkerrorlist.end(), itPixelError->getType());
                if(it_find != tkerrorlist.end()){
                  tkerror_detidcollection->push_back(errordetid);
                }
              }
              // fill list of detIds with errors to be studied
              if(!usererrorlist.empty()) {
                std::vector<int>::iterator it_find = find(usererrorlist.begin(), usererrorlist.end(), itPixelError->getType());
                if(it_find != usererrorlist.end()){
                  usererror_detidcollection->push_back(errordetid);
                }
              }
            }
          }
        }
      }
    }
  }

  if(includeErrors) {
    edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(dummydetid);
    errorDetSet.data = nodeterrors;
  }
  if (errorsInEvent) LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";

  if (theTimer) {
    theTimer->stop();
    LogDebug("SiPixelRawToDigi") << "TIMING IS: (real)" << theTimer->lastMeasurement().real() ;
    ndigis += formatter.nDigis();
    nwords += formatter.nWords();
    LogDebug("SiPixelRawToDigi") << " (Words/Digis) this ev: "
         <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<nwords<<"/"<<ndigis;
    hCPU->Fill( theTimer->lastMeasurement().real() ); 
    hDigi->Fill(formatter.nDigis());
  }

  //send digis and errors back to framework 
  ev.put( collection );
  if(includeErrors){
    ev.put( errorcollection );
    ev.put( tkerror_detidcollection );
    ev.put( usererror_detidcollection, "UserErrorModules" );
  }
}

Member Data Documentation

Definition at line 43 of file SiPixelRawToDigi.h.

Referenced by produce().

Definition at line 42 of file SiPixelRawToDigi.h.

Referenced by produce(), and ~SiPixelRawToDigi().

Definition at line 41 of file SiPixelRawToDigi.h.

Referenced by produce(), and SiPixelRawToDigi().

bool SiPixelRawToDigi::debug [private]

Definition at line 51 of file SiPixelRawToDigi.h.

Referenced by produce().

std::vector<unsigned int> SiPixelRawToDigi::fedIds [private]

Definition at line 54 of file SiPixelRawToDigi.h.

Referenced by produce().

TH1D* SiPixelRawToDigi::hCPU [private]

Definition at line 47 of file SiPixelRawToDigi.h.

Referenced by produce(), SiPixelRawToDigi(), and ~SiPixelRawToDigi().

TH1D * SiPixelRawToDigi::hDigi [private]

Definition at line 47 of file SiPixelRawToDigi.h.

Referenced by produce(), SiPixelRawToDigi(), and ~SiPixelRawToDigi().

Definition at line 49 of file SiPixelRawToDigi.h.

Referenced by produce(), and SiPixelRawToDigi().

Definition at line 57 of file SiPixelRawToDigi.h.

Referenced by produce().

int SiPixelRawToDigi::ndigis [private]

Definition at line 58 of file SiPixelRawToDigi.h.

Referenced by produce(), and SiPixelRawToDigi().

int SiPixelRawToDigi::nwords [private]

Definition at line 59 of file SiPixelRawToDigi.h.

Referenced by produce(), and SiPixelRawToDigi().

Definition at line 56 of file SiPixelRawToDigi.h.

Referenced by produce().

Definition at line 55 of file SiPixelRawToDigi.h.

Referenced by produce().

Definition at line 45 of file SiPixelRawToDigi.h.

Referenced by produce(), SiPixelRawToDigi(), and ~SiPixelRawToDigi().

Definition at line 48 of file SiPixelRawToDigi.h.

Referenced by produce(), SiPixelRawToDigi(), and ~SiPixelRawToDigi().

std::vector<int> SiPixelRawToDigi::tkerrorlist [private]

Definition at line 52 of file SiPixelRawToDigi.h.

Referenced by produce(), and SiPixelRawToDigi().

Definition at line 44 of file SiPixelRawToDigi.h.

Referenced by produce(), SiPixelRawToDigi(), and ~SiPixelRawToDigi().

Definition at line 50 of file SiPixelRawToDigi.h.

Referenced by produce(), and SiPixelRawToDigi().

std::vector<int> SiPixelRawToDigi::usererrorlist [private]

Definition at line 53 of file SiPixelRawToDigi.h.

Referenced by produce(), and SiPixelRawToDigi().