CMS 3D CMS Logo

SiPixelDigiToRaw.cc
Go to the documentation of this file.
12 
14 
17 
19 
21 
26 
29 
32 
34 
35 #include <atomic>
36 #include <memory>
37 
38 namespace sipixeldigitoraw {
39  struct Cache {
40  std::unique_ptr<SiPixelFedCablingTree> cablingTree_;
41  std::unique_ptr<SiPixelFrameReverter> frameReverter_;
42  };
43 } // namespace sipixeldigitoraw
44 
45 namespace pr = sipixeldigitoraw;
46 
47 class SiPixelDigiToRaw final : public edm::global::EDProducer<edm::LuminosityBlockCache<pr::Cache>> {
48 public:
50  explicit SiPixelDigiToRaw(const edm::ParameterSet&);
51 
53  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const final;
54 
55  std::shared_ptr<pr::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
56  edm::EventSetup const& iES) const final;
57 
58  void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const& iES) const final {}
59 
60  // Fill parameters descriptions
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63 private:
64  mutable std::atomic_flag lock_ = ATOMIC_FLAG_INIT;
65  CMS_THREAD_GUARD(lock_) mutable edm::ESWatcher<SiPixelFedCablingMapRcd> recordWatcher;
66  CMS_THREAD_GUARD(lock_) mutable std::shared_ptr<pr::Cache> previousCache_;
67  const edm::EDGetTokenT<edm::DetSetVector<PixelDigi>> tPixelDigi;
68  const edm::EDGetTokenT<PixelFEDChannelCollection> theBadPixelFEDChannelsToken;
69  const edm::EDPutTokenT<FEDRawDataCollection> putToken_;
70  const bool usePilotBlade = false; // I am not yet sure we need it here?
71  const bool usePhase1;
72 };
73 
74 using namespace std;
75 
77  : tPixelDigi{consumes<edm::DetSetVector<PixelDigi>>(pset.getParameter<edm::InputTag>("InputLabel"))},
78  theBadPixelFEDChannelsToken{consumes<PixelFEDChannelCollection>(pset.getParameter<edm::InputTag>("InputLabel"))},
79  putToken_{produces<FEDRawDataCollection>()},
80  usePhase1{pset.getParameter<bool>("UsePhase1")} {
81  // Define EDProduct type
82 
83  if (usePhase1)
84  edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)";
85 }
86 
87 // -----------------------------------------------------------------------------
89  edm::EventSetup const& es) const {
90  while (lock_.test_and_set(std::memory_order_acquire))
91  ; //spin
92  auto rel = [](std::atomic_flag* f) { f->clear(std::memory_order_release); };
93  std::unique_ptr<std::atomic_flag, decltype(rel)> guard(&lock_, rel);
94 
95  if (recordWatcher.check(es)) {
97  es.get<SiPixelFedCablingMapRcd>().get(cablingMap);
98  previousCache_ = std::make_shared<pr::Cache>();
99  previousCache_->cablingTree_ = cablingMap->cablingTree();
100  previousCache_->frameReverter_ = std::make_unique<SiPixelFrameReverter>(es, cablingMap.product());
101  }
102  return previousCache_;
103 }
104 
105 // -----------------------------------------------------------------------------
107  using namespace sipixelobjects;
108 
110  ev.getByToken(tPixelDigi, digiCollection);
111 
114 
115  int digiCounter = 0;
116  for (auto const& di : *digiCollection) {
117  digiCounter += (di.data).size();
118  digis[di.id] = di.data;
119  }
120 
121  auto cache = luminosityBlockCache(ev.getLuminosityBlock().index());
122 
123  LogDebug("SiPixelDigiToRaw") << cache->cablingTree_->version();
124 
126  edm::Handle<PixelFEDChannelCollection> pixelFEDChannelCollectionHandle;
127  if (usePhase1 && ev.getByToken(theBadPixelFEDChannelsToken, pixelFEDChannelCollectionHandle)) {
128  for (auto const& fedChannels : *pixelFEDChannelCollectionHandle) {
129  PixelDataFormatter::DetBadChannels detBadChannels;
130  for (const auto& fedChannel : fedChannels) {
131  sipixelobjects::CablingPathToDetUnit path = {fedChannel.fed, fedChannel.link, 1};
132  if (cache->cablingTree_->findItem(path) != nullptr) {
133  detBadChannels.push_back(fedChannel);
134  } else {
135  edm::LogError("SiPixelDigiToRaw")
136  << " FED " << fedChannel.fed << " Link " << fedChannel.link << " for module " << fedChannels.detId()
137  << " marked bad, but this channel does not exist in the cabling map" << endl;
138  }
139  } // channels reading a module
140  if (!detBadChannels.empty())
141  badChannels.insert({fedChannels.detId(), std::move(detBadChannels)});
142  } // loop on detId-s
143  }
144 
145  //PixelDataFormatter formatter(cablingTree_.get());
146  PixelDataFormatter formatter(cache->cablingTree_.get(), usePhase1);
147 
148  formatter.passFrameReverter(cache->frameReverter_.get());
149 
150  // create product (raw data)
151  FEDRawDataCollection buffers;
152 
153  // convert data to raw
154  formatter.formatRawData(ev.id().event(), rawdata, digis, badChannels);
155 
156  // pack raw data into collection
157  for (auto const* fed : cache->cablingTree_->fedList()) {
158  LogDebug("SiPixelDigiToRaw") << " PRODUCE DATA FOR FED_id: " << fed->id();
159  FEDRawData& fedRawData = buffers.FEDData(fed->id());
160  PixelDataFormatter::RawData::iterator fedbuffer = rawdata.find(fed->id());
161  if (fedbuffer != rawdata.end())
162  fedRawData = fedbuffer->second;
163  LogDebug("SiPixelDigiToRaw") << "size of data in fedRawData: " << fedRawData.size();
164  }
165 
166  LogDebug("SiPixelDigiToRaw").log([&](auto& l) {
167  l << "Words/Digis this ev: " << digiCounter << "(fm:" << formatter.nDigis() << ")/" << formatter.nWords();
168  });
169  ev.emplace(putToken_, std::move(buffers));
170 }
171 
172 // -----------------------------------------------------------------------------
175  desc.add<edm::InputTag>("InputLabel");
176  desc.add<bool>("UsePhase1", false);
177  desc.addUntracked<bool>("Timing", false)->setComment("deprecated");
178  descriptions.add("siPixelRawData", desc);
179 }
180 
181 // declare this as a framework plugin
#define LogDebug(id)
size
Write out results.
EventNumber_t event() const
Definition: EventID.h:40
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final
get data, convert to raw event, attach again to Event
std::map< cms_uint32_t, DetDigis > Digis
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
LuminosityBlockIndex index() const
void passFrameReverter(const SiPixelFrameReverter *reverter)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
bool ev
std::unique_ptr< SiPixelFedCablingTree > cablingTree_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &iES) const final
std::map< cms_uint32_t, DetBadChannels > BadChannels
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
#define CMS_THREAD_GUARD(_var_)
double f[11][100]
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:98
std::shared_ptr< pr::Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &iES) const final
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< SiPixelFrameReverter > frameReverter_
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:421
std::map< int, FEDRawData > RawData
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< PixelFEDChannel > DetBadChannels
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
def cache(function)
Definition: utilities.py:3
T get() const
Definition: EventSetup.h:73
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511