CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelPortCardConfig.cc
Go to the documentation of this file.
1 //
2 // This class specifies the settings on the TKPCIFEC
3 // and the settings on the portcard
4 //
5 //
6 //
7 //
8 
12 #include <fstream>
13 #include <sstream>
14 #include <iostream>
15 #include <string>
16 #include <vector>
17 #include <assert.h>
18 #include <stdexcept>
19 #include <set>
20 
21 using namespace std;
22 using namespace pos::PortCardSettingNames;
23 using namespace pos;
24 
25 //added by Umesh
26 PixelPortCardConfig::PixelPortCardConfig(vector < vector< string> > &tableMat):PixelConfigBase(" "," "," ")
27 {
28  string mthn = "]\t[PixelPortCardConfig::PixelPortCardConfig()]\t\t " ;
29  map<string , int > colM;
30  vector<string> colNames;
31 
123  colNames.push_back("CONFIG_KEY" );
124  colNames.push_back("KEY_TYPE" );
125  colNames.push_back("KEY_ALIAS" );
126  colNames.push_back("VERSION" );
127  colNames.push_back("KIND_OF_COND");
128  colNames.push_back("PORT_CARD" );
129  colNames.push_back("TRKFEC" );
130  colNames.push_back("RING" );
131  colNames.push_back("CHANNEL" );
132  colNames.push_back("CCU_ADDR" );
133  colNames.push_back("I2C_CNTRL" );
134  colNames.push_back("I2C_SPEED" );
135  colNames.push_back("AOH_BIAS1" );
136  colNames.push_back("AOH_BIAS2" );
137  colNames.push_back("AOH_BIAS3" );
138  colNames.push_back("AOH_BIAS4" );
139  colNames.push_back("AOH_BIAS5" );
140  colNames.push_back("AOH_BIAS6" );
141  colNames.push_back("AOH_GAIN1" );
142  colNames.push_back("AOH_GAIN2" );
143  colNames.push_back("AOH_GAIN3" );
144  colNames.push_back("AOH_GAIN4" );
145  colNames.push_back("AOH_GAIN5" );
146  colNames.push_back("AOH_GAIN6" );
147  colNames.push_back("AOH1_BIAS1" );
148  colNames.push_back("AOH1_BIAS2" );
149  colNames.push_back("AOH1_BIAS3" );
150  colNames.push_back("AOH1_BIAS4" );
151  colNames.push_back("AOH1_BIAS5" );
152  colNames.push_back("AOH1_BIAS6" );
153  colNames.push_back("AOH1_GAIN1" );
154  colNames.push_back("AOH1_GAIN2" );
155  colNames.push_back("AOH1_GAIN3" );
156  colNames.push_back("AOH1_GAIN4" );
157  colNames.push_back("AOH1_GAIN5" );
158  colNames.push_back("AOH1_GAIN6" );
159  colNames.push_back("AOH2_BIAS1" );
160  colNames.push_back("AOH2_BIAS2" );
161  colNames.push_back("AOH2_BIAS3" );
162  colNames.push_back("AOH2_BIAS4" );
163  colNames.push_back("AOH2_BIAS5" );
164  colNames.push_back("AOH2_BIAS6" );
165  colNames.push_back("AOH2_GAIN1" );
166  colNames.push_back("AOH2_GAIN2" );
167  colNames.push_back("AOH2_GAIN3" );
168  colNames.push_back("AOH2_GAIN4" );
169  colNames.push_back("AOH2_GAIN5" );
170  colNames.push_back("AOH2_GAIN6" );
171  colNames.push_back("AOH3_BIAS1" );
172  colNames.push_back("AOH3_BIAS2" );
173  colNames.push_back("AOH3_BIAS3" );
174  colNames.push_back("AOH3_BIAS4" );
175  colNames.push_back("AOH3_BIAS5" );
176  colNames.push_back("AOH3_BIAS6" );
177  colNames.push_back("AOH3_GAIN1" );
178  colNames.push_back("AOH3_GAIN2" );
179  colNames.push_back("AOH3_GAIN3" );
180  colNames.push_back("AOH3_GAIN4" );
181  colNames.push_back("AOH3_GAIN5" );
182  colNames.push_back("AOH3_GAIN6" );
183  colNames.push_back("AOH4_BIAS1" );
184  colNames.push_back("AOH4_BIAS2" );
185  colNames.push_back("AOH4_BIAS3" );
186  colNames.push_back("AOH4_BIAS4" );
187  colNames.push_back("AOH4_BIAS5" );
188  colNames.push_back("AOH4_BIAS6" );
189  colNames.push_back("AOH4_GAIN1" );
190  colNames.push_back("AOH4_GAIN2" );
191  colNames.push_back("AOH4_GAIN3" );
192  colNames.push_back("AOH4_GAIN4" );
193  colNames.push_back("AOH4_GAIN5" );
194  colNames.push_back("AOH4_GAIN6" );
195  colNames.push_back("DELAY25_GCR" );
196  colNames.push_back("DELAY25_SCL" );
197  colNames.push_back("DELAY25_TRG" );
198  colNames.push_back("DELAY25_SDA" );
199  colNames.push_back("DELAY25_RCL" );
200  colNames.push_back("DELAY25_RDA" );
201  colNames.push_back("DOH_BIAS0" );
202  colNames.push_back("DOH_BIAS1" );
203  colNames.push_back("DOH_SEU_GAIN");
204  colNames.push_back("PLL_CTR1" );
205  colNames.push_back("PLL_CTR2" );
206  colNames.push_back("PLL_CTR3" );
207  colNames.push_back("PLL_CTR4" );
208  colNames.push_back("PLL_CTR5" );
209 
210  //these are arbitrary integers that control the sort order
211  unsigned int othercount=100;
212  unsigned int delay25count=50;
213  aohcount_=1000;
214  unsigned int pllcount=1;
215 
216  for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
217  {
218  for(unsigned int n=0; n<colNames.size(); n++)
219  {
220  if(tableMat[0][c] == colNames[n]){
221  colM[colNames[n]] = c;
222  break;
223  }
224  }
225  }//end for
226  for(unsigned int n=0; n<colNames.size(); n++)
227  {
228  if(colM.find(colNames[n]) == colM.end())
229  {
230  std::cerr << __LINE__ << mthn << "\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
231  assert(0);
232  }
233  }
234 
235  portcardname_ = tableMat[1][colM["PORT_CARD"]] ;
236 // cout << __LINE__ << mthn << "Loading PortCard " << portcardname_ << endl ;
237  if(portcardname_.find("FPix") != std::string::npos)
238  {
239  type_ = "fpix" ;
240  }
241  else if(portcardname_.find("BPix") != std::string::npos)
242  {
243  type_ = "bpix" ;
244  }
245  fillNameToAddress();
246  fillDBToFileAddress() ;
247 
248  TKFECID_ = tableMat[1][colM["TRKFEC"]] ;
249  ringAddress_ = atoi(tableMat[1][colM["RING"]].c_str() ) ;
250  ccuAddress_ = atoi(tableMat[1][colM["CCU_ADDR"]].c_str() ) ;
251  channelAddress_ = atoi(tableMat[1][colM["CHANNEL"]].c_str() ) ;
252  i2cSpeed_ = atoi(tableMat[1][colM["I2C_SPEED"]].c_str() ) ;
253 /*
254  cout << __LINE__ << "]\t" << mthn <<
255  "ringAddress_\t" << ringAddress_ << endl <<
256  "ccuAddress_\t" << ccuAddress_ << endl <<
257  "channelAddress_\t" << channelAddress_ << endl <<
258  "i2cSpeed_\t" << i2cSpeed_ << endl ;
259  */
260 
261 
262  for(unsigned int col = 0 ; col < tableMat[1].size() ; col++) //Goes to every column of the Matrix
263  {
264  std::string settingName;
265  unsigned int i2c_address;
266  unsigned int i2c_values;
267 
268  settingName = tableMat[0][col] ;
269  i2c_values = atoi(tableMat[1][col].c_str()) ;
270 
271  // Special handling for AOHX_GainY
272  if( type_ == "fpix" && settingName.find("AOH_") != string::npos && settingName.find("GAIN") != string::npos // contains both "AOH_" and "Gain"
273  && settingName.find("123") == string::npos && settingName.find("456") == string::npos ) // does not contain "123" or "456"
274  {
275  setDataBaseAOHGain(settingName, i2c_values);
276  // cout << __LINE__ << "]\t" << mthn << "Setting " << settingName << "\tto value " << std::hex << i2c_values << std::dec << std::endl ;
277  }
278  else if(type_ == "bpix" && settingName.find("AOH") != string::npos && settingName.find("GAIN") != string::npos // contains both "AOH" and "Gain"
279  && settingName.find("AOH_") == string::npos // must not contain AOH_ 'cause this is for forward
280  && settingName.find("123") == string::npos && settingName.find("456") == string::npos ) // does not contain "123" or "456"
281  {
282  if(portcardname_.find("PRT2")!=std::string::npos &&
283  (settingName.find("AOH3_")!=std::string::npos ||
284  settingName.find("AOH4_")!=std::string::npos ) ) continue ;
285  setDataBaseAOHGain(settingName, i2c_values);
286  // cout << __LINE__ << "]\t" << mthn << "Setting " << settingName << "\tto value " << std::hex << i2c_values << std::dec << std::endl ;
287  }
288  // FIXMR
289  else if ( settingName == k_PLL_CTR5 ) // special handling
290  {
291  unsigned int last_CTR2 = 0x0;
292  if ( containsSetting(k_PLL_CTR2) ) last_CTR2 = getdeviceValuesForSetting( k_PLL_CTR2 );
293 
294  device_.push_back( make_pair(getdeviceAddressForSetting(k_PLL_CTR2), new_PLL_CTR2_value(settingName, last_CTR2)) );
295  device_.push_back( make_pair(getdeviceAddressForSetting(k_PLL_CTR4or5), i2c_values) );
296 
297  key_.push_back( pllcount++); //these are arbitrary integers that control the sort order
298  key_.push_back(pllcount++);
299  }
300  // FIXMR
301  else // no special handling for this name
302  {
303  if((settingName.find("DELAY25_") != std::string::npos) ||
304  (settingName.find("_BIAS") != std::string::npos) ||
305  (settingName.find("PLL_CTR2") != std::string::npos) ||
306  (settingName.find("PLL_CTR5") != std::string::npos) ||
307  ((settingName.find("DOH_SEU_GAIN") != std::string::npos) && type_=="bpix"))
308  //Note that DOH_SEU_GAIN will be *ignored* for fpix
309  {
310  map<string,string>::iterator iter = nameDBtoFileConversion_.find(settingName);
311  if(iter == nameDBtoFileConversion_.end()) continue ;
312  map<string, unsigned int>::iterator foundName_itr = nameToAddress_.find(nameDBtoFileConversion_[settingName]);
313 
314  if ( foundName_itr != nameToAddress_.end() )
315  {
316  if(portcardname_.find("PRT2")!=std::string::npos &&
317  (settingName.find("AOH3_")!=std::string::npos ||
318  settingName.find("AOH4_")!=std::string::npos )) continue ;
319  i2c_address = foundName_itr->second;
320  }
321  else
322  {
323  i2c_address = strtoul(settingName.c_str(), 0, 16); // convert string to integer using base 16
324  }
325  if(type_ == "fpix" &&
326  (
327  settingName.find("AOH1_")!=std::string::npos ||
328  settingName.find("AOH2_")!=std::string::npos ||
329  settingName.find("AOH3_")!=std::string::npos ||
330  settingName.find("AOH4_")!=std::string::npos
331  )
332  ) continue ;
333 
334  pair<unsigned int, unsigned int> p(i2c_address, i2c_values);
335  /*
336  cout << __LINE__
337  << mthn << "Setting\t"
338  << "|"
339  << settingName
340  << "|->"
341  << nameDBtoFileConversion_[settingName]
342  << "\twith pair:\t("
343  << i2c_address
344  << ","
345  << i2c_values
346  << ")"
347  << endl ;
348  */
349  device_.push_back(p);
350  if (settingName.find("AOH")!=string::npos) key_.push_back(aohcount_++);
351  else if (settingName.find("Delay25")!=string::npos) key_.push_back(delay25count++);
352  else if (settingName.find("PLL")!=string::npos) key_.push_back(pllcount++);
353  else key_.push_back(othercount++);
354 
355  }
356  }
357  } // End of table columns
358 
359 
360  sortDeviceList();
361 
362 }
363 
364 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
366  PixelConfigBase(" "," "," "){
367 
368  string mthn = "[PixelPortCardConfig::PixelPortCardConfig()]\t\t " ;
369  //std::cout << __LINE__ << "]\t" << mthn << "filename:"<<filename<<std::endl;
370 
371  size_t portcardpos=filename.find(std::string("portcard_"));
372  //std::cout << __LINE__ << "]\t" << mthn << "portcardpos:"<<portcardpos<<std::endl;
373  assert(portcardpos!=std::string::npos);
374  size_t datpos=filename.find(std::string(".dat"));
375  //std::cout << __LINE__ << "]\t" << mthn << "datpos:"<<datpos<<std::endl;
376  assert(datpos!=std::string::npos);
377  assert(datpos>portcardpos);
378 
379  portcardname_=filename.substr(portcardpos+9,datpos-portcardpos-9);
380 
381  //std::cout << "Portcard name extracted from file name:"<<portcardname_<<std::endl;
382 
383  std::ifstream in(filename.c_str());
384 
385  if(!in.good()){
386  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
387  throw std::runtime_error("Failed to open file "+filename);
388  }
389  else {
390  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
391  }
392 
393  string dummy;
394 
395  in >> dummy;
396  if ( dummy == "Name:" ) // check that port card name matches the file name
397  {
398  in >> dummy; assert( dummy==portcardname_ );
399  in >> dummy;
400  }
401  if ( dummy == "Type:" ) // read in the type, defaulting to "fpix" if not specified
402  {
403  in >> type_;
404  assert( type_ == "fpix" || type_ == "bpix" );
405  in >> dummy;
406  }
407  else
408  {
409  type_ = "fpix";
410  }
413  assert(dummy=="TKFECID:"); in >> TKFECID_;
414  in >> dummy; assert(dummy=="ringAddress:"); in >> std::hex >> ringAddress_;
415  in >> dummy; assert(dummy=="ccuAddress:"); in >> std::hex >> ccuAddress_;
416  in >> dummy; assert(dummy=="channelAddress:"); in >> std::hex >> channelAddress_;
417  in >> dummy; assert(dummy=="i2cSpeed:"); in >> std::hex >> i2cSpeed_;
418 
419  //std::cout << __LINE__ << "]\t" << mthn
420  // <<TKFECAddress_<<", "<<ringAddress_<<", "<<ccuAddress_<<", "<<channelAddress_<<", "<<i2cSpeed_<<std::endl;
421 
422  assert( nameToAddress_.size() != 0 );
423  do {
424 
425  std::string settingName;
426  unsigned int i2c_address;
427  unsigned int i2c_values;
428 
429  in >> settingName >> std::hex >> i2c_values >> std::dec;
430  if (in.eof()) break;
431 
432  if ( settingName[settingName.size()-1] == ':' ) settingName.resize( settingName.size()-1 ); // remove ':' from end of string, if it's there
433 
434  // Special handling for AOHX_GainY
435  if ( settingName.find("AOH") != string::npos && settingName.find("Gain") != string::npos // contains both "AOH" and "Gain"
436  && settingName.find("123") == string::npos && settingName.find("456") == string::npos ) // does not contain "123" or "456"
437  {
438  setAOHGain(settingName, i2c_values);
439  }
440  else if ( settingName == k_PLL_CTR4 || settingName == k_PLL_CTR5 ) // special handling
441  {
442  unsigned int last_CTR2 = 0x0;
444 
445  device_.push_back( make_pair(getdeviceAddressForSetting(k_PLL_CTR2), new_PLL_CTR2_value(settingName, last_CTR2)) );
446  device_.push_back( make_pair(getdeviceAddressForSetting(k_PLL_CTR4or5), i2c_values) );
447  }
448  else // no special handling for this name
449  {
450  std::map<std::string, unsigned int>::iterator foundName_itr = nameToAddress_.find(settingName);
451 
452  if ( foundName_itr != nameToAddress_.end() )
453  {
454  i2c_address = foundName_itr->second;
455  }
456  else
457  {
458  i2c_address = strtoul(settingName.c_str(), 0, 16); // convert string to integer using base 16
459  }
460  pair<unsigned int, unsigned int> p(i2c_address, i2c_values);
461  device_.push_back(p);
462  }
463  }
464  while (!in.eof());
465 
466  in.close();
467 
468 }
469 
471 
472  std::set < pair < unsigned int, pair <unsigned int, unsigned int> > > sorted;
473 
474  for (unsigned int i=0; i<device_.size(); i++ ) {
475  //cout<<key_.at(i)<<"\t"<<device_.at(i).first<<" "<<device_.at(i).second<<endl;
476  sorted.insert( make_pair(key_.at(i) , device_.at(i) ));
477  }
478 
479 // cout<<" -=-=-=-= done with sorting -=-=-="<<endl;
480  device_.clear();
481  for ( set < pair < unsigned int, pair <unsigned int, unsigned int> > >::iterator i=sorted.begin() ; i!=sorted.end() ; ++i) {
482  device_.push_back(i->second);
483  }
484 
485  // for (unsigned int i=0; i<device_.size(); i++ ) {
486  // cout<<" \t"<<device_.at(i).first<<" "<<device_.at(i).second<<endl;
487  // }
488 
489 }
490 
491 
492 unsigned int PixelPortCardConfig::new_PLL_CTR2_value(std::string CTR4or5, unsigned int last_CTR2) const
493 {
494  if ( CTR4or5 == k_PLL_CTR4 ) return 0xdf & last_CTR2;
495  else if ( CTR4or5 == k_PLL_CTR5 ) return 0x20 | last_CTR2;
496  else assert(0);
497 }
498 
499 void PixelPortCardConfig::setAOHGain(std::string settingName, unsigned int value)
500 {
501  assert( settingName.find("AOH") != string::npos && settingName.find("Gain") != string::npos // contains both "AOH" and "Gain"
502  && settingName.find("123") == string::npos && settingName.find("456") == string::npos ); // does not contain "123" or "456"
503 
504  unsigned int i2c_address;
505 
506  // Get the i2c address of this AOH, and the channel on the AOH.
507  string::size_type GainPosition = settingName.find("Gain");
508  unsigned int whichAOH;
509  if ( settingName[GainPosition-2] == 'H' ) whichAOH = 0; // fpix
510  else // bpix
511  {
512  char whichAOHDigit[2]={0,0};
513  whichAOHDigit[0]=settingName[GainPosition-2];
514  whichAOH = atoi( whichAOHDigit );
515  }
516  char digit[2]={0,0};
517  digit[0]=settingName[GainPosition+4];
518  unsigned int channelOnAOH = atoi( digit );
519  assert( (type_=="fpix" && whichAOH==0)||(type_=="bpix" && 1 <= whichAOH&&whichAOH <= 4) );
520  assert( 1 <= channelOnAOH && channelOnAOH <= 6 );
521 
522  if ( whichAOH == 0 && channelOnAOH <= 3 ) i2c_address = k_fpix_AOH_Gain123_address;
523  else if ( whichAOH == 0 && channelOnAOH >= 4 ) i2c_address = k_fpix_AOH_Gain456_address;
524  else if ( whichAOH == 1 && channelOnAOH <= 3 ) i2c_address = k_bpix_AOH1_Gain123_address;
525  else if ( whichAOH == 1 && channelOnAOH >= 4 ) i2c_address = k_bpix_AOH1_Gain456_address;
526  else if ( whichAOH == 2 && channelOnAOH <= 3 ) i2c_address = k_bpix_AOH2_Gain123_address;
527  else if ( whichAOH == 2 && channelOnAOH >= 4 ) i2c_address = k_bpix_AOH2_Gain456_address;
528  else if ( whichAOH == 3 && channelOnAOH <= 3 ) i2c_address = k_bpix_AOH3_Gain123_address;
529  else if ( whichAOH == 3 && channelOnAOH >= 4 ) i2c_address = k_bpix_AOH3_Gain456_address;
530  else if ( whichAOH == 4 && channelOnAOH <= 3 ) i2c_address = k_bpix_AOH4_Gain123_address;
531  else if ( whichAOH == 4 && channelOnAOH >= 4 ) i2c_address = k_bpix_AOH4_Gain456_address;
532  else assert(0);
533 
534  // Search for this address in the previously-defined settings.
535  bool foundOne = false;
536  for (unsigned int i=0;i<device_.size();i++)
537  {
538  if ( device_[i].first == i2c_address ) // Change this setting in all previous instances
539  {
540  foundOne = true;
541  unsigned int oldValue = device_[i].second;
542  if ( channelOnAOH%3 == 1 )
543  device_[i].second = (0x3c & oldValue) + ((value & 0x3)<<0); // replace bits 0 and 1 with value
544  else if ( channelOnAOH%3 == 2 )
545  device_[i].second = (0x33 & oldValue) + ((value & 0x3)<<2); // replace bits 2 and 3 with value
546  else if ( channelOnAOH%3 == 0 )
547  device_[i].second = (0x0f & oldValue) + ((value & 0x3)<<4); // replace bits 4 and 5 with value
548  else assert(0);
549  //std::cout << "Changed setting "<< k_fpix_AOH_Gain123 <<"(address 0x"<<std::hex<<k_fpix_AOH_Gain123_address<<") from 0x"<<oldValue<<" to 0x"<< device_[i].second << std::dec <<"\n";
550  }
551  }
552  if ( foundOne ) return;
553  else // If this was not set previously, add this setting with the other two gains set to zero.
554  {
555  unsigned int i2c_value;
556  if ( channelOnAOH%3 == 1 ) i2c_value = ((value & 0x3)<<0);
557  else if ( channelOnAOH%3 == 2 ) i2c_value = ((value & 0x3)<<2);
558  else if ( channelOnAOH%3 == 0 ) i2c_value = ((value & 0x3)<<4);
559  else assert(0);
560 
561  pair<unsigned int, unsigned int> p(i2c_address, i2c_value);
562  device_.push_back(p);
563  return;
564  }
565 }
566 
567 void PixelPortCardConfig::setDataBaseAOHGain(std::string settingName, unsigned int value)
568 {
569  unsigned int i2c_address;
570 
571  // Get the i2c address of this AOH, and the channel on the AOH.
572  string::size_type GainPosition = settingName.find("GAIN");
573  unsigned int whichAOH;
574  if(type_ == "fpix")
575  {
576  whichAOH = 0 ; // fpix
577  }
578  else // bpix
579  {
580  char whichAOHDigit[2]={0,0};
581  whichAOHDigit[0]=settingName[GainPosition-2];
582  whichAOH = atoi( whichAOHDigit );
583  }
584  char digit[2]={0,0};
585  digit[0]=settingName[GainPosition+4];
586  unsigned int channelOnAOH = atoi( digit );
587  assert( (type_=="fpix" && whichAOH==0)||(type_=="bpix" && 1 <= whichAOH&&whichAOH <= 4) );
588  assert( 1 <= channelOnAOH && channelOnAOH <= 6 );
589 
590  if ( whichAOH == 0 && channelOnAOH <= 3 ) i2c_address = k_fpix_AOH_Gain123_address;
591  else if ( whichAOH == 0 && channelOnAOH >= 4 ) i2c_address = k_fpix_AOH_Gain456_address;
592  else if ( whichAOH == 1 && channelOnAOH <= 3 ) i2c_address = k_bpix_AOH1_Gain123_address;
593  else if ( whichAOH == 1 && channelOnAOH >= 4 ) i2c_address = k_bpix_AOH1_Gain456_address;
594  else if ( whichAOH == 2 && channelOnAOH <= 3 ) i2c_address = k_bpix_AOH2_Gain123_address;
595  else if ( whichAOH == 2 && channelOnAOH >= 4 ) i2c_address = k_bpix_AOH2_Gain456_address;
596  else if ( whichAOH == 3 && channelOnAOH <= 3 ) i2c_address = k_bpix_AOH3_Gain123_address;
597  else if ( whichAOH == 3 && channelOnAOH >= 4 ) i2c_address = k_bpix_AOH3_Gain456_address;
598  else if ( whichAOH == 4 && channelOnAOH <= 3 ) i2c_address = k_bpix_AOH4_Gain123_address;
599  else if ( whichAOH == 4 && channelOnAOH >= 4 ) i2c_address = k_bpix_AOH4_Gain456_address;
600  else assert(0);
601 
602  // Search for this address in the previously-defined settings.
603  bool foundOne = false;
604  for (unsigned int i=0;i<device_.size();i++)
605  {
606  if ( device_[i].first == i2c_address ) // Change this setting in all previous instances
607  {
608  foundOne = true;
609  unsigned int oldValue = device_[i].second;
610  if ( channelOnAOH%3 == 1 )
611  device_[i].second = (0x3c & oldValue) + ((value & 0x3)<<0); // replace bits 0 and 1 with value
612  else if ( channelOnAOH%3 == 2 )
613  device_[i].second = (0x33 & oldValue) + ((value & 0x3)<<2); // replace bits 2 and 3 with value
614  else if ( channelOnAOH%3 == 0 )
615  device_[i].second = (0x0f & oldValue) + ((value & 0x3)<<4); // replace bits 4 and 5 with value
616  else assert(0);
617  //std::cout << "Changed setting "<< k_fpix_AOH_Gain123 <<"(address 0x"<<std::hex<<k_fpix_AOH_Gain123_address<<") from 0x"<<oldValue<<" to 0x"<< device_[i].second << std::dec <<"\n";
618  }
619  }
620  if ( foundOne ) return;
621  else // If this was not set previously, add this setting with the other two gains set to zero.
622  {
623  unsigned int i2c_value;
624  if ( channelOnAOH%3 == 1 ) i2c_value = ((value & 0x3)<<0);
625  else if ( channelOnAOH%3 == 2 ) i2c_value = ((value & 0x3)<<2);
626  else if ( channelOnAOH%3 == 0 ) i2c_value = ((value & 0x3)<<4);
627  else assert(0);
628 
629  pair<unsigned int, unsigned int> p(i2c_address, i2c_value);
630  device_.push_back(p);
631  key_.push_back(aohcount_++);
632  return;
633  }
634 }
635 
637 {
638  if ( nameToAddress_.size() != 0 ) return;
639 
640  if ( type_ == "fpix" )
641  {
650 
655 
662 
667  }
668  else if ( type_ == "bpix" )
669  {
678 
687 
696 
705 
710 
717 
722  }
723  else assert(0);
724 
725  return;
726 }
727 
729 {
730  if(type_ == "fpix")
731  {
732  // nameDBtoFileConversion_["CONFIG_KEY_ID" ] = ;
733  // nameDBtoFileConversion_["CONFIG_KEY" ] = ;
734  // nameDBtoFileConversion_["VERSION" ] = ;
735  // nameDBtoFileConversion_["CONDITION_DATA_SET_ID" ] = ;
736  // nameDBtoFileConversion_["KIND_OF_CONDITION_ID" ] = ;
737  // nameDBtoFileConversion_["KIND_OF_COND" ] = ;
738  // nameDBtoFileConversion_["SERIAL_NUMBER" ] = ;
739  // nameDBtoFileConversion_["PORT_CARD_ID" ] = ;
740  // nameDBtoFileConversion_["PORT_CARD" ] = ;
741  // nameDBtoFileConversion_["TRKFEC_NAME" ] = ;
742  // nameDBtoFileConversion_["RINGADDRESS" ] = ;
743  // nameDBtoFileConversion_["CHANNELADDRESS" ] = ;
744  // nameDBtoFileConversion_["CCUADDRESS" ] = ;
745  // nameDBtoFileConversion_["I2C_CNTRL" ] = ;
746  // nameDBtoFileConversion_["I2CSPEED" ] = ;
747  nameDBtoFileConversion_["AOH_BIAS1" ] = k_AOH_Bias1 ;
748  nameDBtoFileConversion_["AOH_BIAS2" ] = k_AOH_Bias2 ;
749  nameDBtoFileConversion_["AOH_BIAS3" ] = k_AOH_Bias3 ;
750  nameDBtoFileConversion_["AOH_BIAS4" ] = k_AOH_Bias4 ;
751  nameDBtoFileConversion_["AOH_BIAS5" ] = k_AOH_Bias5 ;
752  nameDBtoFileConversion_["AOH_BIAS6" ] = k_AOH_Bias6 ;
753  nameDBtoFileConversion_["AOH1_BIAS1" ] = k_AOH1_Bias1 ;
754  nameDBtoFileConversion_["AOH1_BIAS2" ] = k_AOH1_Bias2 ;
755  nameDBtoFileConversion_["AOH1_BIAS3" ] = k_AOH1_Bias3 ;
756  nameDBtoFileConversion_["AOH1_BIAS4" ] = k_AOH1_Bias4 ;
757  nameDBtoFileConversion_["AOH1_BIAS5" ] = k_AOH1_Bias5 ;
758  nameDBtoFileConversion_["AOH1_BIAS6" ] = k_AOH1_Bias6 ;
759 // nameDBtoFileConversion_["AOH1_GAIN1" ] = ;
760 // nameDBtoFileConversion_["AOH1_GAIN2" ] = ;
761 // nameDBtoFileConversion_["AOH1_GAIN3" ] = ;
762 // nameDBtoFileConversion_["AOH1_GAIN4" ] = ;
763 // nameDBtoFileConversion_["AOH1_GAIN5" ] = ;
764 // nameDBtoFileConversion_["AOH1_GAIN6" ] = ;
765  nameDBtoFileConversion_["AOH2_BIAS1" ] = k_AOH2_Bias1 ;
766  nameDBtoFileConversion_["AOH2_BIAS2" ] = k_AOH2_Bias2 ;
767  nameDBtoFileConversion_["AOH2_BIAS3" ] = k_AOH2_Bias3 ;
768  nameDBtoFileConversion_["AOH2_BIAS4" ] = k_AOH2_Bias4 ;
769  nameDBtoFileConversion_["AOH2_BIAS5" ] = k_AOH2_Bias5 ;
770  nameDBtoFileConversion_["AOH2_BIAS6" ] = k_AOH2_Bias6 ;
771 // nameDBtoFileConversion_["AOH2_GAIN1" ] = ;
772 // nameDBtoFileConversion_["AOH2_GAIN2" ] = ;
773 // nameDBtoFileConversion_["AOH2_GAIN3" ] = ;
774 // nameDBtoFileConversion_["AOH2_GAIN4" ] = ;
775 // nameDBtoFileConversion_["AOH2_GAIN5" ] = ;
776 // nameDBtoFileConversion_["AOH2_GAIN6" ] = ;
777  nameDBtoFileConversion_["AOH3_BIAS1" ] = k_AOH3_Bias1 ;
778  nameDBtoFileConversion_["AOH3_BIAS2" ] = k_AOH3_Bias2 ;
779  nameDBtoFileConversion_["AOH3_BIAS3" ] = k_AOH3_Bias3 ;
780  nameDBtoFileConversion_["AOH3_BIAS4" ] = k_AOH3_Bias4 ;
781  nameDBtoFileConversion_["AOH3_BIAS5" ] = k_AOH3_Bias5 ;
782  nameDBtoFileConversion_["AOH3_BIAS6" ] = k_AOH3_Bias6 ;
783 // nameDBtoFileConversion_["AOH3_GAIN1" ] = ;
784 // nameDBtoFileConversion_["AOH3_GAIN2" ] = ;
785 // nameDBtoFileConversion_["AOH3_GAIN3" ] = ;
786 // nameDBtoFileConversion_["AOH3_GAIN4" ] = ;
787 // nameDBtoFileConversion_["AOH3_GAIN5" ] = ;
788 // nameDBtoFileConversion_["AOH3_GAIN6" ] = ;
789  nameDBtoFileConversion_["AOH4_BIAS1" ] = k_AOH4_Bias1 ;
790  nameDBtoFileConversion_["AOH4_BIAS2" ] = k_AOH4_Bias2 ;
791  nameDBtoFileConversion_["AOH4_BIAS3" ] = k_AOH4_Bias3 ;
792  nameDBtoFileConversion_["AOH4_BIAS4" ] = k_AOH4_Bias4 ;
793  nameDBtoFileConversion_["AOH4_BIAS5" ] = k_AOH4_Bias5 ;
794  nameDBtoFileConversion_["AOH4_BIAS6" ] = k_AOH4_Bias6 ;
795 // nameDBtoFileConversion_["AOH4_GAIN1" ] = ;
796 // nameDBtoFileConversion_["AOH4_GAIN2" ] = ;
797 // nameDBtoFileConversion_["AOH4_GAIN3" ] = ;
798 // nameDBtoFileConversion_["AOH4_GAIN4" ] = ;
799 // nameDBtoFileConversion_["AOH4_GAIN5" ] = ;
800 // nameDBtoFileConversion_["AOH4_GAIN6" ] = ;
801 // nameDBtoFileConversion_["AOH5_BIAS1" ] = ;
802 // nameDBtoFileConversion_["AOH5_BIAS2" ] = ;
803 // nameDBtoFileConversion_["AOH5_BIAS3" ] = ;
804 // nameDBtoFileConversion_["AOH5_BIAS4" ] = ;
805 // nameDBtoFileConversion_["AOH5_BIAS5" ] = ;
806 // nameDBtoFileConversion_["AOH5_BIAS6" ] = ;
807 // nameDBtoFileConversion_["AOH5_GAIN1" ] = ;
808 // nameDBtoFileConversion_["AOH5_GAIN2" ] = ;
809 // nameDBtoFileConversion_["AOH5_GAIN3" ] = ;
810 // nameDBtoFileConversion_["AOH5_GAIN4" ] = ;
811 // nameDBtoFileConversion_["AOH5_GAIN5" ] = ;
812 // nameDBtoFileConversion_["AOH5_GAIN6" ] = ;
813 // nameDBtoFileConversion_["AOH6_BIAS1" ] = ;
814 // nameDBtoFileConversion_["AOH6_BIAS2" ] = ;
815 // nameDBtoFileConversion_["AOH6_BIAS3" ] = ;
816 // nameDBtoFileConversion_["AOH6_BIAS4" ] = ;
817 // nameDBtoFileConversion_["AOH6_BIAS5" ] = ;
818 // nameDBtoFileConversion_["AOH6_BIAS6" ] = ;
819 // nameDBtoFileConversion_["AOH6_GAIN1" ] = ;
820 // nameDBtoFileConversion_["AOH6_GAIN2" ] = ;
821 // nameDBtoFileConversion_["AOH6_GAIN3" ] = ;
822 // nameDBtoFileConversion_["AOH6_GAIN4" ] = ;
823 // nameDBtoFileConversion_["AOH6_GAIN5" ] = ;
824 // nameDBtoFileConversion_["AOH6_GAIN6" ] = ;
825  nameDBtoFileConversion_["DELAY25_GCR" ] = k_Delay25_GCR ;
826  nameDBtoFileConversion_["DELAY25_SCL" ] = k_Delay25_SCL ;
827  nameDBtoFileConversion_["DELAY25_TRG" ] = k_Delay25_TRG ;
828  nameDBtoFileConversion_["DELAY25_SDA" ] = k_Delay25_SDA ;
829  nameDBtoFileConversion_["DELAY25_RCL" ] = k_Delay25_RCL ;
830  nameDBtoFileConversion_["DELAY25_RDA" ] = k_Delay25_RDA ;
831  // nameDBtoFileConversion_["DEL3_GCR" ] = ;
832  // nameDBtoFileConversion_["DEL3_SCL" ] = ;
833  // nameDBtoFileConversion_["DEL3_TRG" ] = ;
834  // nameDBtoFileConversion_["DEL3_SDA" ] = ;
835  // nameDBtoFileConversion_["DEL3_RCL" ] = ;
836  // nameDBtoFileConversion_["DEL3_RDA" ] = ;
839  nameDBtoFileConversion_["DOH_SEU_GAIN" ] = k_DOH_Gain_SEU ;
840  // nameDBtoFileConversion_["DOH3_BIAS0" ] = ;
841  // nameDBtoFileConversion_["DOH3_BIAS1" ] = ;
842  // nameDBtoFileConversion_["DOH3_SEU_GAIN" ] = ;
843  nameDBtoFileConversion_["PLL_CTR1" ] = k_PLL_CTR1 ;
844  nameDBtoFileConversion_["PLL_CTR2" ] = k_PLL_CTR2 ;
845  nameDBtoFileConversion_["PLL_CTR3" ] = k_PLL_CTR3 ;
846  nameDBtoFileConversion_["PLL_CTR4" ] = k_PLL_CTR4 ;
847  nameDBtoFileConversion_["PLL_CTR5" ] = k_PLL_CTR5 ;
848  // nameDBtoFileConversion_["PLL3_CTR1" ] = ;
849  // nameDBtoFileConversion_["PLL3_CTR2" ] = ;
850  // nameDBtoFileConversion_["PLL3_CTR3" ] = ;
851  // nameDBtoFileConversion_["PLL3_CTR4_5" ] = ;
852  }
853  else if(type_ == "bpix")
854  {
855  // nameDBtoFileConversion_["CONFIG_KEY_ID" ] = ;
856  // nameDBtoFileConversion_["CONFIG_KEY" ] = ;
857  // nameDBtoFileConversion_["VERSION" ] = ;
858  // nameDBtoFileConversion_["CONDITION_DATA_SET_ID" ] = ;
859  // nameDBtoFileConversion_["KIND_OF_CONDITION_ID" ] = ;
860  // nameDBtoFileConversion_["KIND_OF_COND" ] = ;
861  // nameDBtoFileConversion_["SERIAL_NUMBER" ] = ;
862  // nameDBtoFileConversion_["PORT_CARD_ID" ] = ;
863  // nameDBtoFileConversion_["PORT_CARD" ] = ;
864  // nameDBtoFileConversion_["TRKFEC_NAME" ] = ;
865  // nameDBtoFileConversion_["RINGADDRESS" ] = ;
866  // nameDBtoFileConversion_["CHANNELADDRESS" ] = ;
867  // nameDBtoFileConversion_["CCUADDRESS" ] = ;
868  // nameDBtoFileConversion_["I2C_CNTRL" ] = ;
869  // nameDBtoFileConversion_["I2CSPEED" ] = ;
870  nameDBtoFileConversion_["AOH1_BIAS1" ] = k_AOH1_Bias1 ;
871  nameDBtoFileConversion_["AOH1_BIAS2" ] = k_AOH1_Bias2 ;
872  nameDBtoFileConversion_["AOH1_BIAS3" ] = k_AOH1_Bias3 ;
873  nameDBtoFileConversion_["AOH1_BIAS4" ] = k_AOH1_Bias4 ;
874  nameDBtoFileConversion_["AOH1_BIAS5" ] = k_AOH1_Bias5 ;
875  nameDBtoFileConversion_["AOH1_BIAS6" ] = k_AOH1_Bias6 ;
876  // nameDBtoFileConversion_["AOH1_GAIN1" ] = ;
877  // nameDBtoFileConversion_["AOH1_GAIN2" ] = ;
878  // nameDBtoFileConversion_["AOH1_GAIN3" ] = ;
879  // nameDBtoFileConversion_["AOH1_GAIN4" ] = ;
880  // nameDBtoFileConversion_["AOH1_GAIN5" ] = ;
881  // nameDBtoFileConversion_["AOH1_GAIN6" ] = ;
882  nameDBtoFileConversion_["AOH2_BIAS1" ] = k_AOH2_Bias1 ;
883  nameDBtoFileConversion_["AOH2_BIAS2" ] = k_AOH2_Bias2 ;
884  nameDBtoFileConversion_["AOH2_BIAS3" ] = k_AOH2_Bias3 ;
885  nameDBtoFileConversion_["AOH2_BIAS4" ] = k_AOH2_Bias4 ;
886  nameDBtoFileConversion_["AOH2_BIAS5" ] = k_AOH2_Bias5 ;
887  nameDBtoFileConversion_["AOH2_BIAS6" ] = k_AOH2_Bias6 ;
888  // nameDBtoFileConversion_["AOH2_GAIN1" ] = ;
889  // nameDBtoFileConversion_["AOH2_GAIN2" ] = ;
890  // nameDBtoFileConversion_["AOH2_GAIN3" ] = ;
891  // nameDBtoFileConversion_["AOH2_GAIN4" ] = ;
892  // nameDBtoFileConversion_["AOH2_GAIN5" ] = ;
893  // nameDBtoFileConversion_["AOH2_GAIN6" ] = ;
894  nameDBtoFileConversion_["AOH3_BIAS1" ] = k_AOH3_Bias1 ;
895  nameDBtoFileConversion_["AOH3_BIAS2" ] = k_AOH3_Bias2 ;
896  nameDBtoFileConversion_["AOH3_BIAS3" ] = k_AOH3_Bias3 ;
897  nameDBtoFileConversion_["AOH3_BIAS4" ] = k_AOH3_Bias4 ;
898  nameDBtoFileConversion_["AOH3_BIAS5" ] = k_AOH3_Bias5 ;
899  nameDBtoFileConversion_["AOH3_BIAS6" ] = k_AOH3_Bias6 ;
900  // nameDBtoFileConversion_["AOH3_GAIN1" ] = ;
901  // nameDBtoFileConversion_["AOH3_GAIN2" ] = ;
902  // nameDBtoFileConversion_["AOH3_GAIN3" ] = ;
903  // nameDBtoFileConversion_["AOH3_GAIN4" ] = ;
904  // nameDBtoFileConversion_["AOH3_GAIN5" ] = ;
905  // nameDBtoFileConversion_["AOH3_GAIN6" ] = ;
906  nameDBtoFileConversion_["AOH4_BIAS1" ] = k_AOH4_Bias1 ;
907  nameDBtoFileConversion_["AOH4_BIAS2" ] = k_AOH4_Bias2 ;
908  nameDBtoFileConversion_["AOH4_BIAS3" ] = k_AOH4_Bias3 ;
909  nameDBtoFileConversion_["AOH4_BIAS4" ] = k_AOH4_Bias4 ;
910  nameDBtoFileConversion_["AOH4_BIAS5" ] = k_AOH4_Bias5 ;
911  nameDBtoFileConversion_["AOH4_BIAS6" ] = k_AOH4_Bias6 ;
912  // nameDBtoFileConversion_["AOH4_GAIN1" ] = ;
913  // nameDBtoFileConversion_["AOH4_GAIN2" ] = ;
914  // nameDBtoFileConversion_["AOH4_GAIN3" ] = ;
915  // nameDBtoFileConversion_["AOH4_GAIN4" ] = ;
916  // nameDBtoFileConversion_["AOH4_GAIN5" ] = ;
917  // nameDBtoFileConversion_["AOH4_GAIN6" ] = ;
918  // nameDBtoFileConversion_["AOH5_BIAS1" ] = ;
919  // nameDBtoFileConversion_["AOH5_BIAS2" ] = ;
920  // nameDBtoFileConversion_["AOH5_BIAS3" ] = ;
921  // nameDBtoFileConversion_["AOH5_BIAS4" ] = ;
922  // nameDBtoFileConversion_["AOH5_BIAS5" ] = ;
923  // nameDBtoFileConversion_["AOH5_BIAS6" ] = ;
924  // nameDBtoFileConversion_["AOH5_GAIN1" ] = ;
925  // nameDBtoFileConversion_["AOH5_GAIN2" ] = ;
926  // nameDBtoFileConversion_["AOH5_GAIN3" ] = ;
927  // nameDBtoFileConversion_["AOH5_GAIN4" ] = ;
928  // nameDBtoFileConversion_["AOH5_GAIN5" ] = ;
929  // nameDBtoFileConversion_["AOH5_GAIN6" ] = ;
930  // nameDBtoFileConversion_["AOH6_BIAS1" ] = ;
931  // nameDBtoFileConversion_["AOH6_BIAS2" ] = ;
932  // nameDBtoFileConversion_["AOH6_BIAS3" ] = ;
933  // nameDBtoFileConversion_["AOH6_BIAS4" ] = ;
934  // nameDBtoFileConversion_["AOH6_BIAS5" ] = ;
935  // nameDBtoFileConversion_["AOH6_BIAS6" ] = ;
936  // nameDBtoFileConversion_["AOH6_GAIN1" ] = ;
937  // nameDBtoFileConversion_["AOH6_GAIN2" ] = ;
938  // nameDBtoFileConversion_["AOH6_GAIN3" ] = ;
939  // nameDBtoFileConversion_["AOH6_GAIN4" ] = ;
940  // nameDBtoFileConversion_["AOH6_GAIN5" ] = ;
941  // nameDBtoFileConversion_["AOH6_GAIN6" ] = ;
942  nameDBtoFileConversion_["DELAY25_GCR" ] = k_Delay25_GCR ;
943  nameDBtoFileConversion_["DELAY25_SCL" ] = k_Delay25_SCL ;
944  nameDBtoFileConversion_["DELAY25_TRG" ] = k_Delay25_TRG ;
945  nameDBtoFileConversion_["DELAY25_SDA" ] = k_Delay25_SDA ;
946  nameDBtoFileConversion_["DELAY25_RCL" ] = k_Delay25_RCL ;
947  nameDBtoFileConversion_["DELAY25_RDA" ] = k_Delay25_RDA ;
948  // nameDBtoFileConversion_["DEL3_GCR" ] = ;
949  // nameDBtoFileConversion_["DEL3_SCL" ] = ;
950  // nameDBtoFileConversion_["DEL3_TRG" ] = ;
951  // nameDBtoFileConversion_["DEL3_SDA" ] = ;
952  // nameDBtoFileConversion_["DEL3_RCL" ] = ;
953  // nameDBtoFileConversion_["DEL3_RDA" ] = ;
956  nameDBtoFileConversion_["DOH_SEU_GAIN" ] = k_DOH_Gain_SEU ;
957  // nameDBtoFileConversion_["DOH3_BIAS0" ] = ;
958  // nameDBtoFileConversion_["DOH3_BIAS1" ] = ;
959  // nameDBtoFileConversion_["DOH3_SEU_GAIN" ] = ;
960  nameDBtoFileConversion_["PLL_CTR1" ] = k_PLL_CTR1 ;
961  nameDBtoFileConversion_["PLL_CTR2" ] = k_PLL_CTR2 ;
962  nameDBtoFileConversion_["PLL_CTR3" ] = k_PLL_CTR3 ;
963  nameDBtoFileConversion_["PLL_CTR4" ] = k_PLL_CTR4 ;
964  nameDBtoFileConversion_["PLL_CTR5" ] = k_PLL_CTR5 ;
965  // nameDBtoFileConversion_["PLL3_CTR1" ] = ;
966  // nameDBtoFileConversion_["PLL3_CTR2" ] = ;
967  // nameDBtoFileConversion_["PLL3_CTR3" ] = ;
968  // nameDBtoFileConversion_["PLL3_CTR4_5" ] = ;
969  }
970 
971 
972 }
973 
974 
975 void PixelPortCardConfig::writeASCII(std::string dir) const {
976 
977  std::string mthn = "[PixelPortCardConfig::writeASCII()]\t\t\t\t " ;
978  if (dir!="") dir+="/";
979  std::string filename=dir+"portcard_"+portcardname_+".dat";
980 
981  std::ofstream out(filename.c_str());
982  if (!out.good()){
983  std::cout << __LINE__ << "]\t" << mthn << "Could not open file: " << filename.c_str() << std::endl;
984  assert(0);
985  }
986 
987  out << "Name: " << portcardname_ << std::endl;
988  out << "Type: " << type_ << std::endl;
989  out << "TKFECID: " << TKFECID_ << std::endl;
990  out << "ringAddress: 0x" <<std::hex<< ringAddress_ <<std::dec<< std::endl;
991  out << "ccuAddress: 0x" <<std::hex<< ccuAddress_ <<std::dec<< std::endl;
992 
993  out << "channelAddress: 0x" <<std::hex<< channelAddress_ <<std::dec<< std::endl;
994 
995  out << "i2cSpeed: 0x" <<std::hex<< i2cSpeed_ <<std::dec<< std::endl;
996 
997  bool found_PLL_CTR2 = false;
998  unsigned int last_PLL_CTR2_value = 0x0;
999  for (unsigned int i=0;i<device_.size();i++)
1000  {
1001  unsigned int deviceAddress = device_.at(i).first;
1002 
1003  // Special handling for AOH gains
1004  if ( ( type_=="fpix" && deviceAddress == k_fpix_AOH_Gain123_address )
1005  || ( type_=="fpix" && deviceAddress == k_fpix_AOH_Gain456_address )
1006  || ( type_=="bpix" && deviceAddress == k_bpix_AOH1_Gain123_address )
1007  || ( type_=="bpix" && deviceAddress == k_bpix_AOH1_Gain456_address )
1008  || ( type_=="bpix" && deviceAddress == k_bpix_AOH2_Gain123_address )
1009  || ( type_=="bpix" && deviceAddress == k_bpix_AOH2_Gain456_address )
1010  || ( type_=="bpix" && deviceAddress == k_bpix_AOH3_Gain123_address )
1011  || ( type_=="bpix" && deviceAddress == k_bpix_AOH3_Gain456_address )
1012  || ( type_=="bpix" && deviceAddress == k_bpix_AOH4_Gain123_address )
1013  || ( type_=="bpix" && deviceAddress == k_bpix_AOH4_Gain456_address )
1014  )
1015  {
1016  std::string whichAOHString;
1017  unsigned int zeroOrThree;
1018  if ( type_=="fpix" && deviceAddress == k_fpix_AOH_Gain123_address ) { whichAOHString = ""; zeroOrThree = 0; }
1019  else if ( type_=="fpix" && deviceAddress == k_fpix_AOH_Gain456_address ) { whichAOHString = ""; zeroOrThree = 3; }
1020  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH1_Gain123_address ) { whichAOHString = "1"; zeroOrThree = 0; }
1021  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH1_Gain456_address ) { whichAOHString = "1"; zeroOrThree = 3; }
1022  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH2_Gain123_address ) { whichAOHString = "2"; zeroOrThree = 0; }
1023  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH2_Gain456_address ) { whichAOHString = "2"; zeroOrThree = 3; }
1024  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH3_Gain123_address ) { whichAOHString = "3"; zeroOrThree = 0; }
1025  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH3_Gain456_address ) { whichAOHString = "3"; zeroOrThree = 3; }
1026  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH4_Gain123_address ) { whichAOHString = "4"; zeroOrThree = 0; }
1027  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH4_Gain456_address ) { whichAOHString = "4"; zeroOrThree = 3; }
1028  else assert(0);
1029 
1030  out << "AOH"<<whichAOHString<<"_Gain"<<zeroOrThree+1<<": 0x"<< (((device_[i].second) & 0x03)>>0) << std::endl; // output bits 0 & 1
1031  out << "AOH"<<whichAOHString<<"_Gain"<<zeroOrThree+2<<": 0x"<< (((device_[i].second) & 0x0c)>>2) << std::endl; // output bits 2 & 3
1032  out << "AOH"<<whichAOHString<<"_Gain"<<zeroOrThree+3<<": 0x"<< (((device_[i].second) & 0x30)>>4) << std::endl; // output bits 4 & 5
1033  continue;
1034  }
1035  // End of special handling
1036 
1037  // Check to see if there's a name corresponding to this address.
1038  std::string settingName = "";
1039  for ( std::map<std::string, unsigned int>::const_iterator nameToAddress_itr = nameToAddress_.begin(); nameToAddress_itr != nameToAddress_.end(); ++nameToAddress_itr )
1040  {
1041 // cout << "[PixelPortCardConfig::WriteASCII()]\tnameToAddress.first: " << nameToAddress_itr->first << endl ;
1042 // cout << "[PixelPortCardConfig::WriteASCII()]\tnameToAddress.second: " << nameToAddress_itr->second << endl ;
1043 // cout << "[PixelPortCardConfig::WriteASCII()]\tdeviceAddress: " << deviceAddress << endl ;
1044  if ( nameToAddress_itr->second == deviceAddress ) {settingName = nameToAddress_itr->first; break;}
1045  if(nameToAddress_itr == (--nameToAddress_.end()))
1046  {
1047  cout << "[PixelPortCardConfig::WriteASCII()]\tdeviceAddress: " << deviceAddress << " NOT FOUND" << endl ;
1048  }
1049  }
1050 
1051 
1052  // Special handling for PLL addresses.
1053  if ( settingName == k_PLL_CTR2 )
1054  {
1055  if ( found_PLL_CTR2 && last_PLL_CTR2_value == device_.at(i).second ) continue; // don't save duplicate CTR2 settings
1056  found_PLL_CTR2 = true;
1057  last_PLL_CTR2_value = device_.at(i).second;
1058  }
1059  if ( found_PLL_CTR2 && settingName == k_PLL_CTR4or5 ) // change name to PLL_CTR4 or PLL_CTR5
1060  {
1061  if ( (last_PLL_CTR2_value & 0x20) == 0x0 ) settingName = k_PLL_CTR4;
1062  else settingName = k_PLL_CTR5;
1063  }
1064  // end of special handling
1065 
1066  if ( settingName=="" ) out << "0x" <<std::hex<< device_.at(i).first <<std::dec;
1067  else out << settingName << ":";
1068 
1069  out << " 0x" <<std::hex<< device_.at(i).second <<std::dec<< std::endl;
1070  }
1071 
1072  out.close();
1073 }
1074 
1076  return device_.size();
1077 }
1078 
1080  return TKFECID_;
1081 }
1082 
1084  return ringAddress_;
1085 }
1086 
1088  return ccuAddress_;
1089 }
1090 
1092  return channelAddress_;
1093 }
1094 
1096  return i2cSpeed_;
1097 }
1098 
1099 std::string PixelPortCardConfig::gettype() const{
1100  return type_;
1101 }
1102 
1103 unsigned int PixelPortCardConfig::getdeviceAddress(unsigned int i) const{
1104  assert(i<device_.size());
1105  return device_[i].first;
1106 }
1107 
1108 unsigned int PixelPortCardConfig::getdeviceValues(unsigned int i) const{
1109  assert(i<device_.size());
1110  return device_[i].second;
1111 }
1112 
1113 void PixelPortCardConfig::setdeviceValues(unsigned int address, unsigned int value) {
1114  for (int i=device_.size()-1; i>=0; i--) // Change only the last occurance of address, if there are more than one.
1115  {
1116  if( device_.at(i).first==address )
1117  {
1118  device_.at(i).second=value;
1119  return;
1120  }
1121  }
1122 
1123  // This address wasn't found in the list, so add it and its value.
1124  pair<unsigned int, unsigned int> p(address, value);
1125  device_.push_back(p);
1126 
1127  return;
1128 }
1129 
1130 void PixelPortCardConfig::setdeviceValues(std::string settingName, unsigned int value)
1131 {
1132  setdeviceValues( getdeviceAddressForSetting(settingName), value );
1133  return;
1134 }
1135 
1136 unsigned int PixelPortCardConfig::getdeviceAddressForSetting(std::string settingName) const
1137 {
1138  //std::cout << "[PixelPortCardConfig::getdeviceAddressForSetting()]\t settingName: " << settingName<< std::endl ;
1139  std::map<std::string, unsigned int>::const_iterator foundName_itr = nameToAddress_.find(settingName);
1140  assert( foundName_itr != nameToAddress_.end() );
1141  return foundName_itr->second;
1142 }
1143 
1144 unsigned int PixelPortCardConfig::getdeviceValuesForSetting(std::string settingName) const
1145 {
1147 }
1148 
1150 {
1151  for (int i=device_.size()-1; i>=0; i--) // Get the last occurance of address, if there are more than one.
1152  {
1153  if( device_.at(i).first==address )
1154  {
1155  return device_.at(i).second;
1156  }
1157  }
1158  assert(0); // didn't find this device
1159  return 0;
1160 }
1161 
1162 bool PixelPortCardConfig::containsDeviceAddress(unsigned int deviceAddress) const
1163 {
1164  for ( std::vector<std::pair<unsigned int, unsigned int> >::const_iterator device_itr = device_.begin(); device_itr != device_.end(); device_itr++ )
1165  {
1166  if ( device_itr->first == deviceAddress ) return true;
1167  }
1168  return false;
1169 }
1170 
1171 unsigned int PixelPortCardConfig::AOHBiasAddressFromAOHNumber(unsigned int AOHNumber) const
1172 {
1173  std::string mthn = "[PixelPortCardConfig::AOHBiasAddressFromAOHNumber()] " ;
1174  if ( type_ == "fpix" )
1175  {
1176  if (AOHNumber == 1) return PortCardSettingNames::k_fpix_AOH_Bias1_address;
1177  else if (AOHNumber == 2) return PortCardSettingNames::k_fpix_AOH_Bias2_address;
1178  else if (AOHNumber == 3) return PortCardSettingNames::k_fpix_AOH_Bias3_address;
1179  else if (AOHNumber == 4) return PortCardSettingNames::k_fpix_AOH_Bias4_address;
1180  else if (AOHNumber == 5) return PortCardSettingNames::k_fpix_AOH_Bias5_address;
1181  else if (AOHNumber == 6) return PortCardSettingNames::k_fpix_AOH_Bias6_address;
1182  else {std::cout << __LINE__ << "]\t" << mthn
1183  << "ERROR: For fpix, AOH number must be in the range 1-6, but the given AOH number was "
1184  << AOHNumber
1185  << "."
1186  << std::endl;
1187  assert(0);}
1188  }
1189  else if ( type_ == "bpix" )
1190  {
1191  if (AOHNumber == 1) return PortCardSettingNames::k_bpix_AOH1_Bias1_address;
1192  else if (AOHNumber == 2) return PortCardSettingNames::k_bpix_AOH1_Bias2_address;
1193  else if (AOHNumber == 3) return PortCardSettingNames::k_bpix_AOH1_Bias3_address;
1194  else if (AOHNumber == 4) return PortCardSettingNames::k_bpix_AOH1_Bias4_address;
1195  else if (AOHNumber == 5) return PortCardSettingNames::k_bpix_AOH1_Bias5_address;
1196  else if (AOHNumber == 6) return PortCardSettingNames::k_bpix_AOH1_Bias6_address;
1197  else if (AOHNumber == 7) return PortCardSettingNames::k_bpix_AOH2_Bias1_address;
1198  else if (AOHNumber == 8) return PortCardSettingNames::k_bpix_AOH2_Bias2_address;
1199  else if (AOHNumber == 9) return PortCardSettingNames::k_bpix_AOH2_Bias3_address;
1200  else if (AOHNumber ==10) return PortCardSettingNames::k_bpix_AOH2_Bias4_address;
1201  else if (AOHNumber ==11) return PortCardSettingNames::k_bpix_AOH2_Bias5_address;
1202  else if (AOHNumber ==12) return PortCardSettingNames::k_bpix_AOH2_Bias6_address;
1203  else if (AOHNumber ==13) return PortCardSettingNames::k_bpix_AOH3_Bias1_address;
1204  else if (AOHNumber ==14) return PortCardSettingNames::k_bpix_AOH3_Bias2_address;
1205  else if (AOHNumber ==15) return PortCardSettingNames::k_bpix_AOH3_Bias3_address;
1206  else if (AOHNumber ==16) return PortCardSettingNames::k_bpix_AOH3_Bias4_address;
1207  else if (AOHNumber ==17) return PortCardSettingNames::k_bpix_AOH3_Bias5_address;
1208  else if (AOHNumber ==18) return PortCardSettingNames::k_bpix_AOH3_Bias6_address;
1209  else if (AOHNumber ==19) return PortCardSettingNames::k_bpix_AOH4_Bias1_address;
1210  else if (AOHNumber ==20) return PortCardSettingNames::k_bpix_AOH4_Bias2_address;
1211  else if (AOHNumber ==21) return PortCardSettingNames::k_bpix_AOH4_Bias3_address;
1212  else if (AOHNumber ==22) return PortCardSettingNames::k_bpix_AOH4_Bias4_address;
1213  else if (AOHNumber ==23) return PortCardSettingNames::k_bpix_AOH4_Bias5_address;
1214  else if (AOHNumber ==24) return PortCardSettingNames::k_bpix_AOH4_Bias6_address;
1215  else {std::cout << __LINE__ << "]\t" << mthn
1216  << "ERROR: For bpix, AOH number must be in the range 1-24, but the given AOH number was "
1217  << AOHNumber
1218  << "."
1219  << std::endl;
1220  assert(0);}
1221  }
1222  else assert(0);
1223 }
1224 
1225 std::string PixelPortCardConfig::AOHGainStringFromAOHNumber(unsigned int AOHNumber) const
1226 {
1227  std::string mthn = "[PixelPortCardConfig::AOHGainStringFromAOHNumber()] " ;
1228  if ( type_ == "fpix" )
1229  {
1230  if (AOHNumber == 1) return "AOH_Gain1";
1231  else if (AOHNumber == 2) return "AOH_Gain2";
1232  else if (AOHNumber == 3) return "AOH_Gain3";
1233  else if (AOHNumber == 4) return "AOH_Gain4";
1234  else if (AOHNumber == 5) return "AOH_Gain5";
1235  else if (AOHNumber == 6) return "AOH_Gain6";
1236  else {std::cout << __LINE__ << "]\t" << mthn
1237  << "ERROR: For fpix, AOH number must be in the range 1-6, but the given AOH number was "
1238  << AOHNumber
1239  << "."
1240  << std::endl;
1241  assert(0);}
1242  }
1243  else if ( type_ == "bpix" )
1244  {
1245  if (AOHNumber == 1) return "AOH1_Gain1";
1246  else if (AOHNumber == 2) return "AOH1_Gain2";
1247  else if (AOHNumber == 3) return "AOH1_Gain3";
1248  else if (AOHNumber == 4) return "AOH1_Gain4";
1249  else if (AOHNumber == 5) return "AOH1_Gain5";
1250  else if (AOHNumber == 6) return "AOH1_Gain6";
1251  else if (AOHNumber == 7) return "AOH2_Gain1";
1252  else if (AOHNumber == 8) return "AOH2_Gain2";
1253  else if (AOHNumber == 9) return "AOH2_Gain3";
1254  else if (AOHNumber ==10) return "AOH2_Gain4";
1255  else if (AOHNumber ==11) return "AOH2_Gain5";
1256  else if (AOHNumber ==12) return "AOH2_Gain6";
1257  else if (AOHNumber ==13) return "AOH3_Gain1";
1258  else if (AOHNumber ==14) return "AOH3_Gain2";
1259  else if (AOHNumber ==15) return "AOH3_Gain3";
1260  else if (AOHNumber ==16) return "AOH3_Gain4";
1261  else if (AOHNumber ==17) return "AOH3_Gain5";
1262  else if (AOHNumber ==18) return "AOH3_Gain6";
1263  else if (AOHNumber ==19) return "AOH4_Gain1";
1264  else if (AOHNumber ==20) return "AOH4_Gain2";
1265  else if (AOHNumber ==21) return "AOH4_Gain3";
1266  else if (AOHNumber ==22) return "AOH4_Gain4";
1267  else if (AOHNumber ==23) return "AOH4_Gain5";
1268  else if (AOHNumber ==24) return "AOH4_Gain6";
1269  else {std::cout << __LINE__ << "]\t" << mthn
1270  << "ERROR: For bpix, AOH number must be in the range 1-24, but the given AOH number was "
1271  << AOHNumber
1272  << "."
1273  << std::endl;
1274  assert(0);}
1275  }
1276  else assert(0);
1277 }
1278 
1279 unsigned int PixelPortCardConfig::AOHGainAddressFromAOHNumber(unsigned int AOHNumber) const
1280 {
1281  std::string mthn = "[PixelPortCardConfig::AOHGainAddressFromAOHNumber()] " ;
1282  unsigned int address;
1283  if ( type_ == "fpix" )
1284  {
1285  if (AOHNumber == 1) address = PortCardSettingNames::k_fpix_AOH_Gain123_address;
1286  else if (AOHNumber == 2) address = PortCardSettingNames::k_fpix_AOH_Gain123_address;
1287  else if (AOHNumber == 3) address = PortCardSettingNames::k_fpix_AOH_Gain123_address;
1288  else if (AOHNumber == 4) address = PortCardSettingNames::k_fpix_AOH_Gain456_address;
1289  else if (AOHNumber == 5) address = PortCardSettingNames::k_fpix_AOH_Gain456_address;
1290  else if (AOHNumber == 6) address = PortCardSettingNames::k_fpix_AOH_Gain456_address;
1291  else {std::cout << __LINE__ << "]\t" << mthn
1292  << "ERROR: For fpix, AOH number must be in the range 1-6, but the given AOH number was "
1293  << AOHNumber
1294  << "."
1295  << std::endl;
1296  assert(0);}
1297  }
1298  else if ( type_ == "bpix" )
1299  {
1300  if (AOHNumber == 1) address = PortCardSettingNames::k_bpix_AOH1_Gain123_address;
1301  else if (AOHNumber == 2) address = PortCardSettingNames::k_bpix_AOH1_Gain123_address;
1302  else if (AOHNumber == 3) address = PortCardSettingNames::k_bpix_AOH1_Gain123_address;
1303  else if (AOHNumber == 4) address = PortCardSettingNames::k_bpix_AOH1_Gain456_address;
1304  else if (AOHNumber == 5) address = PortCardSettingNames::k_bpix_AOH1_Gain456_address;
1305  else if (AOHNumber == 6) address = PortCardSettingNames::k_bpix_AOH1_Gain456_address;
1306  else if (AOHNumber == 7) address = PortCardSettingNames::k_bpix_AOH2_Gain123_address;
1307  else if (AOHNumber == 8) address = PortCardSettingNames::k_bpix_AOH2_Gain123_address;
1308  else if (AOHNumber == 9) address = PortCardSettingNames::k_bpix_AOH2_Gain123_address;
1309  else if (AOHNumber ==10) address = PortCardSettingNames::k_bpix_AOH2_Gain456_address;
1310  else if (AOHNumber ==11) address = PortCardSettingNames::k_bpix_AOH2_Gain456_address;
1311  else if (AOHNumber ==12) address = PortCardSettingNames::k_bpix_AOH2_Gain456_address;
1312  else if (AOHNumber ==13) address = PortCardSettingNames::k_bpix_AOH3_Gain123_address;
1313  else if (AOHNumber ==14) address = PortCardSettingNames::k_bpix_AOH3_Gain123_address;
1314  else if (AOHNumber ==15) address = PortCardSettingNames::k_bpix_AOH3_Gain123_address;
1315  else if (AOHNumber ==16) address = PortCardSettingNames::k_bpix_AOH3_Gain456_address;
1316  else if (AOHNumber ==17) address = PortCardSettingNames::k_bpix_AOH3_Gain456_address;
1317  else if (AOHNumber ==18) address = PortCardSettingNames::k_bpix_AOH3_Gain456_address;
1318  else if (AOHNumber ==19) address = PortCardSettingNames::k_bpix_AOH4_Gain123_address;
1319  else if (AOHNumber ==20) address = PortCardSettingNames::k_bpix_AOH4_Gain123_address;
1320  else if (AOHNumber ==21) address = PortCardSettingNames::k_bpix_AOH4_Gain123_address;
1321  else if (AOHNumber ==22) address = PortCardSettingNames::k_bpix_AOH4_Gain456_address;
1322  else if (AOHNumber ==23) address = PortCardSettingNames::k_bpix_AOH4_Gain456_address;
1323  else if (AOHNumber ==24) address = PortCardSettingNames::k_bpix_AOH4_Gain456_address;
1324  else {std::cout << __LINE__ << "]\t" << mthn
1325  << "ERROR: For bpix, AOH number must be in the range 1-24, but the given AOH number was "
1326  << AOHNumber
1327  << "."
1328  << std::endl;
1329  assert(0);}
1330  }
1331  else assert(0);
1332 
1333  return address;
1334 }
1335 
1336 unsigned int PixelPortCardConfig::getAOHGain(unsigned int AOHNumber) const
1337 {
1338  const unsigned int address = AOHGainAddressFromAOHNumber(AOHNumber);
1339  const unsigned int threeGainsValue = getdeviceValuesForAddress(address);
1340 
1341  if ( AOHNumber%3 == 1 ) return (((threeGainsValue) & 0x03)>>0); // return bits 0 & 1
1342  if ( AOHNumber%3 == 2 ) return (((threeGainsValue) & 0x0c)>>2); // return bits 2 & 3
1343  if ( AOHNumber%3 == 0 ) return (((threeGainsValue) & 0x30)>>4); // return bits 4 & 5
1344 
1345  assert(0);
1346 }
1347 //=============================================================================================
1349  int version,
1350  std::string path,
1351  std::ofstream *outstream,
1352  std::ofstream *out1stream,
1353  std::ofstream *out2stream) const
1354 {
1355  std::string mthn = "[PixelPortCardConfig::writeXMLHeader()]\t\t\t " ;
1356  std::stringstream fullPath ;
1357  fullPath << path << "/Pixel_PortCardSettings_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
1358  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << std::endl ;
1359 
1360  outstream->open(fullPath.str().c_str()) ;
1361 
1362  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
1363  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
1364  *outstream << " <HEADER>" << std::endl ;
1365  *outstream << " <TYPE>" << std::endl ;
1366  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_PORTCARD_SETTINGS</EXTENSION_TABLE_NAME>" << std::endl ;
1367  *outstream << " <NAME>Pixel Port Card Settings</NAME>" << std::endl ;
1368  *outstream << " </TYPE>" << std::endl ;
1369  *outstream << " <RUN>" << std::endl ;
1370  *outstream << " <RUN_TYPE>Pixel Port Card Settings</RUN_TYPE>" << std::endl ;
1371  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
1372  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
1373  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
1374  *outstream << " </RUN>" << std::endl ;
1375  *outstream << " </HEADER>" << std::endl ;
1376  *outstream << "" << std::endl ;
1377  *outstream << " <DATA_SET>" << std::endl ;
1378  *outstream << " <PART>" << std::endl ;
1379  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
1380  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
1381  *outstream << " </PART>" << std::endl ;
1382  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
1383  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
1384  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
1385  *outstream << "" << std::endl ;
1386 }
1387 
1388 //=============================================================================================
1389 void PixelPortCardConfig::writeXML(std::ofstream *outstream,
1390  std::ofstream *out1stream,
1391  std::ofstream *out2stream) const
1392 {
1393  std::string mthn = "[PixelPortCardConfig::writeXML()]\t\t\t " ;
1394 
1395 
1396  *outstream << " <DATA>" << std::endl;
1397  *outstream << " <PORT_CARD>" << portcardname_ << "</PORT_CARD>" << std::endl;
1398  *outstream << " <TRKFEC>" << TKFECID_ << "</TRKFEC>" << std::endl;
1399  *outstream << " <RING>" << ringAddress_ << "</RING>" << std::endl;
1400  *outstream << " <CCU_ADDR>" << ccuAddress_ << "</CCU_ADDR>" << std::endl;
1401  *outstream << " <CHANNEL>" << channelAddress_ << "</CHANNEL>" << std::endl;
1402  *outstream << " <I2C_SPEED>" << i2cSpeed_ << "</I2C_SPEED>" << std::endl;
1403 
1404  bool found_PLL_CTR2 = false;
1405  unsigned int last_PLL_CTR2_value = 0x0;
1406  for (unsigned int i=0;i<device_.size();i++)
1407  {
1408  unsigned int deviceAddress = device_.at(i).first;
1409 
1410  // Special handling for AOH gains
1411  if ( ( type_=="fpix" && deviceAddress == k_fpix_AOH_Gain123_address )
1412  || ( type_=="fpix" && deviceAddress == k_fpix_AOH_Gain456_address )
1413  || ( type_=="bpix" && deviceAddress == k_bpix_AOH1_Gain123_address )
1414  || ( type_=="bpix" && deviceAddress == k_bpix_AOH1_Gain456_address )
1415  || ( type_=="bpix" && deviceAddress == k_bpix_AOH2_Gain123_address )
1416  || ( type_=="bpix" && deviceAddress == k_bpix_AOH2_Gain456_address )
1417  || ( type_=="bpix" && deviceAddress == k_bpix_AOH3_Gain123_address )
1418  || ( type_=="bpix" && deviceAddress == k_bpix_AOH3_Gain456_address )
1419  || ( type_=="bpix" && deviceAddress == k_bpix_AOH4_Gain123_address )
1420  || ( type_=="bpix" && deviceAddress == k_bpix_AOH4_Gain456_address )
1421  )
1422  {
1423  std::string whichAOHString;
1424  unsigned int zeroOrThree;
1425  if ( type_=="fpix" && deviceAddress == k_fpix_AOH_Gain123_address ) { whichAOHString = ""; zeroOrThree = 0; }
1426  else if ( type_=="fpix" && deviceAddress == k_fpix_AOH_Gain456_address ) { whichAOHString = ""; zeroOrThree = 3; }
1427  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH1_Gain123_address ) { whichAOHString = "1"; zeroOrThree = 0; }
1428  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH1_Gain456_address ) { whichAOHString = "1"; zeroOrThree = 3; }
1429  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH2_Gain123_address ) { whichAOHString = "2"; zeroOrThree = 0; }
1430  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH2_Gain456_address ) { whichAOHString = "2"; zeroOrThree = 3; }
1431  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH3_Gain123_address ) { whichAOHString = "3"; zeroOrThree = 0; }
1432  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH3_Gain456_address ) { whichAOHString = "3"; zeroOrThree = 3; }
1433  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH4_Gain123_address ) { whichAOHString = "4"; zeroOrThree = 0; }
1434  else if ( type_=="bpix" && deviceAddress == k_bpix_AOH4_Gain456_address ) { whichAOHString = "4"; zeroOrThree = 3; }
1435  else assert(0);
1436 
1437  *outstream << " <AOH" << whichAOHString << "_GAIN" << zeroOrThree+1 << ">" << (((device_[i].second) & 0x03)>>0) << "</AOH" << whichAOHString << "_GAIN" << zeroOrThree+1 << ">" << std::endl; // output bits 0 & 1
1438  *outstream << " <AOH" << whichAOHString << "_GAIN" << zeroOrThree+2 << ">" << (((device_[i].second) & 0x0c)>>2) << "</AOH" << whichAOHString << "_GAIN" << zeroOrThree+2 << ">" << std::endl; // output bits 2 & 3
1439  *outstream << " <AOH" << whichAOHString << "_GAIN" << zeroOrThree+3 << ">" << (((device_[i].second) & 0x30)>>4) << "</AOH" << whichAOHString << "_GAIN" << zeroOrThree+3 << ">" << std::endl; // output bits 4 & 5
1440  continue;
1441  }
1442  // End of special handling
1443 
1444  // Check to see if there's a name corresponding to this address.
1445  std::string settingName = "";
1446  for ( std::map<std::string, unsigned int>::const_iterator nameToAddress_itr = nameToAddress_.begin(); nameToAddress_itr != nameToAddress_.end(); ++nameToAddress_itr )
1447  {
1448  if ( nameToAddress_itr->second == deviceAddress ) {settingName = nameToAddress_itr->first; break;}
1449  }
1450  for ( std::map<std::string, std::string>::const_iterator nameDBtoFileConversion_itr = nameDBtoFileConversion_.begin(); nameDBtoFileConversion_itr != nameDBtoFileConversion_.end(); ++nameDBtoFileConversion_itr )
1451  {
1452  if ( nameDBtoFileConversion_itr->second.find(settingName) != std::string::npos ) {settingName = nameDBtoFileConversion_itr->first; break;}
1453  }
1454 
1455  // Special handling for PLL addresses.
1456  if ( settingName == k_PLL_CTR2 )
1457  {
1458  if ( found_PLL_CTR2 && last_PLL_CTR2_value == device_.at(i).second ) continue; // don't save duplicate CTR2 settings
1459  found_PLL_CTR2 = true;
1460  last_PLL_CTR2_value = device_.at(i).second;
1461  }
1462  if ( found_PLL_CTR2 && settingName == k_PLL_CTR4or5 ) // change name to PLL_CTR4 or PLL_CTR5
1463  {
1464  if ( (last_PLL_CTR2_value & 0x20) == 0x0 ) settingName = k_PLL_CTR4;
1465  else settingName = k_PLL_CTR5;
1466  }
1467  // end of special handling
1468 
1469  if ( settingName=="" ) *outstream << device_.at(i).first;
1470  else *outstream << " <" << settingName << ">" ;
1471 
1472  *outstream << device_.at(i).second << "</" << settingName << ">" << std::endl;
1473  }
1474 
1475  *outstream << " </DATA>" << std::endl;
1476 
1477 }
1478 //=============================================================================================
1479 void PixelPortCardConfig::writeXMLTrailer(std::ofstream *outstream,
1480  std::ofstream *out1stream,
1481  std::ofstream *out2stream) const
1482 {
1483  std::string mthn = "[PixelPortCardConfig::writeXMLTrailer()]\t\t\t " ;
1484 
1485  *outstream << " </DATA_SET>" << std::endl ;
1486  *outstream << "</ROOT> " << std::endl ;
1487 
1488  outstream->close() ;
1489 }
1490 
const unsigned int k_bpix_AOH4_Bias6_address
unsigned int new_PLL_CTR2_value(std::string CTR4or5, unsigned int last_CTR2) const
int i
Definition: DBlmapReader.cc:9
const unsigned int k_fpix_AOH_Bias6_address
bool containsDeviceAddress(unsigned int deviceAddress) const
This file contains the base class for &quot;pixel configuration data&quot; management.
const unsigned int k_fpix_PLL_CTR4or5_address
void writeASCII(std::string dir="") const
const unsigned int k_bpix_AOH1_Gain123_address
char * address
Definition: mlp_lapack.h:14
const unsigned int k_bpix_AOH3_Bias4_address
const unsigned int k_fpix_DOH_Ch1Bias_Data_address
const unsigned int k_bpix_AOH3_Bias3_address
const unsigned int k_bpix_AOH2_Bias3_address
const unsigned int k_fpix_DOH_Dummy_address
unsigned int getchannelAddress() const
const unsigned int k_bpix_DOH_Dummy_address
const unsigned int k_bpix_AOH2_Bias5_address
unsigned int getdeviceValues(unsigned int i) const
const unsigned int k_fpix_Delay25_GCR_address
std::map< std::string, unsigned int > nameToAddress_
const unsigned int k_fpix_PLL_CTR1_address
std::map< std::string, std::string > nameDBtoFileConversion_
const unsigned int k_bpix_AOH4_Bias2_address
const unsigned int k_bpix_AOH1_Gain456_address
unsigned int getccuAddress() const
unsigned int getdeviceValuesForSetting(std::string settingName) const
const unsigned int k_bpix_DOH_Ch1Bias_Data_address
const unsigned int k_bpix_AOH1_Bias4_address
const unsigned int k_bpix_AOH3_Bias1_address
PixelPortCardConfig(std::vector< std::vector< std::string > > &tableMat)
unsigned int getdeviceAddressForSetting(std::string settingName) const
const unsigned int k_bpix_AOH4_Gain456_address
uint16_t size_type
const unsigned int k_bpix_AOH3_Bias5_address
const unsigned int k_bpix_Delay25_SDA_address
const unsigned int k_bpix_AOH2_Bias2_address
static std::string getmSecTime(void)
const unsigned int k_bpix_Delay25_SCL_address
const unsigned int k_bpix_PLL_CTR2_address
int path() const
Definition: HLTadd.h:3
unsigned int AOHBiasAddressFromAOHNumber(unsigned int AOHNumber) const
const unsigned int k_bpix_Delay25_TRG_address
const unsigned int k_bpix_AOH1_Bias2_address
const unsigned int k_bpix_AOH2_Gain456_address
const unsigned int k_bpix_AOH1_Bias3_address
const unsigned int k_bpix_PLL_CTR3_address
const unsigned int k_bpix_AOH4_Bias4_address
unsigned int AOHGainAddressFromAOHNumber(unsigned int AOHNumber) const
const unsigned int k_bpix_PLL_CTR4or5_address
void setDataBaseAOHGain(std::string settingName, unsigned int value)
const unsigned int k_bpix_AOH3_Bias6_address
std::vector< std::pair< unsigned int, unsigned int > > device_
const unsigned int k_bpix_AOH4_Gain123_address
const unsigned int k_bpix_AOH4_Bias3_address
const unsigned int k_fpix_AOH_Bias5_address
std::vector< unsigned int > key_
key used for sorting device_
static std::string getTime(void)
const unsigned int k_bpix_AOH4_Bias1_address
const unsigned int k_bpix_AOH1_Bias6_address
const unsigned int k_fpix_AOH_Bias2_address
std::string getComment() const
const unsigned int k_bpix_AOH1_Bias1_address
const unsigned int k_fpix_AOH_Gain123_address
unsigned int getdeviceAddress(unsigned int i) const
std::string getTKFECID() const
const unsigned int k_fpix_Delay25_TRG_address
const unsigned int k_fpix_AOH_Bias4_address
This class provides utility methods to manipulate ASCII formatted timestamps.
const unsigned int k_bpix_AOH2_Gain123_address
unsigned int getdevicesize() const
const unsigned int k_bpix_AOH3_Gain123_address
const unsigned int k_bpix_DOH_Gain_SEU_address
std::string getAuthor() const
const unsigned int k_bpix_Delay25_RCL_address
std::string AOHGainStringFromAOHNumber(unsigned int AOHNumber) const
void setdeviceValues(unsigned int address, unsigned int value)
bool first
Definition: L1TdeRCT.cc:79
unsigned int getAOHGain(unsigned int AOHNumber) const
const unsigned int k_bpix_DOH_Ch0Bias_CLK_address
const unsigned int k_bpix_Delay25_RDA_address
This class implements..
tuple out
Definition: dbtoconf.py:99
const unsigned int k_bpix_Delay25_GCR_address
const unsigned int k_fpix_Delay25_SDA_address
bool containsSetting(std::string settingName) const
unsigned int getringAddress() const
const unsigned int k_fpix_DOH_Ch0Bias_CLK_address
const unsigned int k_fpix_DOH_Gain_SEU_address
const unsigned int k_fpix_PLL_CTR2_address
const unsigned int k_bpix_PLL_CTR1_address
const unsigned int k_fpix_Delay25_RCL_address
const unsigned int k_fpix_Delay25_SCL_address
unsigned int geti2cSpeed() const
virtual void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
list key
Definition: combine.py:13
const unsigned int k_fpix_AOH_Bias3_address
const unsigned int k_bpix_AOH1_Bias5_address
tuple filename
Definition: lut2db_cfg.py:20
const unsigned int k_fpix_AOH_Gain456_address
tuple cout
Definition: gather_cfg.py:41
dbl *** dir
Definition: mlp_gen.cc:35
void setAOHGain(unsigned int AOHNumber, unsigned int value)
const unsigned int k_bpix_AOH3_Bias2_address
const unsigned int k_fpix_PLL_CTR3_address
const unsigned int k_bpix_AOH3_Gain456_address
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
const unsigned int k_bpix_AOH2_Bias1_address
This class specifies the settings on the TKPCIFEC and the settings on the portcard.
const unsigned int k_bpix_AOH2_Bias6_address
const unsigned int k_bpix_AOH4_Bias5_address
std::string gettype() const
const unsigned int k_fpix_AOH_Bias1_address
void writeXML(pos::PixelConfigKey key, int version, std::string path) const
unsigned int getdeviceValuesForAddress(unsigned int address) const
const unsigned int k_fpix_Delay25_RDA_address
const unsigned int k_bpix_AOH2_Bias4_address