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