/
SiStripRawToDigiModule.cc
167 lines (138 loc) · 6.72 KB
/
SiStripRawToDigiModule.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "SiStripRawToDigiModule.h"
#include "SiStripRawToDigiUnpacker.h"
#include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
#include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/DetId/interface/DetIdCollection.h"
#include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
#include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
#include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <cstdlib>
namespace sistrip {
RawToDigiModule::RawToDigiModule( const edm::ParameterSet& pset ) :
rawToDigi_(nullptr),
cabling_(nullptr),
cacheId_(0),
extractCm_(false),
doFullCorruptBufferChecks_(false),
doAPVEmulatorCheck_(true)
{
if ( edm::isDebugEnabled() ) {
LogTrace("SiStripRawToDigi")
<< "[sistrip::RawToDigiModule::" << __func__ << "]"
<< " Constructing object...";
}
token_ = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"));
int16_t appended_bytes = pset.getParameter<int>("AppendedBytes");
int16_t trigger_fed_id = pset.getParameter<int>("TriggerFedId");
bool legacy_unpacker = pset.getParameter<bool>("LegacyUnpacker");
bool use_daq_register = pset.getParameter<bool>("UseDaqRegister");
bool using_fed_key = pset.getParameter<bool>("UseFedKey");
bool unpack_bad_channels = pset.getParameter<bool>("UnpackBadChannels");
bool mark_missing_feds = pset.getParameter<bool>("MarkModulesOnMissingFeds");
int16_t fed_buffer_dump_freq = pset.getUntrackedParameter<int>("FedBufferDumpFreq",0);
int16_t fed_event_dump_freq = pset.getUntrackedParameter<int>("FedEventDumpFreq",0);
bool quiet = pset.getUntrackedParameter<bool>("Quiet",true);
extractCm_ = pset.getParameter<bool>("UnpackCommonModeValues");
doFullCorruptBufferChecks_ = pset.getParameter<bool>("DoAllCorruptBufferChecks");
doAPVEmulatorCheck_ = pset.getParameter<bool>("DoAPVEmulatorCheck");
uint32_t errorThreshold = pset.getParameter<unsigned int>("ErrorThreshold");
rawToDigi_ = new sistrip::RawToDigiUnpacker( appended_bytes, fed_buffer_dump_freq, fed_event_dump_freq, trigger_fed_id, using_fed_key, unpack_bad_channels, mark_missing_feds, errorThreshold);
rawToDigi_->legacy(legacy_unpacker);
rawToDigi_->quiet(quiet);
rawToDigi_->useDaqRegister( use_daq_register );
rawToDigi_->extractCm(extractCm_);
rawToDigi_->doFullCorruptBufferChecks(doFullCorruptBufferChecks_);
rawToDigi_->doAPVEmulatorCheck(doAPVEmulatorCheck_);
produces< SiStripEventSummary >();
produces< edm::DetSetVector<SiStripRawDigi> >("ScopeMode");
produces< edm::DetSetVector<SiStripRawDigi> >("VirginRaw");
produces< edm::DetSetVector<SiStripRawDigi> >("ProcessedRaw");
produces< edm::DetSetVector<SiStripDigi> >("ZeroSuppressed");
produces<DetIdCollection>();
if ( extractCm_ ) produces< edm::DetSetVector<SiStripRawDigi> >("CommonMode");
}
RawToDigiModule::~RawToDigiModule() {
if ( rawToDigi_ ) { delete rawToDigi_; }
if ( cabling_ ) { cabling_ = nullptr; }
if ( edm::isDebugEnabled() ) {
LogTrace("SiStripRawToDigi")
<< "[sistrip::RawToDigiModule::" << __func__ << "]"
<< " Destructing object...";
}
}
void RawToDigiModule::beginRun( const edm::Run& run, const edm::EventSetup& setup ) {
updateCabling( setup );
}
/**
Retrieves cabling map from EventSetup and FEDRawDataCollection
from Event, creates a DetSetVector of SiStrip(Raw)Digis, uses the
SiStripRawToDigiUnpacker class to fill the DetSetVector, and
attaches the container to the Event.
*/
void RawToDigiModule::produce( edm::Event& event, const edm::EventSetup& setup ) {
updateCabling( setup );
// Retrieve FED raw data (by label, which is "source" by default)
edm::Handle<FEDRawDataCollection> buffers;
event.getByToken( token_, buffers );
// Populate SiStripEventSummary object with "trigger FED" info
auto summary = std::make_unique<SiStripEventSummary>();
rawToDigi_->triggerFed( *buffers, *summary, event.id().event() );
// Create containers for digis
edm::DetSetVector<SiStripRawDigi>* sm = new edm::DetSetVector<SiStripRawDigi>();
edm::DetSetVector<SiStripRawDigi>* vr = new edm::DetSetVector<SiStripRawDigi>();
edm::DetSetVector<SiStripRawDigi>* pr = new edm::DetSetVector<SiStripRawDigi>();
edm::DetSetVector<SiStripDigi>* zs = new edm::DetSetVector<SiStripDigi>();
DetIdCollection* ids = new DetIdCollection();
edm::DetSetVector<SiStripRawDigi>* cm = new edm::DetSetVector<SiStripRawDigi>();
// Create digis
if ( rawToDigi_ ) { rawToDigi_->createDigis( *cabling_,*buffers,*summary,*sm,*vr,*pr,*zs,*ids,*cm ); }
// Create unique_ptr's of digi products
std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > sm_dsv(sm);
std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > vr_dsv(vr);
std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > pr_dsv(pr);
std::unique_ptr< edm::DetSetVector<SiStripDigi> > zs_dsv(zs);
std::unique_ptr< DetIdCollection > det_ids(ids);
std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > cm_dsv(cm);
// Add to event
event.put(std::move(summary));
event.put(std::move(sm_dsv), "ScopeMode");
event.put(std::move(vr_dsv), "VirginRaw");
event.put(std::move(pr_dsv), "ProcessedRaw");
event.put(std::move(zs_dsv), "ZeroSuppressed");
event.put(std::move(det_ids));
if ( extractCm_ ) event.put(std::move(cm_dsv), "CommonMode");
}
void RawToDigiModule::updateCabling( const edm::EventSetup& setup ) {
uint32_t cache_id = setup.get<SiStripFedCablingRcd>().cacheIdentifier();
if ( cacheId_ != cache_id ) {
edm::ESHandle<SiStripFedCabling> c;
setup.get<SiStripFedCablingRcd>().get( c );
cabling_ = c.product();
if ( edm::isDebugEnabled() ) {
if ( !cacheId_ ) {
std::stringstream ss;
ss << "[sistrip::RawToDigiModule::" << __func__ << "]"
<< " Updating cabling for first time..." << std::endl
<< " Terse print out of FED cabling:" << std::endl;
cabling_->terse(ss);
LogTrace("SiStripRawToDigi") << ss.str();
}
}
if ( edm::isDebugEnabled() ) {
std::stringstream sss;
sss << "[sistrip::RawToDigiModule::" << __func__ << "]"
<< " Summary of FED cabling:" << std::endl;
edm::ESHandle<TrackerTopology> tTopo;
setup.get<TrackerTopologyRcd>().get(tTopo);
cabling_->summary(sss, tTopo.product());
LogTrace("SiStripRawToDigi") << sss.str();
}
cacheId_ = cache_id;
}
}
}