CMS 3D CMS Logo

SiStripPopConHandlerUnitTestNoise.h
Go to the documentation of this file.
1 #ifndef SISTRIPPOPCON_UNITTEST_HANDLER_NOISE_H
2 #define SISTRIPPOPCON_UNITTEST_HANDLER_NOISE_H
3 
9 
12 
16 
17 #include <sstream>
18 #include <vector>
19 #include <string>
20 #include <iostream>
21 #include <typeinfo>
22 #include <ctime>
23 
24 #include "CLHEP/Random/RandFlat.h"
25 #include "CLHEP/Random/RandGauss.h"
26 
30 
31 namespace popcon {
32 
33  template <typename T>
35  public:
36  enum DataType { UNDEFINED = 0, _Cabling = 1, _Pedestal = 2, _Noise = 3, _Threshold = 4, _BadStrip = 5, _Gain = 6 };
37 
38  //---------------------------------------
39  //
41  : m_name(pset.getUntrackedParameter<std::string>("name", "SiStripPopPopConConfigDbObjHandler")),
42  m_since(pset.getUntrackedParameter<uint32_t>("since", 5)),
43  m_debugMode(pset.getUntrackedParameter<bool>("debug", false)){};
44 
45  //---------------------------------------
46  //
48 
49  //---------------------------------------
50  //
51  void getNewObjects() override {
52  edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name;
53 
54  if (m_debugMode) {
55  std::stringstream ss;
56  ss << "\n\n------- " << m_name << " - > getNewObjects\n";
57  if (this->tagInfo().size) {
58  //check whats already inside of database
59  ss << "got offlineInfo" << this->tagInfo().name << ", size " << this->tagInfo().size
60  << " , last object valid since " << this->tagInfo().lastInterval.since << " token "
61  << this->tagInfo().lastInterval.payloadId << "\n\n UserText " << this->userTextLog() << "\n LogDBEntry \n"
62  << this->logDBEntry().logId << "\n"
63  << this->logDBEntry().destinationDB << "\n"
64  << this->logDBEntry().provenance << "\n"
65  << this->logDBEntry().usertext << "\n"
66  << this->logDBEntry().iovtag << "\n"
67  << this->logDBEntry().iovtimetype << "\n"
68  << this->logDBEntry().payloadIdx << "\n"
69  << this->logDBEntry().payloadClass << "\n"
70  << this->logDBEntry().payloadToken << "\n"
71  << this->logDBEntry().exectime << "\n"
72  << this->logDBEntry().execmessage << "\n"
73  << "\n\n-- user text "
74  << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@"));
75  } else {
76  ss << " First object for this tag ";
77  }
78  edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << ss.str();
79  }
80  if (isTransferNeeded())
82 
83  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
84  << "[getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
85  }
86 
87  //---------------------------------------
88  //
89  std::string id() const override { return m_name; }
90 
91  private:
92  //methods
93 
95  if (typeid(T) == typeid(SiStripFedCabling)) {
96  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
97  << "[getDataType] for PopCon application " << m_name << " " << typeid(T).name();
98  return _Cabling;
99  }
100  return UNDEFINED;
101  }
102 
103  //---------------------------------------
104  //
106  edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[isTransferNeeded] checking for transfer" << std::endl;
107  std::stringstream ss_logdb, ss;
108  std::stringstream ss1;
109 
110  //get log information from previous upload
111  if (this->tagInfo().size)
112  ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@"));
113  else
114  ss_logdb << "";
115 
116  ss << "@ " << clock();
117 
118  if (!strcmp(ss.str().c_str(), ss_logdb.str().c_str())) {
119  //string are equal, no need to do transfer
120  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
121  << "[isTransferNeeded] the selected conditions are already uploaded in the last iov ("
122  << this->tagInfo().lastInterval.since << ") open for the object " << this->logDBEntry().payloadClass
123  << " in the db " << this->logDBEntry().destinationDB << " parameters: " << ss.str()
124  << "\n NO TRANSFER NEEDED";
125  return false;
126  }
127  this->m_userTextLog = ss.str();
128  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
129  << "[isTransferNeeded] the selected conditions will be uploaded: " << ss.str() << "\n A- " << ss.str()
130  << "\n B- " << ss_logdb.str() << "\n Fine";
131 
132  return true;
133  }
134 
135  //---------------------------------------
136  //
137  void setForTransfer() {
138  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
139  << "[setForTransfer] " << m_name << " getting data to be transferred " << std::endl;
140 
141  T* obj = nullptr;
142 
143  fillObject(obj);
144 
145  if (!this->tagInfo().size)
146  m_since = 1;
147  else if (m_debugMode)
148  m_since = this->tagInfo().lastInterval.since + 1;
149 
150  if (obj != nullptr) {
151  edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "setting since = " << m_since << std::endl;
152  this->m_to_transfer.push_back(std::make_pair(obj, m_since));
153  } else {
154  edm::LogError("SiStripPopPopConConfigDbObjHandler")
155  << "[setForTransfer] " << m_name << " : NULL pointer of obj " << typeid(T).name()
156  << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted" << std::endl;
157  }
158  }
159 
160  private:
161  // data members
163  unsigned long long m_since;
166 
167  void fillObject(T*& obj) {
168  if (typeid(T) == typeid(SiStripNoises)) {
169  obj = new SiStripNoises();
170 
171  edm::FileInPath fp_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
173 
174  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>& DetInfos = reader.getAllData();
175 
176  int count = -1;
177  for (std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator it = DetInfos.begin();
178  it != DetInfos.end();
179  it++) {
180  count++;
181  //Generate Noise for det detid
182  SiStripNoises::InputVector theSiStripVector;
183  for (int strip = 0; strip < 128 * it->second.nApvs; ++strip) {
184  float MeanNoise = 5;
185  float RmsNoise = 1;
186 
187  float noise = CLHEP::RandGauss::shoot(MeanNoise, RmsNoise);
188 
189  //double badStripProb = .5;
190  //bool disable = (CLHEP::RandFlat::shoot(1.) < badStripProb ? true:false);
191 
192  obj->setData(noise, theSiStripVector);
193  if (count < 6)
194  edm::LogInfo("SiStripNoisesBuilder") << "detid " << it->first << " \t"
195  << " strip " << strip << " \t" << noise << " \t"
196  << theSiStripVector.back() / 10 << " \t" << std::endl;
197  }
198 
199  if (!obj->put(it->first, theSiStripVector))
200  edm::LogError("SiStripNoisesBuilder")
201  << "[SiStripNoisesBuilder::analyze] detid already exists" << std::endl;
202  }
203  }
204  }
205  };
206 
207 } // namespace popcon
208 
209 #endif //SISTRIPPOPCON_UNITTEST_HANDLER_H
PopConSourceHandler.h
SiStripPartition.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
popcon::PopConSourceHandler::m_to_transfer
OldContainer m_to_transfer
Definition: PopConSourceHandler.h:162
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
popcon::SiStripPopConHandlerUnitTestNoise::isTransferNeeded
bool isTransferNeeded()
Definition: SiStripPopConHandlerUnitTestNoise.h:105
popcon::SiStripPopConHandlerUnitTestNoise::_BadStrip
Definition: SiStripPopConHandlerUnitTestNoise.h:36
SiStripNoises
Definition: SiStripNoises.h:25
popcon::SiStripPopConHandlerUnitTestNoise::UNDEFINED
Definition: SiStripPopConHandlerUnitTestNoise.h:36
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
SiStripCondObjBuilderFromDb.h
popcon::SiStripPopConHandlerUnitTestNoise::SiStripPopConHandlerUnitTestNoise
SiStripPopConHandlerUnitTestNoise(const edm::ParameterSet &pset)
Definition: SiStripPopConHandlerUnitTestNoise.h:40
edm::LogInfo
Definition: MessageLogger.h:254
popcon::SiStripPopConHandlerUnitTestNoise::_Threshold
Definition: SiStripPopConHandlerUnitTestNoise.h:36
popcon::SiStripPopConHandlerUnitTestNoise::id
std::string id() const override
Definition: SiStripPopConHandlerUnitTestNoise.h:89
popcon::SiStripPopConHandlerUnitTestNoise::m_since
unsigned long long m_since
Definition: SiStripPopConHandlerUnitTestNoise.h:163
SiStripNoises.h
SiStripDbParams.h
SiStripFedCabling
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses,...
Definition: SiStripFedCabling.h:25
SiStripDetInfoFileReader
Definition: SiStripDetInfoFileReader.h:30
cond::LogDBEntry_t::execmessage
std::string execmessage
Definition: Types.h:98
popcon::SiStripPopConHandlerUnitTestNoise::_Pedestal
Definition: SiStripPopConHandlerUnitTestNoise.h:36
popcon::SiStripPopConHandlerUnitTestNoise::_Cabling
Definition: SiStripPopConHandlerUnitTestNoise.h:36
cond::TagInfo_t::name
std::string name
Definition: Types.h:72
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::FileInPath
Definition: FileInPath.h:64
popcon::SiStripPopConHandlerUnitTestNoise
Definition: SiStripPopConHandlerUnitTestNoise.h:34
DQM.reader
reader
Definition: DQM.py:105
Service.h
cond::LogDBEntry_t::provenance
std::string provenance
Definition: Types.h:89
SiStripDetInfoFileReader.h
SiStripApvGain.h
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
popcon::SiStripPopConHandlerUnitTestNoise::getNewObjects
void getNewObjects() override
Definition: SiStripPopConHandlerUnitTestNoise.h:51
cond::LogDBEntry_t::payloadToken
std::string payloadToken
Definition: Types.h:96
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
popcon::PopConSourceHandler::tagInfo
cond::TagInfo_t const & tagInfo() const
Definition: PopConSourceHandler.h:78
cond::Iov_t::payloadId
Hash payloadId
Definition: Types.h:55
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
popcon::SiStripPopConHandlerUnitTestNoise::m_name
std::string m_name
Definition: SiStripPopConHandlerUnitTestNoise.h:162
cond::LogDBEntry_t::usertext
std::string usertext
Definition: Types.h:90
cond::Iov_t::since
Time_t since
Definition: Types.h:53
popcon::SiStripPopConHandlerUnitTestNoise::m_debugMode
bool m_debugMode
Definition: SiStripPopConHandlerUnitTestNoise.h:164
popcon::SiStripPopConHandlerUnitTestNoise::~SiStripPopConHandlerUnitTestNoise
~SiStripPopConHandlerUnitTestNoise() override
Definition: SiStripPopConHandlerUnitTestNoise.h:47
edm::Service< SiStripCondObjBuilderFromDb >
popcon::SiStripPopConHandlerUnitTestNoise::setForTransfer
void setForTransfer()
Definition: SiStripPopConHandlerUnitTestNoise.h:137
cond::LogDBEntry_t::iovtag
std::string iovtag
Definition: Types.h:91
cond::LogDBEntry_t::destinationDB
std::string destinationDB
Definition: Types.h:88
popcon::PopConSourceHandler
Definition: PopConSourceHandler.h:30
cond::TagInfo_t::lastInterval
Iov_t lastInterval
Definition: Types.h:73
cond::LogDBEntry_t::iovtimetype
std::string iovtimetype
Definition: Types.h:92
cond::LogDBEntry_t::payloadClass
std::string payloadClass
Definition: Types.h:95
std
Definition: JetResolutionObject.h:76
popcon
Definition: Exception.h:6
T
long double T
Definition: Basic3DVectorLD.h:48
cond::LogDBEntry_t::logId
unsigned long long logId
Definition: Types.h:87
popcon::SiStripPopConHandlerUnitTestNoise::_Noise
Definition: SiStripPopConHandlerUnitTestNoise.h:36
popcon::SiStripPopConHandlerUnitTestNoise::fillObject
void fillObject(T *&obj)
Definition: SiStripPopConHandlerUnitTestNoise.h:167
ParameterSetfwd.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
popcon::SiStripPopConHandlerUnitTestNoise::_Gain
Definition: SiStripPopConHandlerUnitTestNoise.h:36
popcon::SiStripPopConHandlerUnitTestNoise::getDataType
DataType getDataType()
Definition: SiStripPopConHandlerUnitTestNoise.h:94
SiStripNoises::InputVector
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
hgchebackDigitizer_cfi.noise
noise
Definition: hgchebackDigitizer_cfi.py:42
ParameterSet.h
popcon::SiStripPopConHandlerUnitTestNoise::DataType
DataType
Definition: SiStripPopConHandlerUnitTestNoise.h:36
Types.h
cond::LogDBEntry_t::payloadIdx
unsigned int payloadIdx
Definition: Types.h:93
popcon::PopConSourceHandler::m_userTextLog
std::string m_userTextLog
Definition: PopConSourceHandler.h:168
popcon::PopConSourceHandler::logDBEntry
cond::LogDBEntry_t const & logDBEntry() const
Definition: PopConSourceHandler.h:84
popcon::PopConSourceHandler::userTextLog
std::string const & userTextLog() const
Definition: PopConSourceHandler.h:111
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
cond::TagInfo_t::size
size_t size
Definition: Types.h:74
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
popcon::SiStripPopConHandlerUnitTestNoise::condObjBuilder
edm::Service< SiStripCondObjBuilderFromDb > condObjBuilder
Definition: SiStripPopConHandlerUnitTestNoise.h:165
cond::LogDBEntry_t::exectime
std::string exectime
Definition: Types.h:97