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:
55  //NOTE: these are only changes in the constructor call
59 };
60 
61 /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
62 
64 
65  public edm::stream::EDProducer<edm::GlobalCache<SiPixelStatusCache>,
66  edm::RunCache<SiPixelTopoFinder>,
67  edm::LuminosityBlockSummaryCache<std::vector<SiPixelDetectorStatus>>,
68  edm::EndLuminosityBlockProducer,
69  edm::Accumulator> {
70 public:
72  ~SiPixelStatusProducer() override;
73 
74  /* module description */
75  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
77  {
79  psd0.addUntracked<edm::InputTag>("pixelClusterLabel", edm::InputTag("siPixelClusters", "", "RECO"));
80  psd0.add<std::vector<edm::InputTag>>("badPixelFEDChannelCollections",
81  {
82  edm::InputTag("siPixelDigis"),
83  });
84  desc.add<edm::ParameterSetDescription>("SiPixelStatusProducerParameters", psd0);
85  }
86  descriptions.add("siPixelStatusProducer", desc);
87  }
88 
89  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
90 
91  /* For each instance of the module*/
92  void beginRun(edm::Run const&, edm::EventSetup const&) final;
93 
95  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) final;
96 
97  void accumulate(edm::Event const& iEvent, edm::EventSetup const& iSetup) final;
98 
100  edm::EventSetup const&,
101  std::vector<SiPixelDetectorStatus>* siPixelDetectorStatusVtr) const final; //override;
102 
103  /* For global or runCache */
104 
105  static std::unique_ptr<SiPixelStatusCache> initializeGlobalCache(edm::ParameterSet const& iPSet) {
106  edm::LogInfo("SiPixelStatusProducer") << "Init global Cache " << std::endl;
107  return std::make_unique<SiPixelStatusCache>();
108  }
109 
110  static std::shared_ptr<SiPixelTopoFinder> globalBeginRun(edm::Run const& iRun,
111  edm::EventSetup const& iSetup,
112  GlobalCache const* iCache);
113 
114  static void globalEndRun(edm::Run const& iRun, edm::EventSetup const&, RunContext const* iContext) {
115  /* Do nothing */
116  }
117 
118  static void globalEndJob(SiPixelStatusCache const*) { /* Do nothing */ }
119 
120  static std::shared_ptr<std::vector<SiPixelDetectorStatus>> globalBeginLuminosityBlockSummary(
122  return std::make_shared<std::vector<SiPixelDetectorStatus>>();
123  }
124 
126  edm::EventSetup const&,
127  LuminosityBlockContext const* iContext,
128  std::vector<SiPixelDetectorStatus>*) {
129  /* Do nothing */
130  }
131 
133  edm::EventSetup const&,
134  LuminosityBlockContext const* iContext,
135  std::vector<SiPixelDetectorStatus> const* siPixelDetectorStatusVtr) {
136  edm::LogInfo("SiPixelStatusProducer") << "Global endlumi producer " << std::endl;
137 
138  // only save result for non-zero event lumi block
139  if (!siPixelDetectorStatusVtr->empty()) {
140  int lumi = iLumi.luminosityBlock();
141  int run = iLumi.run();
142 
143  SiPixelDetectorStatus siPixelDetectorStatus = SiPixelDetectorStatus();
144  for (unsigned int instance = 0; instance < siPixelDetectorStatusVtr->size(); instance++) {
145  siPixelDetectorStatus.updateDetectorStatus((*siPixelDetectorStatusVtr)[instance]);
146  }
147 
148  siPixelDetectorStatus.setRunRange(run, run);
149  siPixelDetectorStatus.setLSRange(lumi, lumi);
150 
151  if (debug_) {
152  std::string outTxt = Form("SiPixelDetectorStatus_Run%d_Lumi%d.txt", run, lumi);
153  std::ofstream outFile;
154  outFile.open(outTxt.c_str(), std::ios::app);
155  siPixelDetectorStatus.dumpToFile(outFile);
156  outFile.close();
157  }
158 
159  /* save result */
160  auto result = std::make_unique<SiPixelDetectorStatus>();
161  *result = siPixelDetectorStatus;
162 
163  iLumi.put(std::move(result), std::string("siPixelStatus"));
164  edm::LogInfo("SiPixelStatusProducer")
165  << " lumi-based data stored for run " << run << " lumi " << lumi << std::endl;
166  }
167  }
168 
169 private:
170  virtual int indexROC(int irow, int icol, int nROCcolumns) final;
171 
172  /* ParameterSet */
173  static const bool debug_ = false;
174 
177  std::vector<edm::EDGetTokenT<PixelFEDChannelCollection>> theBadPixelFEDChannelsTokens_;
178 
179  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
180  /* private data member, one instance per stream */
181 
182  /* per-Run data (The pixel topo cannot be changed during a Run) */
183  /* vector of all <int> detIds */
184  std::vector<int> fDetIds_;
185  /* ROC size (number of row, number of columns for each det id) */
186  std::map<int, std::pair<int, int>> fSensors_;
187  /* the roc layout on a module */
188  std::map<int, std::pair<int, int>> fSensorLayout_;
189  /* fedId as a function of detId */
190  std::unordered_map<uint32_t, unsigned int> fFedIds_;
191  /* map the index ROC to rocId */
192  std::map<int, std::map<int, int>> fRocIds_;
193 
194  /* per-LuminosityBlock data */
195  unsigned long int ftotalevents_;
196 
198  int endLumi_;
200  int endRun_;
201 
202  /* Channels always have FEDerror25 for all events in the lumisection */
203  std::map<int, std::vector<PixelFEDChannel>> fFEDerror25_;
204 
205  // Producer production (output collection)
207 };
208 
209 #endif
static void globalEndJob(SiPixelStatusCache const *)
static std::shared_ptr< SiPixelTopoFinder > globalBeginRun(edm::Run const &iRun, edm::EventSetup const &iSetup, GlobalCache const *iCache)
void updateDetectorStatus(SiPixelDetectorStatus newData)
std::map< int, std::pair< int, int > > fSensors_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static void globalEndLuminosityBlockProduce(edm::LuminosityBlock &iLumi, edm::EventSetup const &, LuminosityBlockContext const *iContext, std::vector< SiPixelDetectorStatus > const *siPixelDetectorStatusVtr)
static PFTauRenderPlugin instance
std::vector< int > fDetIds_
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > siPixelFedCablingMapToken_
static std::shared_ptr< std::vector< SiPixelDetectorStatus > > globalBeginLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, LuminosityBlockContext const *)
void dumpToFile(std::ofstream &outFile)
unsigned long int ftotalevents_
std::unordered_map< uint32_t, unsigned int > fFedIds_
int iEvent
Definition: GenABIO.cc:224
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) final
SiPixelDetectorStatus fDet_
std::vector< edm::EDGetTokenT< PixelFEDChannelCollection > > theBadPixelFEDChannelsTokens_
static void globalEndRun(edm::Run const &iRun, edm::EventSetup const &, RunContext const *iContext)
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > fSiPixelClusterToken_
void setLSRange(int ls0, int ls1)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopologyToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
Log< level::Info, false > LogInfo
std::map< int, std::vector< PixelFEDChannel > > fFEDerror25_
static void globalEndLuminosityBlockSummary(edm::LuminosityBlock const &, edm::EventSetup const &, LuminosityBlockContext const *iContext, std::vector< SiPixelDetectorStatus > *)
static std::unique_ptr< SiPixelStatusCache > initializeGlobalCache(edm::ParameterSet const &iPSet)
std::map< int, std::pair< int, int > > fSensorLayout_
void accumulate(edm::Event const &iEvent, edm::EventSetup const &iSetup) final
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void setRunRange(int run0, int run1)
SiPixelStatusProducer(edm::ParameterSet const &iPSet, SiPixelStatusCache const *)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginRun(edm::Run const &, edm::EventSetup const &) final
void endLuminosityBlockSummary(edm::LuminosityBlock const &iLumi, edm::EventSetup const &, std::vector< SiPixelDetectorStatus > *siPixelDetectorStatusVtr) const final
std::map< int, std::map< int, int > > fRocIds_
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) final
virtual int indexROC(int irow, int icol, int nROCcolumns) final
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45