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