CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 }
44 
45 namespace pr = sipixeldigitoraw;
46 
47 class SiPixelDigiToRaw final : public edm::global::EDProducer<edm::LuminosityBlockCache<pr::Cache>> {
48 public:
49 
51  explicit SiPixelDigiToRaw( const edm::ParameterSet& );
52 
53 
55  void produce( edm::StreamID, edm::Event&, const edm::EventSetup& ) const final;
56 
57  std::shared_ptr<pr::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
58  edm::EventSetup const& iES) const final;
59 
61  edm::EventSetup const& iES) const final {}
62 
63  // Fill parameters descriptions
64  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
65 
66 private:
67 
68  mutable std::atomic_flag lock_ = ATOMIC_FLAG_INIT;
69  CMS_THREAD_GUARD(lock_) mutable edm::ESWatcher<SiPixelFedCablingMapRcd> recordWatcher;
70  CMS_THREAD_GUARD(lock_) mutable std::shared_ptr<pr::Cache> previousCache_;
71  const edm::EDGetTokenT<edm::DetSetVector<PixelDigi>> tPixelDigi;
72  const edm::EDGetTokenT<PixelFEDChannelCollection> theBadPixelFEDChannelsToken;
73  const edm::EDPutTokenT<FEDRawDataCollection> putToken_;
74  const bool usePilotBlade = false; // I am not yet sure we need it here?
75  const bool usePhase1;
76 };
77 
78 using namespace std;
79 
81  tPixelDigi{ consumes<edm::DetSetVector<PixelDigi> >(pset.getParameter<edm::InputTag>("InputLabel")) },
82  theBadPixelFEDChannelsToken{ consumes<PixelFEDChannelCollection>(pset.getParameter<edm::InputTag>("InputLabel")) },
83  putToken_{produces<FEDRawDataCollection>()},
84  usePhase1{ pset.getParameter<bool> ("UsePhase1") }
85 {
86 
87 
88  // Define EDProduct type
89 
90  if(usePhase1) edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)";
91 
92 }
93 
94 // -----------------------------------------------------------------------------
95 std::shared_ptr<pr::Cache>
97  edm::EventSetup const& es) const {
98  while(lock_.test_and_set(std::memory_order_acquire)); //spin
99  auto rel = [](std::atomic_flag* f) { f->clear(std::memory_order_release); };
100  std::unique_ptr<std::atomic_flag, decltype(rel)> guard(&lock_, rel);
101 
102  if (recordWatcher.check( es )) {
104  es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
105  previousCache_ = std::make_shared<pr::Cache>();
106  previousCache_->cablingTree_= cablingMap->cablingTree();
107  previousCache_->frameReverter_ = std::make_unique<SiPixelFrameReverter>( es, cablingMap.product() );
108  }
109  return previousCache_;
110 }
111 
112 
113 
114 // -----------------------------------------------------------------------------
116  const edm::EventSetup& es) const
117 {
118  using namespace sipixelobjects;
119 
121  ev.getByToken( tPixelDigi, digiCollection);
122 
125 
126  int digiCounter = 0;
127  for (auto const& di : *digiCollection) {
128  digiCounter += (di.data).size();
129  digis[ di.id] = di.data;
130  }
131 
132  auto cache = luminosityBlockCache(ev.getLuminosityBlock().index());
133 
134 
135  LogDebug("SiPixelDigiToRaw") << cache->cablingTree_->version();
136 
138  edm::Handle<PixelFEDChannelCollection> pixelFEDChannelCollectionHandle;
139  if (usePhase1 && ev.getByToken(theBadPixelFEDChannelsToken, pixelFEDChannelCollectionHandle)){
140  for (auto const& fedChannels: *pixelFEDChannelCollectionHandle) {
141  PixelDataFormatter::DetBadChannels detBadChannels;
142  for(const auto& fedChannel: fedChannels) {
143  sipixelobjects::CablingPathToDetUnit path={fedChannel.fed, fedChannel.link, 1};
144  if (cache->cablingTree_->findItem(path)!=nullptr) {
145  detBadChannels.push_back(fedChannel);
146  } else {
147  edm::LogError("SiPixelDigiToRaw")
148  <<" FED "<<fedChannel.fed<<" Link "<<fedChannel.link<<" for module "<<fedChannels.detId()
149  <<" marked bad, but this channel does not exist in the cabling map" <<endl;
150  }
151  } // channels reading a module
152  if (!detBadChannels.empty()) badChannels.insert({fedChannels.detId(), std::move(detBadChannels)});
153  } // loop on detId-s
154  }
155 
156  //PixelDataFormatter formatter(cablingTree_.get());
157  PixelDataFormatter formatter(cache->cablingTree_.get(), usePhase1);
158 
159  formatter.passFrameReverter(cache->frameReverter_.get());
160 
161  // create product (raw data)
162  FEDRawDataCollection buffers;
163 
164  // convert data to raw
165  formatter.formatRawData( ev.id().event(), rawdata, digis, badChannels);
166 
167  // pack raw data into collection
168  for (auto const* fed: cache->cablingTree_->fedList()) {
169  LogDebug("SiPixelDigiToRaw")<<" PRODUCE DATA FOR FED_id: " << fed->id();
170  FEDRawData& fedRawData = buffers.FEDData( fed->id() );
171  PixelDataFormatter::RawData::iterator fedbuffer = rawdata.find( fed->id() );
172  if( fedbuffer != rawdata.end() ) fedRawData = fedbuffer->second;
173  LogDebug("SiPixelDigiToRaw")<<"size of data in fedRawData: "<<fedRawData.size();
174  }
175 
176  LogDebug("SiPixelDigiToRaw").log([&](auto &l) {
177 
178  l << "Words/Digis this ev: "<<digiCounter<<"(fm:"<<formatter.nDigis()<<")/"
179  <<formatter.nWords();
180  });
181  ev.emplace(putToken_, std::move(buffers));
182 
183 }
184 
185 // -----------------------------------------------------------------------------
188  desc.add<edm::InputTag>("InputLabel");
189  desc.add<bool>("UsePhase1", false);
190  desc.addUntracked<bool>("Timing", false)->setComment("deprecated");
191  descriptions.add("siPixelRawData", desc);
192 }
193 
194 // declare this as a framework plugin
#define LogDebug(id)
size
Write out results.
EventNumber_t event() const
Definition: EventID.h:41
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:517
bool ev
std::unique_ptr< SiPixelFedCablingTree > cablingTree_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
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:97
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:413
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:71
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511