CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelRawToDigi.cc
Go to the documentation of this file.
1 // Include parameter driven interface to SiPixelQuality for study purposes
2 // exclude ROC(raw) based on bad ROC list in SiPixelQuality
3 // enabled by: process.siPixelDigis.UseQualityInfo = True
4 // 20-10-2010 Andrew York (Tennessee)
5 
6 #include "SiPixelRawToDigi.h"
7 
11 
13 
15 
17 
21 
23 
27 
29 
31 
32 #include "TH1D.h"
33 #include "TFile.h"
34 
35 using namespace std;
36 
37 // -----------------------------------------------------------------------------
39  : config_(conf),
40  cabling_(0),
41  badPixelInfo_(0),
42  hCPU(0), hDigi(0), theTimer(0)
43 {
44 
45  includeErrors = config_.getParameter<bool>("IncludeErrors");
46  useQuality = config_.getParameter<bool>("UseQualityInfo");
47  useCablingTree_ = config_.getUntrackedParameter<bool>("UseCablingTree",true);
48 
49  //start counters
50  ndigis = 0;
51  nwords = 0;
52 
53  // Products
54  produces< edm::DetSetVector<PixelDigi> >();
55  if(includeErrors) produces< edm::DetSetVector<SiPixelRawDataError> >();
56 
57  // Timing
58  bool timing = config_.getUntrackedParameter<bool>("Timing",false);
59  if (timing) {
60  theTimer = new R2DTimerObserver("**** MY TIMING REPORT ***");
61  hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
62  hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
63  }
64 }
65 
66 
67 // -----------------------------------------------------------------------------
69  edm::LogInfo("SiPixelRawToDigi") << " HERE ** SiPixelRawToDigi destructor!";
70 
71  if(useCablingTree_) delete cabling_;
72 
73  if (theTimer) {
74  TFile rootFile("analysis.root", "RECREATE", "my histograms");
75  hCPU->Write();
76  hDigi->Write();
77  delete theTimer;
78  }
79 
80 }
81 
82 
83 // -----------------------------------------------------------------------------
84 
85 
86 // -----------------------------------------------------------------------------
88  const edm::EventSetup& es)
89 {
90  const uint32_t dummydetid = 0xffffffff;
92 
93 // initialize cabling map or update if necessary
94  if (recordWatcher.check( es )) {
95  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
97  es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
98  fedIds = cablingMap->fedIds();
99  if (useCablingTree_ && cabling_) delete cabling_;
100  if (useCablingTree_) cabling_ = cablingMap->cablingTree();
101  else cabling_ = cablingMap.product();
102  LogDebug("map version:")<< cabling_->version();
103  }
104 // initialize quality record or update if necessary
105  if (qualityWatcher.check( es )&&useQuality) {
106  // quality info for dead pixel modules or ROCs
107  edm::ESHandle<SiPixelQuality> qualityInfo;
108  es.get<SiPixelQualityRcd>().get( qualityInfo );
109  badPixelInfo_ = qualityInfo.product();
110  if (!badPixelInfo_) {
111  edm::LogError("**SiPixelRawToDigi**")<<" Configured to use SiPixelQuality, but SiPixelQuality not present"<<endl;
112  }
113  }
114 
116  label = config_.getParameter<edm::InputTag>("InputLabel");
117  ev.getByLabel( label, buffers);
118 
119 // create product (digis & errors)
120  std::auto_ptr< edm::DetSetVector<PixelDigi> > collection( new edm::DetSetVector<PixelDigi> );
121  std::auto_ptr< edm::DetSetVector<SiPixelRawDataError> > errorcollection( new edm::DetSetVector<SiPixelRawDataError> );
122 
123  PixelDataFormatter formatter(cabling_);
124  formatter.setErrorStatus(includeErrors);
126 
127  if (theTimer) theTimer->start();
128  bool errorsInEvent = false;
129  PixelDataFormatter::DetErrors nodeterrors;
130 
131  typedef std::vector<unsigned int>::const_iterator IF;
132  for (IF aFed = fedIds.begin(); aFed != fedIds.end(); ++aFed) {
133  int fedId = *aFed;
134  if(debug) LogDebug("SiPixelRawToDigi")<< " PRODUCE DIGI FOR FED: " << fedId << endl;
137 
138  //get event data for this fed
139  const FEDRawData& fedRawData = buffers->FEDData( fedId );
140 
141  //convert data to digi and strip off errors
142  formatter.interpretRawData( errorsInEvent, fedId, fedRawData, digis, errors);
143 
144  //pack digi into collection
145  typedef PixelDataFormatter::Digis::iterator ID;
146  for (ID it = digis.begin(); it != digis.end(); it++) {
147  uint32_t detid = it->first;
148  edm::DetSet<PixelDigi>& detSet = collection->find_or_insert(detid);
149  detSet.data = it->second;
150  }
151 
152  //pack errors into collection
153  if(includeErrors) {
154  typedef PixelDataFormatter::Errors::iterator IE;
155  for (IE is = errors.begin(); is != errors.end(); is++) {
156  uint32_t errordetid = is->first;
157  if (errordetid==dummydetid) { // errors given dummy detId must be sorted by Fed
158  nodeterrors.insert( nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end() );
159  } else {
160  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(errordetid);
161  errorDetSet.data = is->second;
162  }
163  }
164  }
165  }
166 
167  if(includeErrors) {
168  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(dummydetid);
169  errorDetSet.data = nodeterrors;
170  }
171  if (errorsInEvent) LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";
172 
173  if (theTimer) {
174  theTimer->stop();
175  LogDebug("SiPixelRawToDigi") << "TIMING IS: (real)" << theTimer->lastMeasurement().real() ;
176  ndigis += formatter.nDigis();
177  nwords += formatter.nWords();
178  LogDebug("SiPixelRawToDigi") << " (Words/Digis) this ev: "
179  <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<nwords<<"/"<<ndigis;
180  hCPU->Fill( theTimer->lastMeasurement().real() );
181  hDigi->Fill(formatter.nDigis());
182  }
183 
184  //send digis and errors back to framework
185  ev.put( collection );
186  if(includeErrors) ev.put( errorcollection );
187 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
uint32_t ID
Definition: Definitions.h:26
static MessageDrop * instance()
Definition: MessageDrop.cc:65
std::map< uint32_t, DetErrors > Errors
static bool debugEnabled
Definition: MessageDrop.h:100
void interpretRawData(bool &errorsInEvent, int fedId, const FEDRawData &data, Digis &digis, Errors &errors)
void setErrorStatus(bool ErrorStatus)
virtual std::string version() const =0
edm::InputTag label
std::vector< SiPixelRawDataError > DetErrors
std::vector< unsigned int > fedIds
SiPixelRawToDigi(const edm::ParameterSet &)
ctor
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
void setQualityStatus(bool QualityStatus, const SiPixelQuality *QualityInfo)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
tuple conf
Definition: dbtoconf.py:185
virtual ~SiPixelRawToDigi()
dtor
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher
const LastMeasurement & lastMeasurement()
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:59
edm::ParameterSet config_
collection_type data
Definition: DetSet.h:77
std::map< uint32_t, DetDigis > Digis
R2DTimerObserver * theTimer
edm::ESWatcher< SiPixelQualityRcd > qualityWatcher
const SiPixelQuality * badPixelInfo_
const SiPixelFedCabling * cabling_
virtual void produce(edm::Event &, const edm::EventSetup &)
get data, convert to digis attach againe to Event