CMS 3D CMS Logo

SiStripBadStripFromASCIIFile.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <cstdio>
4 #include <string>
5 
6 // user include files
7 
9 
18 
19 #include "CLHEP/Random/RandFlat.h"
20 #include "CLHEP/Random/RandGauss.h"
21 
23 
24 using namespace std;
25 
28  printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)) {
30  "file", edm::FileInPath("CalibTracker/SiStripQuality/data/DefectsFromConstructionDB.dat"));
31 }
32 
33 std::unique_ptr<SiStripBadStrip> SiStripBadStripFromASCIIFile::getNewObject() {
34  auto SiStripBadStrip_ = std::make_unique<SiStripBadStrip>();
35 
36  // open file and fill DB
37  ifstream infile((fp_.fullPath()).c_str());
38  if (!infile) {
39  std::cout << "Problem while trying to open File: " << (fp_.fullPath()).c_str() << std::endl;
40  }
41 
42  //variables needed for reading file and filling of SiStripBadStripObject
43  uint32_t detid;
44  short flag;
45  short channel;
46 
47  bool firstrun = true;
48  short tempchannel = 0;
49  int count = 0;
50  std::vector<unsigned int> theSiStripVector;
51  short tempflag = 0;
52  uint32_t tempdetid = 0;
53 
54  while (!infile.eof()) {
55  // get data from file:
56  //infile >> detid >> channel >> flag;
57 
58  //if no flag is available, use the following:
59  infile >> detid >> channel;
60  flag = 1;
61 
62  unsigned int theBadStripRange = 0;
63 
64  // first loop ?
65  if (firstrun) {
66  tempdetid = detid;
67  tempchannel = channel;
68  tempflag = flag;
69  count = 0;
70  firstrun = false;
71  }
72 
73  if (detid == tempdetid) {
74  if (channel != tempchannel + count || flag != tempflag) {
75  // 1.badstrip, nconsectrips, flag
76  theBadStripRange = SiStripBadStrip_->encode(
77  tempchannel - 1,
78  count,
79  tempflag); // In the quality object, strips are counted from 0 to 767!!! Therefore "tempchannel-1"!
80  // In the input txt-file, they have to be from 1 to 768 instead!!!
81  edm::LogInfo("SiStripBadStripFromASCIIFile")
82  << "detid " << tempdetid << " \t"
83  << " firstBadStrip " << tempchannel << "\t "
84  << " NconsecutiveBadStrips " << count << "\t "
85  << "flag " << tempflag << "\t"
86  << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
87 
88  theSiStripVector.push_back(theBadStripRange);
89 
90  if (infile.eof()) { // Don't forget to save the last strip before eof!!!
91  SiStripBadStrip::Range range(theSiStripVector.begin(), theSiStripVector.end());
92  if (!SiStripBadStrip_->put(tempdetid, range))
93  edm::LogError("SiStripBadStripFromASCIIFile")
94  << "[SiStripBadStripFromASCIIFile::GetNewObject] detid already exists" << std::endl;
95  theSiStripVector.clear();
96  }
97 
98  count = 1;
99  tempchannel = channel;
100  tempflag = flag;
101 
102  } else {
103  count++;
104  }
105  }
106 
107  if (detid != tempdetid) {
108  // 1.badstrip, nconsectrips, flag
109  theBadStripRange = SiStripBadStrip_->encode(
110  tempchannel - 1,
111  count,
112  tempflag); // In the quality object, strips are counted from 0 to 767!!! Therefore "tempchannel-1"!
113  // In the input txt-file, they have to be from 1 to 768 instead!!!
114  edm::LogInfo("SiStripBadStripFromASCIIFile")
115  << "detid " << tempdetid << " \t"
116  << " firstBadStrip " << tempchannel << "\t "
117  << " NconsecutiveBadStrips " << count << "\t "
118  << "flag " << tempflag << "\t"
119  << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
120 
121  theSiStripVector.push_back(theBadStripRange);
122 
123  // populate db object
124  SiStripBadStrip::Range range(theSiStripVector.begin(), theSiStripVector.end());
125  if (!SiStripBadStrip_->put(tempdetid, range))
126  edm::LogError("SiStripBadStripFromASCIIFile")
127  << "[SiStripBadStripFromASCIIFile::GetNewObject] detid already exists" << std::endl;
128  theSiStripVector.clear();
129 
130  count = 1;
131  tempdetid = detid;
132  tempchannel = channel;
133  tempflag = flag;
134  }
135  }
136 
137  return SiStripBadStrip_;
138 }
FEDNumbering.h
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
electrons_cff.bool
bool
Definition: electrons_cff.py:366
StripGeomDetUnit.h
funct::false
false
Definition: Factorize.h:29
TrackerGeometry.h
StripGeomDetType.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GeomDetType.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
StripTopology.h
SiStripBadStripFromASCIIFile.h
SiStripBadStrip
Definition: SiStripBadStrip.h:30
edm::FileInPath
Definition: FileInPath.h:64
SiStripBadStrip::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripBadStrip.h:53
ConditionDBWriter
Definition: ConditionDBWriter.h:149
SiStripBadStripFromASCIIFile::fp_
edm::FileInPath fp_
Definition: SiStripBadStripFromASCIIFile.h:19
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
SiStripBadStripFromASCIIFile::getNewObject
std::unique_ptr< SiStripBadStrip > getNewObject() override
Definition: SiStripBadStripFromASCIIFile.cc:33
TrackerDigiGeometryRecord.h
SiStripBadStripFromASCIIFile::SiStripBadStripFromASCIIFile
SiStripBadStripFromASCIIFile(const edm::ParameterSet &iConfig)
Definition: SiStripBadStripFromASCIIFile.cc:26
edm::ParameterSet
Definition: ParameterSet.h:47
writedatasetfile.firstrun
firstrun
Definition: writedatasetfile.py:27
GeomDet.h
std
Definition: JetResolutionObject.h:76
timingPdfMaker.infile
infile
Definition: timingPdfMaker.py:350
ParameterSet.h
edm::Log
Definition: MessageLogger.h:70
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116