CMS 3D CMS Logo

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(nullptr), hDigi(nullptr)
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");
82  ev.getByToken( tPixelDigi, digiCollection);
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_;
101  frameReverter_ = new SiPixelFrameReverter( es, cablingMap.product() );
102  }
103 
105  if (debug) LogDebug("SiPixelDigiToRaw") << cablingTree_->version();
106 
107  //PixelDataFormatter formatter(cablingTree_.get());
108  PixelDataFormatter formatter(cablingTree_.get(), usePhase1);
109 
111  if (theTimer) theTimer->start();
112 
113  // create product (raw data)
114  auto buffers = std::make_unique<FEDRawDataCollection>();
115 
116  const vector<const PixelFEDCabling *> fedList = cablingTree_->fedList();
117 
118  // convert data to raw
119  formatter.formatRawData( ev.id().event(), rawdata, digis );
120 
121  // pack raw data into collection
122  typedef vector<const PixelFEDCabling *>::const_iterator FI;
123  for (FI it = fedList.begin(); it != fedList.end(); it++) {
124  LogDebug("SiPixelDigiToRaw")<<" PRODUCE DATA FOR FED_id: " << (**it).id();
125  FEDRawData& fedRawData = buffers->FEDData( (**it).id() );
126  PixelDataFormatter::RawData::iterator fedbuffer = rawdata.find( (**it).id() );
127  if( fedbuffer != rawdata.end() ) fedRawData = fedbuffer->second;
128  LogDebug("SiPixelDigiToRaw")<<"size of data in fedRawData: "<<fedRawData.size();
129  }
130  allWordCounter += formatter.nWords();
131  if (debug) LogDebug("SiPixelDigiToRaw")
132 
133  << "Words/Digis this ev: "<<digiCounter<<"(fm:"<<formatter.nDigis()<<")/"
134  <<formatter.nWords()
135  <<" all: "<< allDigiCounter <<"/"<<allWordCounter;
136 
137  if (theTimer) {
138  theTimer->stop();
139  LogDebug("SiPixelDigiToRaw") << "TIMING IS: (real)" << theTimer->realTime() ;
140  LogDebug("SiPixelDigiToRaw") << " (Words/Digis) this ev: "
141  <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<allWordCounter<<"/"<<allDigiCounter;
142  hCPU->Fill( theTimer->realTime() );
143  hDigi->Fill(formatter.nDigis());
144  }
145 
146  ev.put(std::move(buffers));
147 
148 }
149 
150 // declare this as a framework plugin
#define LogDebug(id)
size
Write out results.
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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void passFrameReverter(const SiPixelFrameReverter *reverter)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
std::vector< unsigned int > const fedList
Definition: Constants.h:87
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
std::unique_ptr< edm::CPUTimer > theTimer
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_
T get() const
Definition: EventSetup.h:63
~SiPixelDigiToRaw() override
dtor
std::vector< unsigned int > fedIds() const
T const * product() const
Definition: ESHandle.h:86
edm::InputTag label
def move(src, dest)
Definition: eostools.py:510