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 
33 #include <atomic>
34 #include <memory>
35 
36 namespace sipixeldigitoraw {
37  struct Cache {
38  std::unique_ptr<SiPixelFedCablingTree> cablingTree_;
39  std::unique_ptr<SiPixelFrameReverter> frameReverter_;
40  };
41 }
42 
43 namespace pr = sipixeldigitoraw;
44 
45 class SiPixelDigiToRaw final : public edm::global::EDProducer<edm::LuminosityBlockCache<pr::Cache>> {
46 public:
47 
49  explicit SiPixelDigiToRaw( const edm::ParameterSet& );
50 
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 
59  edm::EventSetup const& iES) const final {}
60 
61  // Fill parameters descriptions
62  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
63 
64 private:
65 
66  mutable std::atomic_flag lock_{ ATOMIC_FLAG_INIT };
67  CMS_THREAD_GUARD(lock_) mutable edm::ESWatcher<SiPixelFedCablingMapRcd> recordWatcher;
68  CMS_THREAD_GUARD(lock_) mutable std::shared_ptr<pr::Cache> previousCache_;
69  const edm::EDGetTokenT<edm::DetSetVector<PixelDigi>> tPixelDigi;
70  const edm::EDPutTokenT<FEDRawDataCollection> putToken_;
71  const bool usePilotBlade = false; // I am not yet sure we need it here?
72  const bool usePhase1;
73 };
74 
75 using namespace std;
76 
78  tPixelDigi{ consumes<edm::DetSetVector<PixelDigi> >(pset.getParameter<edm::InputTag>("InputLabel")) },
79  putToken_{produces<FEDRawDataCollection>()},
80  usePhase1{ pset.getParameter<bool> ("UsePhase1") }
81 {
82 
83 
84  // Define EDProduct type
85 
86  if(usePhase1) edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)";
87 
88 }
89 
90 // -----------------------------------------------------------------------------
91 std::shared_ptr<pr::Cache>
93  edm::EventSetup const& es) const {
94  while(lock_.test_and_set(std::memory_order_acquire)); //spin
95  auto rel = [](std::atomic_flag* f) { f->clear(std::memory_order_release); };
96  std::unique_ptr<std::atomic_flag, decltype(rel)> guard(&lock_, rel);
97 
98  if (recordWatcher.check( es )) {
100  es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
101  previousCache_ = std::make_shared<pr::Cache>();
102  previousCache_->cablingTree_= cablingMap->cablingTree();
103  previousCache_->frameReverter_ = std::make_unique<SiPixelFrameReverter>( es, cablingMap.product() );
104  }
105  return previousCache_;
106 }
107 
108 
109 
110 // -----------------------------------------------------------------------------
112  const edm::EventSetup& es) const
113 {
114  using namespace sipixelobjects;
115 
117  ev.getByToken( tPixelDigi, digiCollection);
118 
121 
122  int digiCounter = 0;
123  for (auto const& di : *digiCollection) {
124  digiCounter += (di.data).size();
125  digis[ di.id] = di.data;
126  }
127 
128  auto cache = luminosityBlockCache(ev.getLuminosityBlock().index());
129 
130 
131  LogDebug("SiPixelDigiToRaw") << cache->cablingTree_->version();
132 
133  //PixelDataFormatter formatter(cablingTree_.get());
134  PixelDataFormatter formatter(cache->cablingTree_.get(), usePhase1);
135 
136  formatter.passFrameReverter(cache->frameReverter_.get());
137 
138  // create product (raw data)
139  FEDRawDataCollection buffers;
140 
141  // convert data to raw
142  formatter.formatRawData( ev.id().event(), rawdata, digis );
143 
144  // pack raw data into collection
145  for (auto const* fed: cache->cablingTree_->fedList()) {
146  LogDebug("SiPixelDigiToRaw")<<" PRODUCE DATA FOR FED_id: " << fed->id();
147  FEDRawData& fedRawData = buffers.FEDData( fed->id() );
148  PixelDataFormatter::RawData::iterator fedbuffer = rawdata.find( fed->id() );
149  if( fedbuffer != rawdata.end() ) fedRawData = fedbuffer->second;
150  LogDebug("SiPixelDigiToRaw")<<"size of data in fedRawData: "<<fedRawData.size();
151  }
152 
153  LogDebug("SiPixelDigiToRaw").log([&](auto &l) {
154 
155  l << "Words/Digis this ev: "<<digiCounter<<"(fm:"<<formatter.nDigis()<<")/"
156  <<formatter.nWords();
157  });
158  ev.emplace(putToken_, std::move(buffers));
159 
160 }
161 
162 // -----------------------------------------------------------------------------
165  desc.add<edm::InputTag>("InputLabel");
166  desc.add<bool>("UsePhase1", false);
167  desc.addUntracked<bool>("Timing", false)->setComment("deprecated");
168  descriptions.add("siPixelRawData", desc);
169 }
170 
171 // 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:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
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:101
std::shared_ptr< pr::Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &iES) const final
ParameterDescriptionBase * add(U const &iLabel, T const &value)
def cache(function)
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:453
std::map< int, FEDRawData > RawData
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
T get() const
Definition: EventSetup.h:68
T const * product() const
Definition: ESHandle.h:84
def move(src, dest)
Definition: eostools.py:511