CMS 3D CMS Logo

FineDelayHistosUsingDb.cc
Go to the documentation of this file.
1 
17 #include <iostream>
18 
19 using namespace sistrip;
20 
21 // -----------------------------------------------------------------------------
24  : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("FineDelayParameters"), bei, sistrip::FINE_DELAY),
26  SamplingHistograms(pset.getParameter<edm::ParameterSet>("FineDelayParameters"), bei, sistrip::FINE_DELAY),
27  tracker_(nullptr) {
28  LogTrace(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
29  << " Constructing object...";
30  delays_.clear();
31 }
32 
33 // -----------------------------------------------------------------------------
36  LogTrace(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
37  << " Destructing object...";
38 }
39 
40 // -----------------------------------------------------------------------------
44  // get geometry
46  setup.get<TrackerDigiGeometryRecord>().get(estracker);
47  tracker_ = &(*estracker);
49  cosmic_ = this->pset().getParameter<bool>("cosmic");
50 }
51 
52 // -----------------------------------------------------------------------------
55  if (!db()) {
56  edm::LogWarning(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
57  << " NULL pointer to SiStripConfigDb interface!"
58  << " Aborting upload...";
59  return;
60  }
61 
62  // Retrieve and update PLL device descriptions
65  bool upload = update(devices);
66 
67  // Check if new PLL settings are valid
68  if (!upload) {
69  edm::LogWarning(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
70  << " Found invalid PLL settings (coarse > 15)"
71  << " Aborting update to database...";
72  return;
73  }
74 
75  // Upload PLL device descriptions
76  if (doUploadConf()) {
77  LogTrace(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
78  << " Uploading PLL settings to DB...";
80  LogTrace(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
81  << " Upload of PLL settings to DB finished!";
82  } else {
83  edm::LogWarning(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
84  << " TEST only! No PLL settings will be uploaded to DB...";
85  }
86 
87  // Update FED descriptions with new ticker thresholds
90  update(feds);
91 
92  // Update FED descriptions with new ticker thresholds
93  if (doUploadConf()) {
94  LogTrace(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
95  << " Uploading FED ticker thresholds to DB...";
97  LogTrace(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
98  << " Upload of FED ticker thresholds to DB finished!";
99  } else {
100  edm::LogWarning(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
101  << " TEST only! No FED ticker thresholds will be uploaded to DB...";
102  }
103 }
104 
106  // do nothing if delays_ map is already filled
107  if (!delays_.empty())
108  return;
109 
110  // the point from which track should originate
111  float x = 0.;
112  float y = 0.;
113  float z = 0.;
114  if (cosmic_) {
115  y = 385.;
116  z = 20.;
117  } // mean entry point of cosmics
118  GlobalPoint referenceP_ = GlobalPoint(x, y, z);
119  const double c = 30; // cm/ns
120 
121  // the reference parameters (best delay in ns, initial Latency)
122  float bestDelay_ = 0.;
123  if (!data().empty()) {
124  Analyses::const_iterator iter = data().begin();
125  bestDelay_ = dynamic_cast<SamplingAnalysis*>(iter->second)->maximum();
126  }
127 
128  // Retrieve FED ids from cabling
129  auto ids = cabling()->fedIds();
130 
131  // loop over the FED ids
132  for (auto ifed = ids.begin(); ifed != ids.end(); ++ifed) {
133  auto conns = cabling()->fedConnections(*ifed);
134  // loop over the connections for that FED
135  for (auto iconn = conns.begin(); iconn != conns.end(); ++iconn) {
136  // check that this is a tracker module
137  if (DetId(iconn->detId()).det() != DetId::Tracker)
138  continue;
139  // retrieve the position of that module in the tracker using the geometry
140  // and use it to compute the distance to the reference point set in the configuration
141  if (tracker_) {
142  float dist = tracker_->idToDetUnit(DetId(iconn->detId()))->toLocal(referenceP_).mag();
143  float tof = dist / c;
144  // compute the PLL delay shift for the module as delay + tof
145  float delay = bestDelay_ + tof;
146  // store that in the map
148  iconn->fecCrate(), iconn->fecSlot(), iconn->fecRing(), iconn->ccuAddr(), iconn->ccuChan(), 0)
149  .key()] = delay;
150  edm::LogVerbatim(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__
151  << "] Computed Delay to be added to PLL: " << bestDelay_ << " " << tof << " "
152  << delay << std::endl;
153  } else {
154  edm::LogError(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
155  << " Tracker geometry not initialized. Impossible to compute the delays.";
156  }
157  }
158  }
159 }
160 
161 // -----------------------------------------------------------------------------
164  // do the core computation of delays per FED connection
165  computeDelays();
166 
167  // Iterate through devices and update device descriptions
168  uint16_t updated = 0;
169  std::vector<SiStripFecKey> invalid;
170  SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
171  for (idevice = devices.begin(); idevice != devices.end(); idevice++) {
172  // Check device type
173  if ((*idevice)->getDeviceType() != PLL) {
174  continue;
175  }
176 
177  // Cast to retrieve appropriate description object
178  pllDescription* desc = dynamic_cast<pllDescription*>(*idevice);
179  if (!desc) {
180  continue;
181  }
182 
183  // Retrieve device addresses from device description
185 
186  // Construct key from device description
187  uint32_t fec_key =
188  SiStripFecKey(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, addr.ccuAddr_, addr.ccuChan_, 0).key();
189  SiStripFecKey fec_path = SiStripFecKey(fec_key);
190 
191  // extract the delay from the map
192  float delay = desc->getDelayCoarse() * 25 + desc->getDelayFine() * 25. / 24. + delays_[fec_key];
193  int delayCoarse = int(delay / 25);
194  int delayFine = int(round((delay - 25 * delayCoarse) * 24. / 25.));
195  if (delayFine == 24) {
196  delayFine = 0;
197  ++delayCoarse;
198  }
199  // maximum coarse setting
200  if (delayCoarse > 15) {
201  invalid.push_back(fec_key);
202  delayCoarse = sistrip::invalid_;
203  }
204 
205  // Update PLL settings
206  if (delayCoarse != sistrip::invalid_ && delayFine != sistrip::invalid_) {
207  std::stringstream ss;
208  ss << "[FineDelayHistosUsingDb::" << __func__ << "]"
209  << " Updating coarse/fine PLL settings"
210  << " for Crate/FEC/slot/ring/CCU " << fec_path.fecCrate() << "/" << fec_path.fecSlot() << "/"
211  << fec_path.fecRing() << "/" << fec_path.ccuAddr() << "/" << fec_path.ccuChan() << " from "
212  << static_cast<uint16_t>(desc->getDelayCoarse()) << "/" << static_cast<uint16_t>(desc->getDelayFine());
213  desc->setDelayCoarse(delayCoarse);
214  desc->setDelayFine(delayFine);
215  updated++;
216  ss << " to " << static_cast<uint16_t>(desc->getDelayCoarse()) << "/"
217  << static_cast<uint16_t>(desc->getDelayFine());
218  LogTrace(mlDqmClient_) << ss.str();
219 
220  } else {
221  LogTrace(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
222  << " Unexpected PLL delay settings for Crate/FEC/slot/ring/CCU " << fec_path.fecCrate()
223  << "/" << fec_path.fecSlot() << "/" << fec_path.fecRing() << "/" << fec_path.ccuAddr()
224  << "/" << fec_path.ccuChan();
225  }
226  }
227 
228  // Check if invalid settings were found
229  if (!invalid.empty()) {
230  std::stringstream ss;
231  ss << "[FineDelayHistosUsingDb::" << __func__ << "]"
232  << " Found PLL coarse setting of 15"
233  << " (not allowed!) for following channels"
234  << " (Crate/FEC/slot/ring/CCU/LLD): ";
235  std::vector<SiStripFecKey>::iterator ikey = invalid.begin();
236  std::vector<SiStripFecKey>::iterator jkey = invalid.end();
237  for (; ikey != jkey; ++ikey) {
238  ss << ikey->fecCrate() << "/" << ikey->fecSlot() << "/" << ikey->fecRing() << "/" << ikey->ccuAddr() << "/"
239  << ikey->ccuChan() << ", ";
240  }
241  edm::LogWarning(mlDqmClient_) << ss.str();
242  return false;
243  }
244 
245  edm::LogVerbatim(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
246  << " Updated PLL settings for " << updated << " modules";
247  return true;
248 }
249 
250 // -----------------------------------------------------------------------------
253  // do the core computation of delays per FED connection
254  computeDelays();
255 
256  // Retrieve FED ids from cabling
257  auto ids = cabling()->fedIds();
258 
259  // loop over the FED ids
260  for (SiStripConfigDb::FedDescriptionsV::const_iterator ifed = feds.begin(); ifed != feds.end(); ifed++) {
261  // If FED id not found in list (from cabling), then continue
262  if (find(ids.begin(), ids.end(), (*ifed)->getFedId()) == ids.end()) {
263  continue;
264  }
265  auto conns = cabling()->fedConnections((*ifed)->getFedId());
266  // loop over the connections for that FED
267  for (auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
268  // check that this is a tracker module
269  if (DetId(iconn->detId()).det() != DetId::Tracker)
270  continue;
271  // build the Fed9UAddress for that channel. Used to update the description.
272  Fed9U::Fed9UAddress fedChannel = Fed9U::Fed9UAddress(iconn->fedCh());
273  // retreive the current value for the delays
274  int fedDelayCoarse = (*ifed)->getCoarseDelay(fedChannel);
275  int fedDelayFine = (*ifed)->getFineDelay(fedChannel);
276  int fedDelay = int(fedDelayCoarse * 25. - fedDelayFine * 24. / 25.);
277  // extract the delay from the map
278  int delay = int(round(
280  iconn->fecCrate(), iconn->fecSlot(), iconn->fecRing(), iconn->ccuAddr(), iconn->ccuChan(), 0)
281  .key()]));
282  // compute the FED delay
283  // this is done by substracting the best (PLL) delay to the present value (from the db)
284  fedDelay -= delay;
285  fedDelayCoarse = (fedDelay / 25) + 1;
286  fedDelayFine = fedDelayCoarse * 25 - fedDelay;
287  if (fedDelayFine == 25) {
288  fedDelayFine = 0;
289  --fedDelayCoarse;
290  }
291  // update the FED delay
292  std::stringstream ss;
293  ss << "[FineDelayHistosUsingDb::" << __func__ << "]"
294  << " Updating the FED delay"
295  << " for loop FED id/ch " << (*ifed)->getFedId() << "/" << iconn->fedCh() << " from "
296  << (*ifed)->getCoarseDelay(fedChannel) << "/" << (*ifed)->getFineDelay(fedChannel) << " to ";
297  (*ifed)->setDelay(fedChannel, fedDelayCoarse, fedDelayFine);
298  ss << (*ifed)->getCoarseDelay(fedChannel) << "/" << (*ifed)->getFineDelay(fedChannel) << std::endl;
299  LogTrace(mlDqmClient_) << ss.str();
300  }
301  }
302 
303  edm::LogVerbatim(mlDqmClient_) << "[FineDelayHistosUsingDb::" << __func__ << "]"
304  << " Updated FED delay for " << ids.size() << " FEDs!";
305 }
306 
307 // -----------------------------------------------------------------------------
310  SamplingAnalysis* anal = dynamic_cast<SamplingAnalysis*>(analysis->second);
311  if (!anal) {
312  return;
313  }
314 
315  SiStripFecKey fec_key(anal->fecKey()); //@@ analysis->first
316  SiStripFedKey fed_key(anal->fedKey());
317 
318  FineDelayAnalysisDescription* tmp;
319  tmp = new FineDelayAnalysisDescription(anal->maximum(),
320  anal->error(),
321  0,
322  0,
323  0,
324  0,
325  0,
326  0,
327  db()->dbParams().partitions().begin()->second.partitionName(),
328  db()->dbParams().partitions().begin()->second.runNumber(),
329  anal->isValid(),
330  "",
331  fed_key.fedId(),
332  fed_key.feUnit(),
333  fed_key.feChan(),
334  fed_key.fedApv());
335 
336  // Add comments
337  typedef std::vector<std::string> Strings;
338  Strings errors = anal->getErrorCodes();
339  Strings::const_iterator istr = errors.begin();
340  Strings::const_iterator jstr = errors.end();
341  for (; istr != jstr; ++istr) {
342  tmp->addComments(*istr);
343  }
344 
345  // Store description
346  desc.push_back(tmp);
347 }
SiStripConfigDb::getDeviceDescriptions
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
Definition: DeviceDescriptions.cc:11
l1tstage2emulator_dqm_sourceclient-live_cfg.feds
feds
Definition: l1tstage2emulator_dqm_sourceclient-live_cfg.py:146
DDAxes::y
FineDelayHistosUsingDb::FineDelayHistosUsingDb
FineDelayHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const)
Definition: FineDelayHistosUsingDb.cc:23
FineDelayHistosUsingDb::tracker_
const TrackerGeometry * tracker_
Definition: FineDelayHistosUsingDb.h:34
MessageLogger.h
TrackerGeometry.h
SiStripConfigDb::DeviceDescriptionsRange
DeviceDescriptions::range DeviceDescriptionsRange
Definition: SiStripConfigDb.h:110
ESHandle.h
CommissioningHistograms::pset
const edm::ParameterSet & pset() const
Definition: CommissioningHistograms.h:163
sistrip::tracker_
static const char tracker_[]
Definition: ConstantsForGranularity.h:23
SiStripConfigDb::dbParams
const SiStripDbParams & dbParams() const
Definition: SiStripConfigDb.h:421
SamplingAnalysis
Analysis for latency run.
Definition: SamplingAnalysis.h:17
SiStripKey::key
const uint32_t & key() const
Definition: SiStripKey.h:120
SiStripConfigDb::deviceAddress
DeviceAddress deviceAddress(const deviceDescription &)
Definition: DeviceDescriptions.cc:503
edm
HLT enums.
Definition: AlignableModifier.h:19
SiStripConfigDb::getFedDescriptions
FedDescriptionsRange getFedDescriptions(std::string partition="")
Definition: FedDescriptions.cc:12
SiStripConfigDb::uploadFedDescriptions
void uploadFedDescriptions(std::string partition="")
Definition: FedDescriptions.cc:197
CommissioningHistosUsingDb::cabling
SiStripFedCabling *const cabling() const
Definition: CommissioningHistosUsingDb.h:94
SiStripFedCabling.h
GeomDetType.h
DDAxes::x
SiStripFecKey::fecCrate
const uint16_t & fecCrate() const
Definition: SiStripFecKey.h:198
SiStripFedKey
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
CTPPSpixelLocalTrackReconstructionInfo::invalid
CommissioningHistograms::data
Analyses & data(bool getMaskedData=false)
Definition: CommissioningHistograms.cc:718
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
Strings
std::vector< std::string > Strings
Definition: MsgTools.h:18
CommissioningHistosUsingDb
Definition: CommissioningHistosUsingDb.h:16
sistrip::mlDqmClient_
static const char mlDqmClient_[]
Definition: ConstantsForLogger.h:19
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
SiStripConfigDb::clearFedDescriptions
void clearFedDescriptions(std::string partition="")
Definition: FedDescriptions.cc:268
SamplingHistograms
Definition: SamplingHistograms.h:9
FineDelayHistosUsingDb.h
TrackerGeometry::idToDetUnit
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: TrackerGeometry.cc:183
sistrip::FINE_DELAY
Definition: ConstantsForRunType.h:85
FineDelayHistosUsingDb::uploadConfigurations
void uploadConfigurations() override
Definition: FineDelayHistosUsingDb.cc:54
dqmiodatasetharvest.db
db
Definition: dqmiodatasetharvest.py:119
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
DetId
Definition: DetId.h:17
SiStripConfigDb::FedDescriptionsRange
FedDescriptions::range FedDescriptionsRange
Definition: SiStripConfigDb.h:116
generateTowerEtThresholdLUT.addr
addr
Definition: generateTowerEtThresholdLUT.py:57
dqm::legacy::DQMStore
Definition: DQMStore.h:727
errors
Definition: errors.py:1
SiStripFecKey::fecRing
const uint16_t & fecRing() const
Definition: SiStripFecKey.h:200
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
FineDelayHistosUsingDb::update
bool update(SiStripConfigDb::DeviceDescriptionsRange)
Definition: FineDelayHistosUsingDb.cc:163
DDAxes::z
edm::ESHandle< TrackerGeometry >
SiStripConfigDb
An interface class to the DeviceFactory.
Definition: SiStripConfigDb.h:47
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
FineDelayHistosUsingDb::create
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis) override
Definition: FineDelayHistosUsingDb.cc:309
Point3DBase< float, GlobalTag >
GeomDet::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
SamplingHistograms::configure
void configure(const edm::ParameterSet &, const edm::EventSetup &) override
Definition: SamplingHistograms.cc:81
SiStripFecKey
Utility class that identifies a position within the strip tracker control structure,...
Definition: SiStripFecKey.h:45
SiStripFecKey.h
SiStripConfigDb::uploadDeviceDescriptions
void uploadDeviceDescriptions(std::string partition="")
Definition: DeviceDescriptions.cc:264
SiStripFecKey::ccuChan
const uint16_t & ccuChan() const
Definition: SiStripFecKey.h:202
edm::LogWarning
Definition: MessageLogger.h:141
TrackerDigiGeometryRecord.h
SiStripConstants.h
SiStripFedKey.h
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
DetId::Tracker
Definition: DetId.h:25
ParameterSet
Definition: Functions.h:16
CommissioningHistosUsingDb::configure
void configure(const edm::ParameterSet &, const edm::EventSetup &) override
Definition: CommissioningHistosUsingDb.cc:56
FineDelayHistosUsingDb::delays_
std::map< unsigned int, float > delays_
Definition: FineDelayHistosUsingDb.h:32
SiStripDbParams::partitions
const_iterator_range partitions() const
Definition: SiStripDbParams.h:178
createfilelist.int
int
Definition: createfilelist.py:10
edm::LogVerbatim
Definition: MessageLogger.h:297
CommissioningHistosUsingDb::doUploadConf
bool doUploadConf() const
Definition: CommissioningHistosUsingDb.h:91
edm::EventSetup
Definition: EventSetup.h:57
sistrip::invalid_
static const uint16_t invalid_
Definition: Constants.h:16
CommissioningHistograms
Definition: CommissioningHistograms.h:23
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
get
#define get
FineDelayHistosUsingDb::computeDelays
void computeDelays()
Definition: FineDelayHistosUsingDb.cc:105
PV3DBase::mag
T mag() const
Definition: PV3DBase.h:64
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
GeomDet.h
FineDelayHistosUsingDb::cosmic_
bool cosmic_
Definition: FineDelayHistosUsingDb.h:36
FedChannelConnection.h
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
SiStripFecKey::ccuAddr
const uint16_t & ccuAddr() const
Definition: SiStripFecKey.h:201
SiStripConfigDb::AnalysisDescriptionsV
std::vector< AnalysisDescription * > AnalysisDescriptionsV
Definition: SiStripConfigDb.h:135
SiStripFedCablingRcd.h
CommissioningHistosUsingDb::db
SiStripConfigDb *const db() const
Definition: CommissioningHistosUsingDb.h:93
SiStripFedCabling::fedIds
FedsConstIterRange fedIds() const
Definition: SiStripFedCabling.h:154
alcaDQMUpload.upload
def upload(url, args, files)
Definition: alcaDQMUpload.py:65
phase2TrackerDigitizer_cfi.delay
delay
Definition: phase2TrackerDigitizer_cfi.py:67
SiStripConfigDb::DeviceAddress
Definition: SiStripConfigDb.h:141
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
SiStripConfigDb::clearDeviceDescriptions
void clearDeviceDescriptions(std::string partition="")
Definition: DeviceDescriptions.cc:335
FineDelayHistosUsingDb::~FineDelayHistosUsingDb
~FineDelayHistosUsingDb() override
Definition: FineDelayHistosUsingDb.cc:35
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
conversion_template_cfg.anal
anal
Definition: conversion_template_cfg.py:16
SiStripFecKey::fecSlot
const uint16_t & fecSlot() const
Definition: SiStripFecKey.h:199
SiStripFedCabling::fedConnections
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Definition: SiStripFedCabling.cc:160
crabWrapper.key
key
Definition: crabWrapper.py:19
CommissioningHistograms::Analysis
Analyses::iterator Analysis
Definition: CommissioningHistograms.h:58
GlobalPoint.h
Topology.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
FineDelayHistosUsingDb::configure
void configure(const edm::ParameterSet &, const edm::EventSetup &) override
Definition: FineDelayHistosUsingDb.cc:42