CMS 3D CMS Logo

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