CMS 3D CMS Logo

SiStripGainFromAsciiFile.cc
Go to the documentation of this file.
4 
6 
8 
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 
14  : ConditionDBWriter<SiStripApvGain>(iConfig) {
15  Asciifilename_ = iConfig.getParameter<std::string>("InputFileName");
16  referenceValue_ = iConfig.getParameter<double>("referenceValue");
18 }
19 
21  edm::LogInfo("SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile");
22 }
23 
24 std::unique_ptr<SiStripApvGain> SiStripGainFromAsciiFile::getNewObject() {
25  auto obj = std::make_unique<SiStripApvGain>();
26 
27  std::stringstream ss;
28  ss.str("");
29  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Reading Ascii File\n";
30  FILE* infile = fopen(Asciifilename_.c_str(), "r");
31  char line[4096];
32  if (infile) {
33  while (fgets(line, 4096, infile) != nullptr) {
34  uint32_t detid;
35  ModuleGain MG;
36  MG.apv[0] = 0.0;
37  MG.apv[1] = 0.0;
38  MG.apv[2] = 0.0;
39  MG.apv[3] = 0.0;
40  MG.apv[4] = 0.0;
41  MG.apv[5] = 0.0;
42  char* saveptr;
43  char* pch = strtok_r(line, " ", &saveptr);
44  int Arg = 0;
45  while (pch != nullptr) {
46  if (Arg == 0) {
47  sscanf(pch, "%d", &detid);
48  } else if (Arg <= 6) {
49  sscanf(pch, "%f", &(MG.apv[Arg - 1]));
50  } else {
51  //nothing to do here
52  }
53  pch = strtok_r(nullptr, " ", &saveptr);
54  Arg++;
55  }
56  ss << detid << " " << MG.apv[0] << " " << MG.apv[1] << " " << MG.apv[2] << " " << MG.apv[3] << " " << MG.apv[4]
57  << " " << MG.apv[5] << std::endl;
58  GainsMap.insert(std::pair<unsigned int, ModuleGain>(detid, MG));
59  }
60  fclose(infile);
61  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
62  } else {
63  edm::LogError("SiStripGainFromAsciiFile")
64  << " [SiStripGainFromAsciiFile::getNewObject] Error opening file " << Asciifilename_ << std::endl;
65  assert(0);
66  }
67 
68  const auto detInfo = SiStripDetInfoFileReader::read(fp_.fullPath());
69 
70  ss.str("");
71  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Filling SiStripApvGain object";
72  short nApvPair;
73  for (const auto it : detInfo.getAllDetIds()) {
74  ModuleGain MG;
75  if (DetId(it).det() != DetId::Tracker)
76  continue;
77 
78  nApvPair = detInfo.getNumberOfApvsAndStripLength(it).first / 2;
79 
80  ss << "Looking at detid " << it << " nApvPairs " << nApvPair << std::endl;
81  auto iter = GainsMap.find(it);
82  if (iter != GainsMap.end()) {
83  MG = iter->second;
84  ss << " " << MG.apv[0] << " " << MG.apv[1] << " " << MG.apv[2] << " " << MG.apv[3] << " " << MG.apv[4] << " "
85  << MG.apv[5] << std::endl;
86  } else {
87  ss << "Hard reset for detid " << it << std::endl;
89  }
90 
91  std::vector<float> DetGainsVector;
92 
93  if (nApvPair == 2) {
94  DetGainsVector.push_back(MG.apv[0] / referenceValue_);
95  DetGainsVector.push_back(MG.apv[1] / referenceValue_);
96  DetGainsVector.push_back(MG.apv[2] / referenceValue_);
97  DetGainsVector.push_back(MG.apv[3] / referenceValue_);
98  } else if (nApvPair == 3) {
99  DetGainsVector.push_back(MG.apv[0] / referenceValue_);
100  DetGainsVector.push_back(MG.apv[1] / referenceValue_);
101  DetGainsVector.push_back(MG.apv[2] / referenceValue_);
102  DetGainsVector.push_back(MG.apv[3] / referenceValue_);
103  DetGainsVector.push_back(MG.apv[4] / referenceValue_);
104  DetGainsVector.push_back(MG.apv[5] / referenceValue_);
105  } else {
106  edm::LogError("SiStripGainFromAsciiFile") << " SiStripGainFromAsciiFile::getNewObject] ERROR for detid " << it
107  << " not expected number of APV pairs " << nApvPair << std::endl;
108  }
109 
110  SiStripApvGain::Range range(DetGainsVector.begin(), DetGainsVector.end());
111  if (!obj->put(it, range)) {
112  edm::LogError("SiStripGainFromAsciiFile")
113  << " [SiStripGainFromAsciiFile::getNewObject] detid already exists" << std::endl;
114  ss << " [SiStripGainFromAsciiFile::getNewObject] detid already exists" << std::endl;
115  }
116  }
117  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
118 
119  return obj;
120 }
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
SiStripGainFromAsciiFile::fp_
edm::FileInPath fp_
Definition: SiStripGainFromAsciiFile.h:38
MessageLogger.h
SiStripGainFromAsciiFile::SiStripGainFromAsciiFile
SiStripGainFromAsciiFile(const edm::ParameterSet &)
Definition: SiStripGainFromAsciiFile.cc:13
SiStripGainFromAsciiFile::getNewObject
std::unique_ptr< SiStripApvGain > getNewObject() override
Definition: SiStripGainFromAsciiFile.cc:24
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
SiStripGainFromAsciiFile::GainsMap
std::unordered_map< unsigned int, ModuleGain > GainsMap
Definition: SiStripGainFromAsciiFile.h:40
SiStripGainFromAsciiFile::Asciifilename_
std::string Asciifilename_
Definition: SiStripGainFromAsciiFile.h:36
cms::cuda::assert
assert(be >=bs)
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
SiStripGainFromAsciiFile.h
SiStripDetInfoFileReader::read
SiStripDetInfo read(std::string filePath)
Definition: SiStripDetInfoFileReader.cc:11
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
DetId
Definition: DetId.h:17
edm::FileInPath
Definition: FileInPath.h:61
ConditionDBWriter
Definition: ConditionDBWriter.h:149
SiStripGainFromAsciiFile::ModuleGain::hard_reset
void hard_reset(float val)
Definition: SiStripGainFromAsciiFile.h:30
SiStripDetInfoFileReader.h
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
SiStripGainFromAsciiFile::ModuleGain
Definition: SiStripGainFromAsciiFile.h:22
edm::ParameterSet
Definition: ParameterSet.h:47
DetId::Tracker
Definition: DetId.h:25
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile
~SiStripGainFromAsciiFile() override
Definition: SiStripGainFromAsciiFile.cc:20
DetId.h
SiStripApvGain::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripApvGain.h:28
SiStripDetInfoFileReader::kDefaultFile
constexpr static char const *const kDefaultFile
Definition: SiStripDetInfoFileReader.h:10
SiStripGainFromAsciiFile::referenceValue_
float referenceValue_
Definition: SiStripGainFromAsciiFile.h:37
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
timingPdfMaker.infile
infile
Definition: timingPdfMaker.py:349
ParameterSet.h
mps_splice.line
line
Definition: mps_splice.py:76
SiStripApvGain
Definition: SiStripApvGain.h:25
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
SiStripGainFromAsciiFile::ModuleGain::apv
float apv[6]
Definition: SiStripGainFromAsciiFile.h:23