CMS 3D CMS Logo

SiPixelStatusProducer.h
Go to the documentation of this file.
1 #ifndef CalibTracker_SiPixelQuality_SiPixelStatusProducer_h
2 #define CalibTracker_SiPixelQuality_SiPixelStatusProducer_h
3 
10 // C++ standard
11 #include <cstring>
12 #include <fstream>
13 #include <iostream>
14 #include <memory>
15 
16 #include <string>
17 // // CMS FW
27 // Concurrency
30 
34 
35 // // Pixel data format
42 // Tracker Geo
47 // SiPixelTopoFinder
49 // SiPixelDetectorStatus
51 
52 /* Cache to pertain SiPixelTopoFinder */
54 public:
56 
57  std::shared_ptr<SiPixelTopoFinder> getSiPixelTopoFinder(edm::EventSetup const& iSetup) const {
58  std::shared_ptr<SiPixelTopoFinder> returnValue;
59 
60  m_queue.pushAndWait([&]() {
61  if (!this->siPixelFedCablingMapWatcher_.check(iSetup) && !this->trackerDIGIGeoWatcher_.check(iSetup) &&
62  !this->trackerTopoWatcher_.check(iSetup)) {
63  /*the condition hasn't changed so we can just use our old value*/
64  returnValue = m_mostRecentSiPixelTopoFinder_;
65  } else {
67  iSetup.get<TrackerDigiGeometryRecord>().get(tkGeoHandle);
68  const TrackerGeometry* trackerGeometry = tkGeoHandle.product();
69 
70  edm::ESHandle<TrackerTopology> tkTopoHandle;
71  iSetup.get<TrackerTopologyRcd>().get(tkTopoHandle);
72  const TrackerTopology* trackerTopology = tkTopoHandle.product();
73 
75  iSetup.get<SiPixelFedCablingMapRcd>().get(cMapHandle);
76  const SiPixelFedCablingMap* cablingMap = cMapHandle.product();
77 
78  /*the condition has changed so we need to update*/
79  //const TrackerGeometry* trackerGeometry = &iSetup.getData(trackerGeometryToken);
80  //const TrackerTopology* trackerTopology = &iSetup.getData(trackerTopologyToken);
81  //const SiPixelFedCablingMap* cablingMap = &iSetup.getData(siPixelFedCablingMapToken);
82 
83  returnValue = m_holder.makeOrGet([]() { return new SiPixelTopoFinder(); });
84  returnValue->init(trackerGeometry, trackerTopology, cablingMap);
85 
86  m_mostRecentSiPixelTopoFinder_ = returnValue;
87  }
88  }); //m_queue
89 
90  return returnValue;
91  }
92 
93 private:
96 
97  /* Condition watchers */
98  /* CablingMaps */
100  /* TrackerDIGIGeo */
102  /* TrackerTopology */
104 
105  /* SiPixelTopoFinder */
106  mutable std::shared_ptr<SiPixelTopoFinder> m_mostRecentSiPixelTopoFinder_;
107 };
108 
109 /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
110 
112 
113  public edm::stream::EDProducer<edm::GlobalCache<SiPixelTopoCache>,
114  edm::RunCache<SiPixelTopoFinder>,
115  edm::LuminosityBlockSummaryCache<std::vector<SiPixelDetectorStatus>>,
116  edm::EndLuminosityBlockProducer,
117  edm::Accumulator> {
118 public:
120  ~SiPixelStatusProducer() override;
121 
122  /* module description */
125  {
127  psd0.addUntracked<edm::InputTag>("pixelClusterLabel", edm::InputTag("siPixelClusters", "", "RECO"));
128  psd0.add<std::vector<edm::InputTag>>("badPixelFEDChannelCollections",
129  {
130  edm::InputTag("siPixelDigis"),
131  });
132  desc.add<edm::ParameterSetDescription>("SiPixelStatusProducerParameters", psd0);
133  }
134  descriptions.add("siPixelStatusProducer", desc);
135  }
136 
137  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
138 
139  /* For each instance of the module*/
140  void beginRun(edm::Run const&, edm::EventSetup const&) final;
141 
142  void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) final;
143  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) final;
144 
145  void accumulate(edm::Event const& iEvent, edm::EventSetup const& iSetup) final;
146 
148  edm::EventSetup const&,
149  std::vector<SiPixelDetectorStatus>* siPixelDetectorStatusVtr) const final; //override;
150 
151  /* For global or runCache */
152 
153  static std::unique_ptr<SiPixelTopoCache> initializeGlobalCache(edm::ParameterSet const& iPSet) {
154  edm::LogInfo("SiPixelStatusProducer") << "Init global Cache " << std::endl;
155  return std::make_unique<SiPixelTopoCache>(iPSet);
156  }
157 
158  static std::shared_ptr<SiPixelTopoFinder> globalBeginRun(edm::Run const& iRun,
159  edm::EventSetup const& iSetup,
160  GlobalCache const* iCache) {
161  edm::LogInfo("SiPixelStatusProducer") << "Global beginRun " << std::endl;
162  return iCache->getSiPixelTopoFinder(iSetup);
163  }
164 
165  static void globalEndRun(edm::Run const& iRun, edm::EventSetup const&, RunContext const* iContext) {
166  /* Do nothing */
167  }
168 
169  static void globalEndJob(SiPixelTopoCache const*) { /* Do nothing */
170  }
171 
172  static std::shared_ptr<std::vector<SiPixelDetectorStatus>> globalBeginLuminosityBlockSummary(
174  return std::make_shared<std::vector<SiPixelDetectorStatus>>();
175  }
176 
178  edm::EventSetup const&,
179  LuminosityBlockContext const* iContext,
180  std::vector<SiPixelDetectorStatus>*) {
181  /* Do nothing */
182  }
183 
185  edm::EventSetup const&,
186  LuminosityBlockContext const* iContext,
187  std::vector<SiPixelDetectorStatus> const* siPixelDetectorStatusVtr) {
188  edm::LogInfo("SiPixelStatusProducer") << "Global endlumi producer " << std::endl;
189 
190  // only save result for non-zero event lumi block
191  if (!siPixelDetectorStatusVtr->empty()) {
192  int lumi = iLumi.luminosityBlock();
193  int run = iLumi.run();
194 
195  SiPixelDetectorStatus siPixelDetectorStatus = SiPixelDetectorStatus();
196  for (unsigned int instance = 0; instance < siPixelDetectorStatusVtr->size(); instance++) {
197  siPixelDetectorStatus.updateDetectorStatus((*siPixelDetectorStatusVtr)[instance]);
198  }
199 
200  siPixelDetectorStatus.setRunRange(run, run);
201  siPixelDetectorStatus.setLSRange(lumi, lumi);
202 
203  if (debug_) {
204  std::string outTxt = Form("SiPixelDetectorStatus_Run%d_Lumi%d.txt", run, lumi);
205  std::ofstream outFile;
206  outFile.open(outTxt.c_str(), std::ios::app);
207  siPixelDetectorStatus.dumpToFile(outFile);
208  outFile.close();
209  }
210 
211  /* save result */
212  auto result = std::make_unique<SiPixelDetectorStatus>();
213  *result = siPixelDetectorStatus;
214 
215  iLumi.put(std::move(result), std::string("siPixelStatus"));
216  edm::LogInfo("SiPixelStatusProducer")
217  << " lumi-based data stored for run " << run << " lumi " << lumi << std::endl;
218  }
219  }
220 
221 private:
222  virtual int indexROC(int irow, int icol, int nROCcolumns) final;
223 
224  /* ParameterSet */
225  static const bool debug_ = false;
226 
229  std::vector<edm::EDGetTokenT<PixelFEDChannelCollection>> theBadPixelFEDChannelsTokens_;
230 
231  /*
232  edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeometryToken_;
233  edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopologyToken_;
234  edm::ESGetToken<SiPixelFedCablingMap, SiPixelFedCablingMapRcd> siPixelFedCablingMapToken_;
235  */
236 
237  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
238  /* private data member, one instance per stream */
239 
240  /* per-Run data (The pixel topo cannot be changed during a Run) */
241  /* vector of all <int> detIds */
242  std::vector<int> fDetIds_;
243  /* ROC size (number of row, number of columns for each det id) */
244  std::map<int, std::pair<int, int>> fSensors_;
245  /* the roc layout on a module */
246  std::map<int, std::pair<int, int>> fSensorLayout_;
247  /* fedId as a function of detId */
248  std::unordered_map<uint32_t, unsigned int> fFedIds_;
249  /* map the index ROC to rocId */
250  std::map<int, std::map<int, int>> fRocIds_;
251 
252  /* per-LuminosityBlock data */
253  unsigned long int ftotalevents_;
254 
256  int endLumi_;
258  int endRun_;
259 
260  /* Channels always have FEDerror25 for all events in the lumisection */
261  std::map<int, std::vector<PixelFEDChannel>> fFEDerror25_;
262 
263  // Producer production (output collection)
265 };
266 
267 #endif
ConfigurationDescriptions.h
SiPixelStatusProducer::fFEDerror25_
std::map< int, std::vector< PixelFEDChannel > > fFEDerror25_
Definition: SiPixelStatusProducer.h:261
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
SiPixelStatusProducer::ftotalevents_
unsigned long int ftotalevents_
Definition: SiPixelStatusProducer.h:253
SiPixelTopoCache
Definition: SiPixelStatusProducer.h:53
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
SiPixelTopoFinder.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
SiPixelTopoCache::trackerTopoWatcher_
edm::ESWatcher< TrackerTopologyRcd > trackerTopoWatcher_
Definition: SiPixelStatusProducer.h:103
TrackerGeometry.h
edm::ESWatcher< SiPixelFedCablingMapRcd >
SiPixelStatusProducer::theBadPixelFEDChannelsTokens_
std::vector< edm::EDGetTokenT< PixelFEDChannelCollection > > theBadPixelFEDChannelsTokens_
Definition: SiPixelStatusProducer.h:229
SiPixelStatusProducer::fSensors_
std::map< int, std::pair< int, int > > fSensors_
Definition: SiPixelStatusProducer.h:244
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
SiPixelStatusProducer
Definition: SiPixelStatusProducer.h:111
SiPixelStatusProducer::fSensorLayout_
std::map< int, std::pair< int, int > > fSensorLayout_
Definition: SiPixelStatusProducer.h:246
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
SiPixelStatusProducer::globalBeginLuminosityBlockSummary
static std::shared_ptr< std::vector< SiPixelDetectorStatus > > globalBeginLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, LuminosityBlockContext const *)
Definition: SiPixelStatusProducer.h:172
SiPixelTopoCache::m_holder
edm::ReusableObjectHolder< SiPixelTopoFinder > m_holder
Definition: SiPixelStatusProducer.h:94
LuminosityBlock.h
TrackerTopology
Definition: TrackerTopology.h:16
SiPixelStatusProducer::globalEndLuminosityBlockSummary
static void globalEndLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, LuminosityBlockContext const *iContext, std::vector< SiPixelDetectorStatus > *)
Definition: SiPixelStatusProducer.h:177
SiPixelTopoCache::siPixelFedCablingMapWatcher_
edm::ESWatcher< SiPixelFedCablingMapRcd > siPixelFedCablingMapWatcher_
Definition: SiPixelStatusProducer.h:99
PixelFEDChannel.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
SiPixelStatusProducer::fSiPixelClusterToken_
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > fSiPixelClusterToken_
Definition: SiPixelStatusProducer.h:228
SiPixelStatusProducer::globalEndLuminosityBlockProduce
static void globalEndLuminosityBlockProduce(edm::LuminosityBlock &iLumi, edm::EventSetup const &, LuminosityBlockContext const *iContext, std::vector< SiPixelDetectorStatus > const *siPixelDetectorStatusVtr)
Definition: SiPixelStatusProducer.h:184
SiPixelTopoCache::getSiPixelTopoFinder
std::shared_ptr< SiPixelTopoFinder > getSiPixelTopoFinder(edm::EventSetup const &iSetup) const
Definition: SiPixelStatusProducer.h:57
SiPixelStatusProducer::SiPixelStatusProducer
SiPixelStatusProducer(edm::ParameterSet const &iPSet, SiPixelTopoCache const *)
Definition: SiPixelStatusProducer.cc:30
EDProducer.h
SiPixelFedCablingMap.h
edm::SerialTaskQueue
Definition: SerialTaskQueue.h:67
SiPixelStatusProducer::endLumi_
int endLumi_
Definition: SiPixelStatusProducer.h:256
SiPixelStatusProducer::globalEndRun
static void globalEndRun(edm::Run const &iRun, edm::EventSetup const &, RunContext const *iContext)
Definition: SiPixelStatusProducer.h:165
SiPixelStatusProducer::globalBeginRun
static std::shared_ptr< SiPixelTopoFinder > globalBeginRun(edm::Run const &iRun, edm::EventSetup const &iSetup, GlobalCache const *iCache)
Definition: SiPixelStatusProducer.h:158
SiPixelDetectorStatus::setLSRange
void setLSRange(int ls0, int ls1)
Definition: SiPixelDetectorStatus.h:63
edm::LuminosityBlockBase::run
RunNumber_t run() const
Definition: LuminosityBlockBase.h:42
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
ESGetToken.h
SiPixelStatusProducer::fDetIds_
std::vector< int > fDetIds_
Definition: SiPixelStatusProducer.h:242
edm::stream::EDProducer< edm::GlobalCache< SiPixelTopoCache >, edm::RunCache< SiPixelTopoFinder >, edm::LuminosityBlockSummaryCache< std::vector< SiPixelDetectorStatus > >, edm::EndLuminosityBlockProducer, edm::Accumulator >::GlobalCache
CacheTypes::GlobalCache GlobalCache
Definition: EDProducer.h:45
edm::stream::RunContextT
Definition: Contexts.h:31
SiPixelStatusProducer::endLuminosityBlockSummary
void endLuminosityBlockSummary(edm::LuminosityBlock const &iLumi, edm::EventSetup const &, std::vector< SiPixelDetectorStatus > *siPixelDetectorStatusVtr) const final
Definition: SiPixelStatusProducer.cc:257
SiPixelStatusProducer::fRocIds_
std::map< int, std::map< int, int > > fRocIds_
Definition: SiPixelStatusProducer.h:250
SiPixelDetectorStatus
Definition: SiPixelDetectorStatus.h:11
SiPixelDetectorStatus::dumpToFile
void dumpToFile(std::ofstream &outFile)
Definition: SiPixelDetectorStatus.cc:85
edm::ReusableObjectHolder< SiPixelTopoFinder >
edm::ReusableObjectHolder::makeOrGet
std::shared_ptr< T > makeOrGet(F iFunc)
If there isn't an object already available, creates a new one using iFunc.
Definition: ReusableObjectHolder.h:126
TrackerTopology.h
SiPixelStatusProducer::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) final
Definition: SiPixelStatusProducer.cc:236
ReusableObjectHolder.h
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
SerialTaskQueue.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
SiPixelStatusProducer::fFedIds_
std::unordered_map< uint32_t, unsigned int > fFedIds_
Definition: SiPixelStatusProducer.h:248
edm::LuminosityBlockBase::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockBase.h:40
SiPixelStatusProducer::debug_
static const bool debug_
Definition: SiPixelStatusProducer.h:225
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
edm::ESHandle< TrackerGeometry >
SiPixelStatusProducer::accumulate
void accumulate(edm::Event const &iEvent, edm::EventSetup const &iSetup) final
Definition: SiPixelStatusProducer.cc:87
SiPixelTopoCache::m_mostRecentSiPixelTopoFinder_
std::shared_ptr< SiPixelTopoFinder > m_mostRecentSiPixelTopoFinder_
Definition: SiPixelStatusProducer.h:106
Transition.h
SiPixelStatusProducer::beginRun_
int beginRun_
Definition: SiPixelStatusProducer.h:257
SiPixelTopoFinder
Definition: SiPixelTopoFinder.h:16
SiPixelStatusProducer::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) final
Definition: SiPixelStatusProducer.cc:53
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
L1TdeCSCTF_cfi.outFile
outFile
Definition: L1TdeCSCTF_cfi.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
TrackerDigiGeometryRecord.h
edm::SerialTaskQueue::pushAndWait
void pushAndWait(const T &iAction)
synchronously pushes functor iAction into queue
Definition: SerialTaskQueue.h:194
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
SiPixelFedCablingMapRcd.h
SiPixelStatusProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SiPixelStatusProducer.h:123
iEvent
int iEvent
Definition: GenABIO.cc:224
SiPixelStatusProducer::~SiPixelStatusProducer
~SiPixelStatusProducer() override
Definition: SiPixelStatusProducer.cc:49
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
SiPixelStatusProducer::endRun_
int endRun_
Definition: SiPixelStatusProducer.h:258
get
#define get
edm::LuminosityBlock::put
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: LuminosityBlock.h:116
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
edm::stream::LuminosityBlockContextT
Definition: Contexts.h:43
SiPixelFedCablingMap
Definition: SiPixelFedCablingMap.h:19
SiPixelTopoCache::SiPixelTopoCache
SiPixelTopoCache(edm::ParameterSet const &iPSet)
Definition: SiPixelStatusProducer.h:55
SiPixelTopoCache::trackerDIGIGeoWatcher_
edm::ESWatcher< TrackerDigiGeometryRecord > trackerDIGIGeoWatcher_
Definition: SiPixelStatusProducer.h:101
SiPixelDetectorStatus::updateDetectorStatus
void updateDetectorStatus(SiPixelDetectorStatus newData)
Definition: SiPixelDetectorStatus.cc:207
SiPixelDetectorStatus.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
SiPixelStatusProducer::fPixelClusterLabel_
edm::InputTag fPixelClusterLabel_
Definition: SiPixelStatusProducer.h:227
SiPixelStatusProducer::beginLumi_
int beginLumi_
Definition: SiPixelStatusProducer.h:255
DetId.h
Frameworkfwd.h
ESWatcher.h
SiPixelStatusProducer::globalEndJob
static void globalEndJob(SiPixelTopoCache const *)
Definition: SiPixelStatusProducer.h:169
SiPixelStatusProducer::initializeGlobalCache
static std::unique_ptr< SiPixelTopoCache > initializeGlobalCache(edm::ParameterSet const &iPSet)
Definition: SiPixelStatusProducer.h:153
SiPixelStatusProducer::indexROC
virtual int indexROC(int irow, int icol, int nROCcolumns) final
Definition: SiPixelStatusProducer.cc:269
EventSetup.h
SiPixelDetectorStatus::setRunRange
void setRunRange(int run0, int run1)
Definition: SiPixelDetectorStatus.h:57
SiPixelTopoCache::m_queue
edm::SerialTaskQueue m_queue
Definition: SiPixelStatusProducer.h:95
mps_fire.result
result
Definition: mps_fire.py:311
ConsumesCollector.h
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
SiPixelStatusProducer::fDet_
SiPixelDetectorStatus fDet_
Definition: SiPixelStatusProducer.h:264
ParameterSet.h
SiPixelFedCablingMapRcd
Definition: SiPixelFedCablingMapRcd.h:5
edm::Event
Definition: Event.h:73
lumi
Definition: LumiSectionData.h:20
SiPixelStatusProducer::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) final
Definition: SiPixelStatusProducer.cc:71
DetSetVectorNew.h
edm::InputTag
Definition: InputTag.h:15
TrackerGeometry
Definition: TrackerGeometry.h:14