Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-17 01:40:50

0001 // -*- C++ -*-
0002 //
0003 // Package:    InsertNoisyPixelsInDB
0004 // Class:      InsertNoisyPixelsInDB
0005 //
0006 /**\class InsertNoisyPixelsInDB InsertNoisyPixelsInDB.cc CondTools/InsertNoisyPixelsInDB/src/InsertNoisyPixelsInDB.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Romain Rougny
0015 //         Created:  Tue Feb  3 15:18:02 CET 2009
0016 // $Id: SiPixelGainCalibrationRejectNoisyAndDead.cc,v 1.5 2009/10/21 15:53:42 heyburn Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <fstream>
0022 #include <map>
0023 #include <memory>
0024 #include <sys/stat.h>
0025 #include <utility>
0026 #include <vector>
0027 
0028 // user include files
0029 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationForHLTService.h"
0030 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineService.h"
0031 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationService.h"
0032 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationServiceBase.h"
0033 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0034 #include "CondFormats/SiPixelObjects/interface/SiPixelCalibConfiguration.h"
0035 #include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibration.h"
0036 #include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationForHLT.h"
0037 #include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationOffline.h"
0038 #include "FWCore/Framework/interface/Event.h"
0039 #include "FWCore/Framework/interface/Frameworkfwd.h"
0040 #include "FWCore/Framework/interface/MakerMacros.h"
0041 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0042 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0043 #include "FWCore/ServiceRegistry/interface/Service.h"
0044 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0045 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0046 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0047 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0048 
0049 // ROOT includes
0050 #include "TH2F.h"
0051 #include "TFile.h"
0052 #include "TDirectory.h"
0053 #include "TKey.h"
0054 #include "TString.h"
0055 #include "TList.h"
0056 
0057 class SiPixelGainCalibrationRejectNoisyAndDead : public edm::one::EDAnalyzer<> {
0058 public:
0059   explicit SiPixelGainCalibrationRejectNoisyAndDead(const edm::ParameterSet&);
0060   ~SiPixelGainCalibrationRejectNoisyAndDead() override;
0061 
0062 private:
0063   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> pddToken_;
0064   SiPixelGainCalibrationOfflineService SiPixelGainCalibrationOfflineService_;
0065   std::unique_ptr<SiPixelGainCalibrationOffline> theGainCalibrationDbInputOffline_;
0066 
0067   SiPixelGainCalibrationForHLTService SiPixelGainCalibrationForHLTService_;
0068   std::unique_ptr<SiPixelGainCalibrationForHLT> theGainCalibrationDbInputForHLT_;
0069 
0070   void analyze(const edm::Event&, const edm::EventSetup&) override;
0071 
0072   std::map<int, std::vector<std::pair<int, int> > > noisypixelkeeper;
0073   std::map<int, std::vector<std::pair<int, int> > > insertednoisypixel;
0074   int nnoisyininput;
0075 
0076   void fillDatabase(const edm::EventSetup&);
0077   void getNoisyPixels();
0078 
0079   // ----------member data ---------------------------
0080   const std::string noisypixellist_;
0081   const int insertnoisypixelsindb_;
0082   const std::string record_;
0083   const bool DEBUG;
0084   float pedlow_;
0085   float pedhi_;
0086   float gainlow_;
0087   float gainhi_;
0088 };
0089 
0090 using namespace edm;
0091 using namespace std;
0092 
0093 SiPixelGainCalibrationRejectNoisyAndDead::SiPixelGainCalibrationRejectNoisyAndDead(const edm::ParameterSet& iConfig)
0094     : pddToken_(esConsumes()),
0095       SiPixelGainCalibrationOfflineService_(iConfig, consumesCollector()),
0096       SiPixelGainCalibrationForHLTService_(iConfig, consumesCollector()),
0097       noisypixellist_(iConfig.getUntrackedParameter<std::string>("noisyPixelList", "noisypixel.txt")),
0098       insertnoisypixelsindb_(iConfig.getUntrackedParameter<int>("insertNoisyPixelsInDB", 1)),
0099       record_(iConfig.getUntrackedParameter<std::string>("record", "SiPixelGainCalibrationOfflineRcd")),
0100       DEBUG(iConfig.getUntrackedParameter<bool>("debug", false)) {
0101   //now do what ever initialization is needed
0102 }
0103 
0104 SiPixelGainCalibrationRejectNoisyAndDead::~SiPixelGainCalibrationRejectNoisyAndDead() = default;
0105 
0106 // ------------ method called to for each event  ------------
0107 void SiPixelGainCalibrationRejectNoisyAndDead::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0108   if (insertnoisypixelsindb_ != 0)
0109     getNoisyPixels();
0110   fillDatabase(iSetup);
0111 }
0112 
0113 void SiPixelGainCalibrationRejectNoisyAndDead::fillDatabase(const edm::EventSetup& iSetup) {
0114   if (DEBUG)
0115     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0116         << "=>=>=>=> Starting the function fillDatabase()" << endl;
0117 
0118   if (record_ != "SiPixelGainCalibrationOfflineRcd" && record_ != "SiPixelGainCalibrationForHLTRcd") {
0119     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0120         << record_ << " : this record  can't be used !" << std::endl;
0121     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0122         << "Please select SiPixelGainCalibrationForHLTRcd or SiPixelGainCalibrationOfflineRcd" << std::endl;
0123     return;
0124   }
0125 
0126   //Get the Calibration Data
0127   if (record_ == "SiPixelGainCalibrationOfflineRcd")
0128     SiPixelGainCalibrationOfflineService_.setESObjects(iSetup);
0129   if (record_ == "SiPixelGainCalibrationForHLTRcd")
0130     SiPixelGainCalibrationForHLTService_.setESObjects(iSetup);
0131 
0132   //Get list of ideal detids
0133   const TrackerGeometry* pDD = &iSetup.getData(pddToken_);
0134   edm::LogInfo("SiPixelCondObjOfflineBuilder") << " There are " << pDD->dets().size() << " detectors" << std::endl;
0135 
0136   if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0137     pedlow_ = SiPixelGainCalibrationOfflineService_.getPedLow();
0138     pedhi_ = SiPixelGainCalibrationOfflineService_.getPedHigh();
0139     gainlow_ = SiPixelGainCalibrationOfflineService_.getGainLow();
0140     gainhi_ = SiPixelGainCalibrationOfflineService_.getGainHigh();
0141   } else if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0142     pedlow_ = SiPixelGainCalibrationForHLTService_.getPedLow();
0143     pedhi_ = SiPixelGainCalibrationForHLTService_.getPedHigh();
0144     gainlow_ = SiPixelGainCalibrationForHLTService_.getGainLow();
0145     gainhi_ = SiPixelGainCalibrationForHLTService_.getGainHigh();
0146   }
0147   if (gainlow_ < 0)
0148     gainlow_ = 0;
0149   if (gainhi_ > 21)
0150     gainhi_ = 21;
0151   if (pedlow_ < -100)
0152     pedlow_ = -100;
0153   if (pedhi_ > 300)
0154     pedhi_ = 300;
0155 
0156   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0157       << "New payload will have pedlow,hi " << pedlow_ << "," << pedhi_ << " and gainlow,hi " << gainlow_ << ","
0158       << gainhi_ << endl;
0159   if (record_ == "SiPixelGainCalibrationOfflineRcd")
0160     theGainCalibrationDbInputOffline_ =
0161         std::make_unique<SiPixelGainCalibrationOffline>(pedlow_, pedhi_, gainlow_, gainhi_);
0162   if (record_ == "SiPixelGainCalibrationForHLTRcd")
0163     theGainCalibrationDbInputForHLT_ =
0164         std::make_unique<SiPixelGainCalibrationForHLT>(pedlow_, pedhi_, gainlow_, gainhi_);
0165 
0166   int nnoisy = 0;
0167   int ndead = 0;
0168 
0169   int detid = 0;
0170   int NDetid = 0;
0171 
0172   //checking for noisy pixels that won't be inserted ...
0173   bool willNoisyPixBeInserted;
0174   for (std::map<int, std::vector<std::pair<int, int> > >::const_iterator it = noisypixelkeeper.begin();
0175        it != noisypixelkeeper.end();
0176        it++) {
0177     willNoisyPixBeInserted = false;
0178     for (TrackerGeometry::DetContainer::const_iterator mod = pDD->dets().begin(); mod != pDD->dets().end(); mod++) {
0179       detid = 0;
0180       if (dynamic_cast<PixelGeomDetUnit const*>((*mod)) != nullptr)
0181         detid = ((*mod)->geographicalId()).rawId();
0182       if (detid == it->first) {
0183         willNoisyPixBeInserted = true;
0184         break;
0185       }
0186     }
0187     if (!willNoisyPixBeInserted)
0188       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0189           << "All Noisy Pixels in detid " << it->first
0190           << "won't be inserted, check the TrackerGeometry you are using !! You are missing some modules" << endl;
0191   }
0192 
0193   if (DEBUG)
0194     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Starting Loop over all modules" << endl;
0195 
0196   //Looping over all modules
0197   for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++) {
0198     detid = 0;
0199     if (dynamic_cast<PixelGeomDetUnit const*>((*it)) != nullptr)
0200       detid = ((*it)->geographicalId()).rawId();
0201     if (detid == 0)
0202       continue;
0203     NDetid++;
0204     //edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")<<NDetid<<"  "<<detid<<endl;
0205     //if(NDetid==164) continue;
0206 
0207     if (DEBUG)
0208       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> We are in module " << detid << endl;
0209 
0210     // Get the module sizes
0211     const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>((*it));
0212     const PixelTopology& topol = pixDet->specificTopology();
0213     int nrows = topol.nrows();     // rows in x
0214     int ncols = topol.ncolumns();  // cols in y
0215 
0216     float ped;
0217     float gainforthiscol[2];
0218     float pedforthiscol[2];
0219     int nusedrows[2];
0220     int nrowsrocsplit;
0221     if (record_ == "SiPixelGainCalibrationOfflineRcd")
0222       nrowsrocsplit = theGainCalibrationDbInputOffline_->getNumberOfRowsToAverageOver();
0223     if (record_ == "SiPixelGainCalibrationForHLTRcd")
0224       nrowsrocsplit = theGainCalibrationDbInputForHLT_->getNumberOfRowsToAverageOver();
0225 
0226     std::vector<char> theSiPixelGainCalibrationGainPerColPedPerPixel;
0227     std::vector<char> theSiPixelGainCalibrationPerCol;
0228 
0229     if (DEBUG)
0230       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Starting Loop for each rows/cols " << endl;
0231 
0232     for (int icol = 0; icol <= ncols - 1; icol++) {
0233       if (DEBUG)
0234         edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Starting a new column" << endl;
0235 
0236       nusedrows[0] = nusedrows[1] = 0;
0237       gainforthiscol[0] = gainforthiscol[1] = 0;
0238       pedforthiscol[0] = pedforthiscol[1] = 0;
0239 
0240       for (int jrow = 0; jrow <= nrows - 1; jrow++) {
0241         if (DEBUG)
0242           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0243               << "=>=>=>=> We are in col,row " << icol << "," << jrow << endl;
0244 
0245         ped = 0;
0246 
0247         size_t iglobalrow = 0;
0248         int noisyPixInRow = 0;
0249         if (jrow > nrowsrocsplit) {
0250           iglobalrow = 1;
0251           noisyPixInRow = 0;
0252         }
0253 
0254         bool isPixelDeadOld = false;
0255         bool isColumnDeadOld = false;
0256         //  bool isPixelDeadNew = false;
0257         //  bool isColumnDeadNew = false;
0258 
0259         bool isPixelNoisyOld = false;
0260         bool isColumnNoisyOld = false;
0261         bool isPixelNoisyNew = false;
0262         bool isColumnNoisyNew = false;
0263 
0264         bool isColumnDead = false;
0265         bool isColumnNoisy = false;
0266         bool isPixelDead = false;
0267         bool isPixelNoisy = false;
0268 
0269         if (DEBUG)
0270           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Trying to get gain/ped " << endl;
0271 
0272         try {
0273           if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0274             isPixelDeadOld = SiPixelGainCalibrationOfflineService_.isDead(detid, icol, jrow);
0275             isPixelNoisyOld = SiPixelGainCalibrationOfflineService_.isNoisy(detid, icol, jrow);
0276             isColumnDeadOld = SiPixelGainCalibrationOfflineService_.isNoisyColumn(detid, icol, jrow);
0277             isColumnNoisyOld = SiPixelGainCalibrationOfflineService_.isDeadColumn(detid, icol, jrow);
0278           }
0279           if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0280             isColumnDeadOld = SiPixelGainCalibrationForHLTService_.isNoisyColumn(detid, icol, jrow);
0281             isColumnNoisyOld = SiPixelGainCalibrationForHLTService_.isDeadColumn(detid, icol, jrow);
0282           }
0283           if (!isColumnDeadOld && !isColumnNoisyOld) {
0284             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0285               gainforthiscol[iglobalrow] = SiPixelGainCalibrationOfflineService_.getGain(detid, icol, jrow);
0286             if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0287               gainforthiscol[iglobalrow] = SiPixelGainCalibrationForHLTService_.getGain(detid, icol, jrow);
0288               pedforthiscol[iglobalrow] = SiPixelGainCalibrationForHLTService_.getPedestal(detid, icol, jrow);
0289             }
0290           }
0291           if (!isPixelDeadOld && !isPixelNoisyOld)
0292             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0293               ped = SiPixelGainCalibrationOfflineService_.getPedestal(detid, icol, jrow);
0294         } catch (const std::exception& er) {
0295           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0296               << "Problem trying to catch gain/ped from DETID " << detid << " @ col,row " << icol << "," << jrow
0297               << endl;
0298         }
0299         //edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")<<"For DetId "<<detid<<" we found gain : "<<gain<<", pedestal : "<<ped<<std::endl;
0300 
0301         if (DEBUG)
0302           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0303               << "=>=>=>=> Found gain " << gainforthiscol[iglobalrow] << " and ped " << pedforthiscol[iglobalrow]
0304               << endl;
0305 
0306         //Check if pixel is in new noisy list
0307         for (std::map<int, std::vector<std::pair<int, int> > >::const_iterator it = noisypixelkeeper.begin();
0308              it != noisypixelkeeper.end();
0309              it++)
0310           for (unsigned int i = 0; i < (it->second).size(); i++)
0311             if (it->first == detid && (it->second.at(i)).first == icol && (it->second.at(i)).second == jrow)
0312               isPixelNoisyNew = true;
0313 
0314         isColumnDead = isColumnDeadOld;
0315         isPixelDead = isPixelDeadOld;
0316 
0317         if (isPixelNoisyNew)
0318           noisyPixInRow++;
0319         if (noisyPixInRow == nrowsrocsplit)
0320           isColumnNoisyNew = true;
0321 
0322         if (insertnoisypixelsindb_ == 0) {
0323           isColumnNoisy = isColumnNoisyOld;
0324           isPixelNoisy = isPixelNoisyOld;
0325         } else if (insertnoisypixelsindb_ == 1) {
0326           isPixelNoisy = isPixelNoisyNew;
0327           isColumnNoisy = isColumnNoisyNew;
0328         } else if (insertnoisypixelsindb_ == 2) {
0329           isPixelNoisy = isPixelNoisyNew || isPixelNoisyOld;
0330           isColumnNoisy = isColumnNoisyNew || isColumnNoisyOld;
0331         }
0332 
0333         if (isPixelNoisy)
0334           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0335               << "Inserting a noisy pixel in " << detid << " at col,row " << icol << "," << jrow << endl;
0336         if (isColumnNoisy)
0337           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0338               << "Inserting a noisy column in " << detid << " at col,row " << icol << "," << jrow << endl;
0339         if (isPixelNoisy)
0340           nnoisy++;
0341         if (isPixelDead)
0342           ndead++;
0343 
0344         if (DEBUG)
0345           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Now Starting to fill the DB" << endl;
0346 
0347         //**********  Fill the new DB !!
0348 
0349         if (DEBUG)
0350           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0351               << "=>=>=>=> Filling Pixel Level Calibration" << endl;
0352 
0353         //Set Pedestal
0354         if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0355           if (isPixelDead)
0356             theGainCalibrationDbInputOffline_->setDeadPixel(theSiPixelGainCalibrationGainPerColPedPerPixel);
0357           else if (isPixelNoisy)
0358             theGainCalibrationDbInputOffline_->setNoisyPixel(theSiPixelGainCalibrationGainPerColPedPerPixel);
0359           else
0360             theGainCalibrationDbInputOffline_->setDataPedestal(ped, theSiPixelGainCalibrationGainPerColPedPerPixel);
0361         }
0362 
0363         //Set Gain
0364         if ((jrow + 1) % nrowsrocsplit == 0) {
0365           if (DEBUG)
0366             edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0367                 << "=>=>=>=> Filling Column Level Calibration" << endl;
0368 
0369           if (isColumnDead) {
0370             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0371               theGainCalibrationDbInputOffline_->setDeadColumn(nrowsrocsplit,
0372                                                                theSiPixelGainCalibrationGainPerColPedPerPixel);
0373             if (record_ == "SiPixelGainCalibrationForHLTRcd")
0374               theGainCalibrationDbInputForHLT_->setDeadColumn(nrowsrocsplit, theSiPixelGainCalibrationPerCol);
0375           } else if (isColumnNoisy) {
0376             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0377               theGainCalibrationDbInputOffline_->setNoisyColumn(nrowsrocsplit,
0378                                                                 theSiPixelGainCalibrationGainPerColPedPerPixel);
0379             if (record_ == "SiPixelGainCalibrationForHLTRcd")
0380               theGainCalibrationDbInputForHLT_->setNoisyColumn(nrowsrocsplit, theSiPixelGainCalibrationPerCol);
0381           } else {
0382             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0383               theGainCalibrationDbInputOffline_->setDataGain(
0384                   gainforthiscol[iglobalrow], nrowsrocsplit, theSiPixelGainCalibrationGainPerColPedPerPixel);
0385             if (record_ == "SiPixelGainCalibrationForHLTRcd")
0386               theGainCalibrationDbInputForHLT_->setData(
0387                   pedforthiscol[iglobalrow], gainforthiscol[iglobalrow], theSiPixelGainCalibrationPerCol);
0388           }
0389         }
0390 
0391         if (DEBUG)
0392           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0393               << "=>=>=>=> This pixel is finished inserting" << endl;
0394 
0395       }  //end of loop over rows
0396 
0397       if (DEBUG)
0398         edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0399             << "=>=>=>=> This column is finished inserting" << endl;
0400 
0401     }  //end of loop over col
0402 
0403     if (DEBUG)
0404       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Loop over rows/cols is finished" << endl;
0405 
0406     if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0407       SiPixelGainCalibrationOffline::Range offlinerange(theSiPixelGainCalibrationGainPerColPedPerPixel.begin(),
0408                                                         theSiPixelGainCalibrationGainPerColPedPerPixel.end());
0409       if (!theGainCalibrationDbInputOffline_->put(detid, offlinerange, ncols))
0410         edm::LogError("SiPixelGainCalibrationAnalysis")
0411             << "warning: detid already exists for Offline (gain per col, ped per pixel) calibration database"
0412             << std::endl;
0413     }
0414     if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0415       SiPixelGainCalibrationOffline::Range hltrange(theSiPixelGainCalibrationPerCol.begin(),
0416                                                     theSiPixelGainCalibrationPerCol.end());
0417       if (!theGainCalibrationDbInputForHLT_->put(detid, hltrange, ncols))
0418         edm::LogError("SiPixelGainCalibrationAnalysis")
0419             << "warning: detid already exists for HLT (gain per col, ped per col) calibration database" << std::endl;
0420     }
0421 
0422     if (DEBUG)
0423       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> This detid is finished inserting" << endl;
0424 
0425   }  //end of loop over Detids
0426 
0427   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << " --- writing to DB!" << std::endl;
0428   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0429   if (!mydbservice.isAvailable()) {
0430     edm::LogError("db service unavailable");
0431     return;
0432   } else {
0433     if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0434       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0435           << "now doing SiPixelGainCalibrationOfflineRcd payload..." << std::endl;
0436       if (mydbservice->isNewTagRequest("SiPixelGainCalibrationOfflineRcd")) {
0437         mydbservice->createOneIOV<SiPixelGainCalibrationOffline>(
0438             *theGainCalibrationDbInputOffline_, mydbservice->beginOfTime(), "SiPixelGainCalibrationOfflineRcd");
0439       } else {
0440         mydbservice->appendOneIOV<SiPixelGainCalibrationOffline>(
0441             *theGainCalibrationDbInputOffline_, mydbservice->currentTime(), "SiPixelGainCalibrationOfflineRcd");
0442       }
0443     }
0444     if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0445       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0446           << "now doing SiPixelGainCalibrationForHLTRcd payload..." << std::endl;
0447       if (mydbservice->isNewTagRequest("SiPixelGainCalibrationForHLTRcd")) {
0448         mydbservice->createOneIOV<SiPixelGainCalibrationForHLT>(
0449             *theGainCalibrationDbInputForHLT_, mydbservice->beginOfTime(), "SiPixelGainCalibrationForHLTRcd");
0450       } else {
0451         mydbservice->appendOneIOV<SiPixelGainCalibrationForHLT>(
0452             *theGainCalibrationDbInputForHLT_, mydbservice->currentTime(), "SiPixelGainCalibrationForHLTRcd");
0453       }
0454     }
0455   }
0456 
0457   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << " ---> SUMMARY :" << std::endl;
0458   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0459       << " File had   " << nnoisyininput << " noisy pixels" << std::endl;
0460 
0461   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << " DB has now " << nnoisy << " noisy pixels" << std::endl;
0462   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << " DB has now " << ndead << " dead pixels" << std::endl;
0463 }
0464 
0465 void SiPixelGainCalibrationRejectNoisyAndDead::getNoisyPixels() {
0466   nnoisyininput = 0;
0467 
0468   ifstream in;
0469   struct stat Stat;
0470   if (stat(noisypixellist_.c_str(), &Stat)) {
0471     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "No file named " << noisypixellist_ << std::endl;
0472     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0473         << "If you don't want to insert noisy pixel flag, disable it using tag insertNoisyPixelsInDB " << std::endl;
0474     return;
0475   }
0476 
0477   in.open(noisypixellist_.c_str());
0478   if (in.is_open()) {
0479     TString line;
0480     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "opened" << endl;
0481     char linetmp[201];
0482     while (in.getline(linetmp, 200)) {
0483       line = linetmp;
0484       if (line.Contains("OFFLINE")) {
0485         line.Remove(0, line.First(",") + 9);
0486         TString detidstring = line;
0487         detidstring.Remove(line.First(" "), line.Sizeof());
0488 
0489         line.Remove(0, line.First(",") + 20);
0490         TString col = line;
0491         col.Remove(line.First(","), line.Sizeof());
0492         line.Remove(0, line.First(",") + 1);
0493         TString row = line;
0494         row.Remove(line.First(" "), line.Sizeof());
0495 
0496         edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0497             << "Found noisy pixel in DETID " << detidstring << " col,row " << col << "," << row << std::endl;
0498         nnoisyininput++;
0499 
0500         std::vector<std::pair<int, int> > tempvec;
0501         if (noisypixelkeeper.find(detidstring.Atoi()) != noisypixelkeeper.end())
0502           tempvec = (noisypixelkeeper.find(detidstring.Atoi()))->second;
0503 
0504         std::pair<int, int> temppair(col.Atoi(), row.Atoi());
0505         tempvec.push_back(temppair);
0506         noisypixelkeeper[detidstring.Atoi()] = tempvec;
0507       }
0508     }
0509   }
0510   /*
0511   for(std::map <int,std::vector<std::pair<int,int> > >::const_iterator it=noisypixelkeeper.begin();it!=noisypixelkeeper.end();it++) 
0512     for(int i=0;i<(it->second).size();i++)
0513       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")<<it->first<<"  "<<(it->second.at(i)).first<<"  "<<(it->second.at(i)).second<<std::endl;
0514   */
0515 }
0516 
0517 //define this as a plug-in
0518 DEFINE_FWK_MODULE(SiPixelGainCalibrationRejectNoisyAndDead);