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