CMS 3D CMS Logo

SiPixelDigiToRaw.cc
Go to the documentation of this file.
13 
19 
26 
28 
29 #include <atomic>
30 #include <memory>
31 
32 namespace sipixeldigitoraw {
33  struct Cache {
34  std::unique_ptr<SiPixelFedCablingTree> cablingTree_;
35  std::unique_ptr<SiPixelFrameReverter> frameReverter_;
36  };
37 } // namespace sipixeldigitoraw
38 
39 namespace pr = sipixeldigitoraw;
40 
41 class SiPixelDigiToRaw final : public edm::global::EDProducer<edm::LuminosityBlockCache<pr::Cache>> {
42 public:
44  explicit SiPixelDigiToRaw(const edm::ParameterSet&);
45 
47  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const final;
48 
49  std::shared_ptr<pr::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
50  edm::EventSetup const& iES) const final;
51 
52  void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const& iES) const final {}
53 
54  // Fill parameters descriptions
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57 private:
58  mutable std::atomic_flag lock_ = ATOMIC_FLAG_INIT;
60  CMS_THREAD_GUARD(lock_) mutable std::shared_ptr<pr::Cache> previousCache_;
65  const bool usePilotBlade = false; // I am not yet sure we need it here?
66  const bool usePhase1;
67 };
68 
69 using namespace std;
70 
72  : tPixelDigi{consumes<edm::DetSetVector<PixelDigi>>(pset.getParameter<edm::InputTag>("InputLabel"))},
73  theBadPixelFEDChannelsToken{consumes<PixelFEDChannelCollection>(pset.getParameter<edm::InputTag>("InputLabel"))},
74  cabelingMapToken_(
75  esConsumes<SiPixelFedCablingMap, SiPixelFedCablingMapRcd, edm::Transition::BeginLuminosityBlock>()),
76  putToken_{produces<FEDRawDataCollection>()},
77  usePhase1{pset.getParameter<bool>("UsePhase1")} {
78  // Define EDProduct type
79 
80  if (usePhase1)
81  edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)";
82 }
83 
84 // -----------------------------------------------------------------------------
86  edm::EventSetup const& es) const {
87  while (lock_.test_and_set(std::memory_order_acquire))
88  ; //spin
89  auto rel = [](std::atomic_flag* f) { f->clear(std::memory_order_release); };
90  std::unique_ptr<std::atomic_flag, decltype(rel)> guard(&lock_, rel);
91 
92  if (recordWatcher.check(es)) {
94  previousCache_ = std::make_shared<pr::Cache>();
95  previousCache_->cablingTree_ = cablingMap->cablingTree();
96  previousCache_->frameReverter_ = std::make_unique<SiPixelFrameReverter>(cablingMap.product());
97  }
98  return previousCache_;
99 }
100 
101 // -----------------------------------------------------------------------------
103  using namespace sipixelobjects;
104 
106  ev.getByToken(tPixelDigi, digiCollection);
107 
110 
111  int digiCounter = 0;
112  for (auto const& di : *digiCollection) {
113  digiCounter += (di.data).size();
114  digis[di.id] = di.data;
115  }
116 
117  auto cache = luminosityBlockCache(ev.getLuminosityBlock().index());
118 
119  LogDebug("SiPixelDigiToRaw") << cache->cablingTree_->version();
120 
122  edm::Handle<PixelFEDChannelCollection> pixelFEDChannelCollectionHandle;
123  if (usePhase1 && ev.getByToken(theBadPixelFEDChannelsToken, pixelFEDChannelCollectionHandle)) {
124  for (auto const& fedChannels : *pixelFEDChannelCollectionHandle) {
125  PixelDataFormatter::DetBadChannels detBadChannels;
126  for (const auto& fedChannel : fedChannels) {
127  sipixelobjects::CablingPathToDetUnit path = {fedChannel.fed, fedChannel.link, 1};
128  if (cache->cablingTree_->findItem(path) != nullptr) {
129  detBadChannels.push_back(fedChannel);
130  } else {
131  edm::LogError("SiPixelDigiToRaw")
132  << " FED " << fedChannel.fed << " Link " << fedChannel.link << " for module " << fedChannels.detId()
133  << " marked bad, but this channel does not exist in the cabling map" << endl;
134  }
135  } // channels reading a module
136  if (!detBadChannels.empty())
137  badChannels.insert({fedChannels.detId(), std::move(detBadChannels)});
138  } // loop on detId-s
139  }
140 
141  //PixelDataFormatter formatter(cablingTree_.get());
142  PixelDataFormatter formatter(cache->cablingTree_.get(), usePhase1);
143 
144  formatter.passFrameReverter(cache->frameReverter_.get());
145 
146  // create product (raw data)
147  FEDRawDataCollection buffers;
148 
149  // convert data to raw
150  formatter.formatRawData(ev.id().event(), rawdata, digis, badChannels);
151 
152  // pack raw data into collection
153  for (auto const* fed : cache->cablingTree_->fedList()) {
154  LogDebug("SiPixelDigiToRaw") << " PRODUCE DATA FOR FED_id: " << fed->id();
155  FEDRawData& fedRawData = buffers.FEDData(fed->id());
156  PixelDataFormatter::RawData::iterator fedbuffer = rawdata.find(fed->id());
157  if (fedbuffer != rawdata.end())
158  fedRawData = fedbuffer->second;
159  LogDebug("SiPixelDigiToRaw") << "size of data in fedRawData: " << fedRawData.size();
160  }
161 
162  LogDebug("SiPixelDigiToRaw").log([&](auto& l) {
163  l << "Words/Digis this ev: " << digiCounter << "(fm:" << formatter.nDigis() << ")/" << formatter.nWords();
164  });
165  ev.emplace(putToken_, std::move(buffers));
166 }
167 
168 // -----------------------------------------------------------------------------
171  desc.add<edm::InputTag>("InputLabel");
172  desc.add<bool>("UsePhase1", false);
173  descriptions.add("siPixelRawData", desc);
174 }
175 
176 // declare this as a framework plugin
SiPixelDigiToRaw::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SiPixelDigiToRaw.cc:169
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
edm::StreamID
Definition: StreamID.h:30
SiPixelDigiToRaw
Definition: SiPixelDigiToRaw.cc:41
Handle.h
MessageLogger.h
edm::ESWatcher< SiPixelFedCablingMapRcd >
ESHandle.h
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
PixelDataFormatter::RawData
std::map< int, FEDRawData > RawData
Definition: PixelDataFormatter.h:66
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::EDGetTokenT
Definition: EDGetToken.h:33
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm::EDPutTokenT< FEDRawDataCollection >
PixelFEDChannel.h
SiPixelDigiToRaw::globalBeginLuminosityBlock
std::shared_ptr< pr::Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &iES) const final
Definition: SiPixelDigiToRaw.cc:85
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
SiPixelDigiToRaw::recordWatcher
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher
Definition: SiPixelDigiToRaw.cc:59
SiPixelFedCablingMap.h
SiPixelDigiToRaw::usePilotBlade
const bool usePilotBlade
Definition: SiPixelDigiToRaw.cc:65
PixelDigi.h
SiPixelFedCablingTree.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
FEDRawData.h
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
FEDRawData
Definition: FEDRawData.h:19
PixelDataFormatter
Definition: PixelDataFormatter.h:61
MakerMacros.h
sipixeldigitoraw::Cache
Definition: SiPixelDigiToRaw.cc:33
sipixeldigitoraw::Cache::frameReverter_
std::unique_ptr< SiPixelFrameReverter > frameReverter_
Definition: SiPixelDigiToRaw.cc:35
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
sipixelobjects
Definition: CablingPathToDetUnit.h:4
SiPixelDigiToRaw::SiPixelDigiToRaw
SiPixelDigiToRaw(const edm::ParameterSet &)
ctor
Definition: SiPixelDigiToRaw.cc:71
sipixelobjects::CablingPathToDetUnit
Definition: CablingPathToDetUnit.h:5
edm::ESHandle< SiPixelFedCablingMap >
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
utilities.cache
def cache(function)
Definition: utilities.py:3
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
SiPixelFedCablingMap::cablingTree
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
Definition: SiPixelFedCablingMap.cc:103
SiPixelDigiToRaw::previousCache_
std::shared_ptr< pr::Cache > previousCache_
Definition: SiPixelDigiToRaw.cc:60
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
sipixeldigitoraw
Definition: SiPixelDigiToRaw.cc:32
Event.h
SiPixelFedCablingMapRcd.h
thread_safety_macros.h
PixelDataFormatter::DetBadChannels
std::vector< PixelFEDChannel > DetBadChannels
Definition: PixelDataFormatter.h:69
postprocess-scan-build.formatter
formatter
Definition: postprocess-scan-build.py:49
FEDRawDataCollection.h
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
SiPixelDigiToRaw::putToken_
const edm::EDPutTokenT< FEDRawDataCollection > putToken_
Definition: SiPixelDigiToRaw.cc:64
apvshotsanalyzer_cfi.digiCollection
digiCollection
Definition: apvshotsanalyzer_cfi.py:4
edm::EventSetup
Definition: EventSetup.h:58
DetSetVector.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
SiPixelDigiToRaw::lock_
std::atomic_flag lock_
Definition: SiPixelDigiToRaw.cc:58
PixelDataFormatter::Digis
std::map< cms_uint32_t, DetDigis > Digis
Definition: PixelDataFormatter.h:68
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd >
InputTag.h
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
SiPixelDigiToRaw::tPixelDigi
const edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > tPixelDigi
Definition: SiPixelDigiToRaw.cc:61
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
PixelDataFormatter.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
RefreshWebPage.rel
rel
Definition: RefreshWebPage.py:66
ESWatcher.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:97
PixelDataFormatter::BadChannels
std::map< cms_uint32_t, DetBadChannels > BadChannels
Definition: PixelDataFormatter.h:70
EventSetup.h
sipixeldigitoraw::Cache::cablingTree_
std::unique_ptr< SiPixelFedCablingTree > cablingTree_
Definition: SiPixelDigiToRaw.cc:34
SiPixelDigiToRaw::globalEndLuminosityBlock
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &iES) const final
Definition: SiPixelDigiToRaw.cc:52
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
CPUTimer.h
ParameterSet.h
EDProducer.h
SiPixelDigiToRaw::usePhase1
const bool usePhase1
Definition: SiPixelDigiToRaw.cc:66
edm::Event
Definition: Event.h:73
SiPixelDigiToRaw::cabelingMapToken_
const edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > cabelingMapToken_
Definition: SiPixelDigiToRaw.cc:63
CMS_THREAD_GUARD
#define CMS_THREAD_GUARD(_var_)
Definition: thread_safety_macros.h:6
edm::InputTag
Definition: InputTag.h:15
PixelFEDCabling.h
SiPixelDigiToRaw::theBadPixelFEDChannelsToken
const edm::EDGetTokenT< PixelFEDChannelCollection > theBadPixelFEDChannelsToken
Definition: SiPixelDigiToRaw.cc:62
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
SiPixelDigiToRaw::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final
get data, convert to raw event, attach again to Event
Definition: SiPixelDigiToRaw.cc:102
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
SiPixelFrameReverter.h