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 
32  // Define EDProduct type
33  produces<FEDRawDataCollection>();
34 
35  // start the counters
36  eventCounter = 0;
37  allDigiCounter = 0;
38  allWordCounter = 0;
39 
40  // Timing
41  bool timing = config_.getUntrackedParameter<bool>("Timing",false);
42  if (timing) {
43  theTimer.reset(new edm::CPUTimer);
44  hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
45  hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
46  }
47 
48  // Control the usage of phase1
49  usePhase1 = false;
50  if (config_.exists("UsePhase1")) {
51  usePhase1 = config_.getParameter<bool> ("UsePhase1");
52  if(usePhase1) edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)";
53  }
54 
55  usePilotBlade=false; // I am not yet sure we need it here?
56 }
57 
58 // -----------------------------------------------------------------------------
60  delete frameReverter_;
61 
62  if (theTimer) {
63  TFile rootFile("analysis.root", "RECREATE", "my histograms");
64  hCPU->Write();
65  hDigi->Write();
66  }
67 }
68 
69 // -----------------------------------------------------------------------------
70 
71 // -----------------------------------------------------------------------------
73  const edm::EventSetup& es)
74 {
75  using namespace sipixelobjects;
76  eventCounter++;
77  edm::LogInfo("SiPixelDigiToRaw") << "[SiPixelDigiToRaw::produce] "
78  << "event number: " << eventCounter;
79 
81  label = config_.getParameter<edm::InputTag>("InputLabel");
83 
86  typedef vector< edm::DetSet<PixelDigi> >::const_iterator DI;
87 
88  int digiCounter = 0;
89  for (DI di=digiCollection->begin(); di != digiCollection->end(); di++) {
90  digiCounter += (di->data).size();
91  digis[ di->id] = di->data;
92  }
93  allDigiCounter += digiCounter;
94 
95  if (recordWatcher.check( es )) {
97  es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
98  fedIds = cablingMap->fedIds();
99  cablingTree_= cablingMap->cablingTree();
100  if (frameReverter_) delete frameReverter_; frameReverter_ = new SiPixelFrameReverter( es, cablingMap.product() );
101  }
102 
104  if (debug) LogDebug("SiPixelDigiToRaw") << cablingTree_->version();
105 
106  //PixelDataFormatter formatter(cablingTree_.get());
107  PixelDataFormatter formatter(cablingTree_.get(), usePhase1);
108 
110  if (theTimer) theTimer->start();
111 
112  // create product (raw data)
113  std::auto_ptr<FEDRawDataCollection> buffers( new FEDRawDataCollection );
114 
115  const vector<const PixelFEDCabling *> fedList = cablingTree_->fedList();
116 
117  // convert data to raw
118  formatter.formatRawData( ev.id().event(), rawdata, digis );
119 
120  // pack raw data into collection
121  typedef vector<const PixelFEDCabling *>::const_iterator FI;
122  for (FI it = fedList.begin(); it != fedList.end(); it++) {
123  LogDebug("SiPixelDigiToRaw")<<" PRODUCE DATA FOR FED_id: " << (**it).id();
124  FEDRawData& fedRawData = buffers->FEDData( (**it).id() );
125  PixelDataFormatter::RawData::iterator fedbuffer = rawdata.find( (**it).id() );
126  if( fedbuffer != rawdata.end() ) fedRawData = fedbuffer->second;
127  LogDebug("SiPixelDigiToRaw")<<"size of data in fedRawData: "<<fedRawData.size();
128  }
129  allWordCounter += formatter.nWords();
130  if (debug) LogDebug("SiPixelDigiToRaw")
131 
132  << "Words/Digis this ev: "<<digiCounter<<"(fm:"<<formatter.nDigis()<<")/"
133  <<formatter.nWords()
134  <<" all: "<< allDigiCounter <<"/"<<allWordCounter;
135 
136  if (theTimer) {
137  theTimer->stop();
138  LogDebug("SiPixelDigiToRaw") << "TIMING IS: (real)" << theTimer->realTime() ;
139  LogDebug("SiPixelDigiToRaw") << " (Words/Digis) this ev: "
140  <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<allWordCounter<<"/"<<allDigiCounter;
141  hCPU->Fill( theTimer->realTime() );
142  hDigi->Fill(formatter.nDigis());
143  }
144 
145  ev.put( buffers );
146 
147 }
148 
149 // -----------------------------------------------------------------------------
150 
#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
void passFrameReverter(const SiPixelFrameReverter *reverter)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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
bool exists(std::string const &parameterName) const
checks if a parameter exists
unsigned long eventCounter
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > tPixelDigi
bool ev
#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:115
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:60
SiPixelFrameReverter * frameReverter_
dictionary rawdata
Definition: lumiPlot.py:393
tuple size
Write out results.
edm::InputTag label