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  fedList = 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  if (badPixelInfo_) delete badPixelInfo_;
110  badPixelInfo_ = qualityInfo.product();
111  if (!badPixelInfo_) {
112  edm::LogError("**SiPixelRawToDigi**")<<" Configured to use SiPixelQuality, but SiPixelQuality not present"<<endl;
113  }
114  }
115 
117  label = config_.getParameter<edm::InputTag>("InputLabel");
118  ev.getByLabel( label, buffers);
119 
120 // create product (digis & errors)
121  std::auto_ptr< edm::DetSetVector<PixelDigi> > collection( new edm::DetSetVector<PixelDigi> );
122  std::auto_ptr< edm::DetSetVector<SiPixelRawDataError> > errorcollection( new edm::DetSetVector<SiPixelRawDataError> );
123 
124  PixelDataFormatter formatter(cabling_);
125  formatter.setErrorStatus(includeErrors);
127 
128  if (theTimer) theTimer->start();
129  bool errorsInEvent = false;
130  PixelDataFormatter::DetErrors nodeterrors;
131 
132  typedef std::vector<unsigned int>::const_iterator IF;
133  for (IF aFed = fedList.begin(); aFed != fedList.end(); ++aFed) {
134  int fedId = *aFed;
135  if(debug) LogDebug("SiPixelRawToDigi")<< " PRODUCE DIGI FOR FED: " << fedId << endl;
138 
139  //get event data for this fed
140  const FEDRawData& fedRawData = buffers->FEDData( fedId );
141 
142  //convert data to digi and strip off errors
143  formatter.interpretRawData( errorsInEvent, fedId, fedRawData, digis, errors);
144 
145  //pack digi into collection
146  typedef PixelDataFormatter::Digis::iterator ID;
147  for (ID it = digis.begin(); it != digis.end(); it++) {
148  uint32_t detid = it->first;
149  edm::DetSet<PixelDigi>& detSet = collection->find_or_insert(detid);
150  detSet.data = it->second;
151  }
152 
153  //pack errors into collection
154  if(includeErrors) {
155  typedef PixelDataFormatter::Errors::iterator IE;
156  for (IE is = errors.begin(); is != errors.end(); is++) {
157  uint32_t errordetid = is->first;
158  if (errordetid==dummydetid) { // errors given dummy detId must be sorted by Fed
159  nodeterrors.insert( nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end() );
160  } else {
161  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(errordetid);
162  errorDetSet.data = is->second;
163  }
164  }
165  }
166  }
167 
168  if(includeErrors) {
169  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(dummydetid);
170  errorDetSet.data = nodeterrors;
171  }
172  if (errorsInEvent) LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";
173 
174  if (theTimer) {
175  theTimer->stop();
176  LogDebug("SiPixelRawToDigi") << "TIMING IS: (real)" << theTimer->lastMeasurement().real() ;
177  ndigis += formatter.nDigis();
178  nwords += formatter.nWords();
179  LogDebug("SiPixelRawToDigi") << " (Words/Digis) this ev: "
180  <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<nwords<<"/"<<ndigis;
181  hCPU->Fill( theTimer->lastMeasurement().real() );
182  hDigi->Fill(formatter.nDigis());
183  }
184 
185  //send digis and errors back to framework
186  ev.put( collection );
187  if(includeErrors) ev.put( errorcollection );
188 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< unsigned int > fedList
uint32_t ID
Definition: Definitions.h:26
static MessageDrop * instance()
Definition: MessageDrop.cc:61
std::map< uint32_t, DetErrors > Errors
static bool debugEnabled
Definition: MessageDrop.h:97
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
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:359
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:65
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