CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelDigiToRaw.cc
Go to the documentation of this file.
1 #include "SiPixelDigiToRaw.h"
2 
5 
7 
12 
15 
18 
20 
21 #include "TH1D.h"
22 #include "TFile.h"
23 
24 using namespace std;
25 
27  cablingTree_(0),
28  frameReverter_(0),
29  config_(pset),
30  hCPU(0), hDigi(0), theTimer(0)
31 {
32 
33  tPixelDigi = consumes<edm::DetSetVector<PixelDigi> >(config_.getParameter<edm::InputTag>("InputLabel"));
34  // Define EDProduct type
35  produces<FEDRawDataCollection>();
36 
37  // start the counters
38  eventCounter = 0;
39  allDigiCounter = 0;
40  allWordCounter = 0;
41 
42  // Timing
43  bool timing = config_.getUntrackedParameter<bool>("Timing",false);
44  if (timing) {
45  theTimer = new R2DTimerObserver("**** MY TIMING REPORT ***");
46  hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
47  hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
48  }
49 }
50 
51 // -----------------------------------------------------------------------------
53  delete cablingTree_;
54  delete frameReverter_;
55 
56  if (theTimer) {
57  TFile rootFile("analysis.root", "RECREATE", "my histograms");
58  hCPU->Write();
59  hDigi->Write();
60  delete theTimer;
61  }
62 }
63 
64 // -----------------------------------------------------------------------------
65 
66 // -----------------------------------------------------------------------------
68  const edm::EventSetup& es)
69 {
70  using namespace sipixelobjects;
71  eventCounter++;
72  edm::LogInfo("SiPixelDigiToRaw") << "[SiPixelDigiToRaw::produce] "
73  << "event number: " << eventCounter;
74 
76  label = config_.getParameter<edm::InputTag>("InputLabel");
78 
81  typedef vector< edm::DetSet<PixelDigi> >::const_iterator DI;
82 
83  int digiCounter = 0;
84  for (DI di=digiCollection->begin(); di != digiCollection->end(); di++) {
85  digiCounter += (di->data).size();
86  digis[ di->id] = di->data;
87  }
88  allDigiCounter += digiCounter;
89 
90  if (recordWatcher.check( es )) {
92  es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
93  fedIds = cablingMap->fedIds();
94  if (cablingTree_) delete cablingTree_; cablingTree_= cablingMap->cablingTree();
95  if (frameReverter_) delete frameReverter_; frameReverter_ = new SiPixelFrameReverter( es, cablingMap.product() );
96  }
97 
99  if (debug) LogDebug("SiPixelDigiToRaw") << cablingTree_->version();
100 
101  PixelDataFormatter formatter(cablingTree_);
103  if (theTimer) theTimer->start();
104 
105  // create product (raw data)
106  std::auto_ptr<FEDRawDataCollection> buffers( new FEDRawDataCollection );
107 
108  const vector<const PixelFEDCabling *> fedList = cablingTree_->fedList();
109 
110  // convert data to raw
111  formatter.formatRawData( ev.id().event(), rawdata, digis );
112 
113  // pack raw data into collection
114  typedef vector<const PixelFEDCabling *>::const_iterator FI;
115  for (FI it = fedList.begin(); it != fedList.end(); it++) {
116  LogDebug("SiPixelDigiToRaw")<<" PRODUCE DATA FOR FED_id: " << (**it).id();
117  FEDRawData& fedRawData = buffers->FEDData( (**it).id() );
118  PixelDataFormatter::RawData::iterator fedbuffer = rawdata.find( (**it).id() );
119  if( fedbuffer != rawdata.end() ) fedRawData = fedbuffer->second;
120  LogDebug("SiPixelDigiToRaw")<<"size of data in fedRawData: "<<fedRawData.size();
121  }
122  allWordCounter += formatter.nWords();
123  if (debug) LogDebug("SiPixelDigiToRaw")
124 
125  << "Words/Digis this ev: "<<digiCounter<<"(fm:"<<formatter.nDigis()<<")/"
126  <<formatter.nWords()
127  <<" all: "<< allDigiCounter <<"/"<<allWordCounter;
128 
129  if (theTimer) {
130  theTimer->stop();
131  LogDebug("SiPixelDigiToRaw") << "TIMING IS: (real)" << theTimer->lastMeasurement().real() ;
132  LogDebug("SiPixelDigiToRaw") << " (Words/Digis) this ev: "
133  <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<allWordCounter<<"/"<<allDigiCounter;
134  hCPU->Fill( theTimer->lastMeasurement().real() );
135  hDigi->Fill(formatter.nDigis());
136  }
137 
138  ev.put( buffers );
139 
140 }
141 
142 // -----------------------------------------------------------------------------
143 
#define LogDebug(id)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
std::map< cms_uint32_t, DetDigis > Digis
SiPixelDigiToRaw(const edm::ParameterSet &)
ctor
void passFrameReverter(const SiPixelFrameReverter *reverter)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
static MessageDrop * instance()
Definition: MessageDrop.cc:60
unsigned long eventCounter
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > tPixelDigi
virtual void produce(edm::Event &, const edm::EventSetup &)
get data, convert to raw event, attach again to Event
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
std::vector< unsigned int > fedIds
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual ~SiPixelDigiToRaw()
dtor
void formatRawData(unsigned int lvl1_ID, RawData &fedRawData, const Digis &digis)
R2DTimerObserver * theTimer
virtual std::string version() const
map version
const LastMeasurement & lastMeasurement()
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::map< int, FEDRawData > RawData
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher
edm::ParameterSet config_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:58
edm::EventID id() const
Definition: EventBase.h:56
SiPixelFrameReverter * frameReverter_
dictionary rawdata
Definition: lumiPlot.py:393
SiPixelFedCablingTree * cablingTree_
std::vector< const PixelFEDCabling * > fedList() const
tuple size
Write out results.
edm::InputTag label