CMS 3D CMS Logo

PixelConfigFile.h
Go to the documentation of this file.
1 #ifndef PixelConfigFile_h
2 #define PixelConfigFile_h
3 
40 #include <string>
41 #include <vector>
42 #include <map>
43 #include <iostream>
44 #include <sstream>
45 #include <typeinfo>
46 #include <stdexcept>
47 #include <sys/stat.h>
48 #include <sys/types.h>
49 #include <unistd.h>
50 
51 #define DEBUG_CF_ 0
52 
53 namespace pos {
61  public:
62  static std::vector<std::pair<std::string, unsigned int> > getAliases() {
63  PixelAliasList& aliases = getAlias();
64  std::vector<std::pair<std::string, unsigned int> > tmp;
65  for (unsigned int i = 0; i < aliases.nAliases(); i++) {
66  std::pair<std::string, unsigned int> apair(aliases.name(i), aliases.key(i));
67  tmp.push_back(apair);
68  }
69  return tmp;
70  }
71 
72  static std::vector<std::string> getVersionAliases(std::string path) { return getAlias().getVersionAliases(path); }
73 
74  static bool getVersionAliases(std::string configAlias,
75  unsigned int& key,
76  std::vector<std::pair<std::string, std::string> >& versionAliases) {
78  if (alias == 0) {
79  return false;
80  }
81  key = alias->key();
82  versionAliases = alias->versionAliases();
83  return true;
84  }
85 
86  static std::map<std::string, unsigned int> getAliases_map() {
87  PixelAliasList& aliases = getAlias();
88  std::map<std::string, unsigned int> tmp;
89  for (unsigned int i = 0; i < aliases.nAliases(); i++) {
90  tmp.insert(make_pair(aliases.name(i), aliases.key(i)));
91  }
92  return tmp;
93  }
94 
96  static PixelConfigList theConfigList = getConfig();
97  return theConfigList;
98  }
99 
100  static unsigned int getVersion(std::string path, std::string alias) { return getAlias().getVersion(path, alias); }
101 
102  // Added by Dario, May 20th, 2008 =====================================================================
105 
106  static std::vector<pathAliasPair> getConfigAliases(std::string path) { return getAlias().getConfigAliases(path); }
107  // End of Dario's addition ============================================================================
108 
109  static void addAlias(std::string alias, unsigned int key) {
110  PixelConfigAlias anAlias(alias, key);
111  getAlias().insertAlias(anAlias);
112  getAlias().writefile();
113  }
114 
116  unsigned int key,
117  std::vector<std::pair<std::string, std::string> > versionaliases) {
118  PixelConfigAlias anAlias(alias, key);
119  for (unsigned int i = 0; i < versionaliases.size(); i++) {
120  anAlias.addVersionAlias(versionaliases[i].first, versionaliases[i].second);
121  }
122  getAlias().insertAlias(anAlias);
123  getAlias().writefile();
124  }
125 
126  static std::vector<std::pair<std::string, unsigned int> > getVersions(pos::PixelConfigKey key) {
127  static PixelConfigList& configs = getConfig();
128  PixelConfig& theConfig = configs[key.key()];
129  return theConfig.versions();
130  }
131 
132  static void addVersionAlias(std::string path, unsigned int version, std::string alias) {
134 
135  PixelVersionAlias anAlias(path, version, alias);
136  getAlias().insertVersionAlias(anAlias);
137  getAlias().updateConfigAlias(path, version, alias, configs);
138  getAlias().writefile();
139  configs.writefile();
140  }
141 
142  static unsigned int makeKey(std::vector<std::pair<std::string, unsigned int> > versions) {
144 
145  for (unsigned int i = 0; i < versions.size(); i++) {
146  config.add(versions[i].first, versions[i].second);
147  }
148 
150 
151  unsigned int newkey = configs.add(config);
152 
153  configs.writefile();
154 
155  return newkey;
156  }
157 
159  static PixelConfigList configs;
160 
161  //FIXME
162 
163  static int counter = 0;
164 
165  if (counter != 0) {
166  while (counter != 0) {
167  std::cout << __LINE__
168  << "]\t[PixelConfigFile::getConfig()]\t\t\t\t Waiting for other thread to complete reading"
169  << std::endl;
170  ::sleep(1);
171  }
172  return configs;
173  }
174 
175  counter++;
176 
177  static std::string directory;
178  static int first = 1;
179 
180  directory = std::getenv("PIXELCONFIGURATIONBASE");
181  std::string filename = directory + "/configurations.txt";
182  /* Don't know who put this snippet of code here: this case is already contemplated in the 'else' of the 'if' statement below
183  if(!first)
184  {
185  configs.reload(filename)
186  }
187 */
188  if (first) {
189  first = 0;
190  configs.readfile(filename);
191  forceConfigReload(false);
192  } else {
193  // if( getForceConfigReload() ) {
194  configs.reload(filename);
195  forceConfigReload(false);
196  // }
197  }
198 
199  counter--;
200 
201  return configs;
202  }
203 
205  static std::string directory;
206  static int first = 1;
207 
208  static PixelAliasList aliases;
209 
210  directory = std::getenv("PIXELCONFIGURATIONBASE");
211  std::string filename = directory + "/aliases.txt";
212 
213  if (first) {
214  first = 0;
215  aliases.readfile(filename);
216 
217  forceAliasesReload(false);
218  } else {
219  if (getForceAliasesReload()) {
220  aliases.readfile(filename);
221  forceAliasesReload(false);
222  }
223  }
224 
225  return aliases;
226  }
227 
228  static void forceAliasesReload(bool m) {
229  if (getForceAliasesReload() != m) {
231  }
232  }
233 
234  static void forceConfigReload(bool m) {
235  if (getForceConfigReload() != m) {
237  }
238  }
239 
240  //Returns the path the the configuration data.
242  unsigned int theKey = key.key();
243 
244  assert(theKey <= getConfig().size());
245 
246  unsigned int last = path.find_last_of("/");
247  assert(last != (unsigned int)std::string::npos);
248 
249  std::string base = path.substr(0, last);
250  std::string ext = path.substr(last + 1);
251 
252  unsigned int slashpos = base.find_last_of("/");
253  if (slashpos == (unsigned int)std::string::npos) {
254  std::cout << "[pos::PixelConfigFile::getPath()]\t\t\tOn path:" << path << std::endl;
255  std::cout << "[pos::PixelConfigFile::getPath()]\t\t\tRecall that you need a trailing /" << std::endl;
256  ::abort();
257  }
258 
259  std::string dir = base.substr(slashpos + 1);
260 
261  // std::cout << "[pos::PixelConfigFile::get()]\t\t\tExtracted dir:" <<dir <<std::endl;
262  // std::cout << "[pos::PixelConfigFile::get()]\t\t\tExtracted base:"<<base<<std::endl;
263  // std::cout << "[pos::PixelConfigFile::get()]\t\t\tExtracted ext :"<<ext <<std::endl;
264 
265  unsigned int version;
266  int err = getConfig()[theKey].find(dir, version);
267  // assert(err==0);
268  if (0 != err) {
269  return "";
270  }
271 
272  std::ostringstream s1;
273  s1 << version;
274  std::string strversion = s1.str();
275 
276  static std::string directory;
277  directory = std::getenv("PIXELCONFIGURATIONBASE");
278 
279  std::string fullpath = directory + "/" + dir + "/" + strversion + "/";
280 
281  return fullpath;
282  }
283 
284  //Returns a pointer to the data found in the path with configuration key.
285  template <class T>
286  static void get(T*& data, std::string path, PixelConfigKey key) {
287  unsigned int theKey = key.key();
288 
289  if (theKey >= configList().size()) {
290  configList() = getConfig();
291  }
292 
293  assert(theKey <= configList().size());
294 
295  unsigned int last = path.find_last_of("/");
296  assert(last != (unsigned int)std::string::npos);
297 
298  std::string base = path.substr(0, last);
299  std::string ext = path.substr(last + 1);
300 
301  unsigned int slashpos = base.find_last_of("/");
302  if (slashpos == (unsigned int)std::string::npos) {
303  std::cout << "[pos::PixelConfigFile::get()]\t\t\tAsking for data of type:" << typeid(data).name() << std::endl;
304  std::cout << "[pos::PixelConfigFile::get()]\t\t\tOn path:" << path << std::endl;
305  std::cout << "[pos::PixelConfigFile::get()]\t\t\tRecall that you need a trailing /" << std::endl;
306  ::abort();
307  }
308 
309  std::string dir = base.substr(slashpos + 1);
310 
311  // std::cout << "[pos::PixelConfigFile::get()]\t\t\tExtracted dir:" <<dir <<std::endl;
312  // std::cout << "[pos::PixelConfigFile::get()]\t\t\tExtracted base:"<<base<<std::endl;
313  // std::cout << "[pos::PixelConfigFile::get()]\t\t\tExtracted ext :"<<ext <<std::endl;
314 
315  unsigned int version = 0;
316  int err = configList()[theKey].find(dir, version);
317  // assert(err==0);
318  if (0 != err) {
319  std::cout << "[PixelConfigFile.h::get] error loading config list. " << theKey << " " << dir << " " << version
320  << std::endl;
321  data = 0;
322  return;
323  }
324 
325  std::ostringstream s1;
326  s1 << version;
327  std::string strversion = s1.str();
328 
329  static std::string directory;
330  directory = std::getenv("PIXELCONFIGURATIONBASE");
331 
332  std::string fullpath = directory + "/" + dir + "/" + strversion + "/";
333 
334  //std::cout << "Directory for configuration data:"<<fullpath<<std::endl;
335 
336  try {
337  if (typeid(data) == typeid(PixelTrimBase*)) {
338  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelTrimBase" << std::endl;
339  assert(dir == "trim");
340  data = (T*)new PixelTrimAllPixels(fullpath + "ROC_Trims_module_" + ext + ".dat");
341  return;
342  } else if (typeid(data) == typeid(PixelMaskBase*)) {
343  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelMaskBase" << std::endl;
344  assert(dir == "mask");
345  data = (T*)new PixelMaskAllPixels(fullpath + "ROC_Masks_module_" + ext + ".dat");
346  return;
347  } else if (typeid(data) == typeid(PixelDACSettings*)) {
348  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelDACSettings" << std::endl;
349  assert(dir == "dac");
350  data = (T*)new PixelDACSettings(fullpath + "ROC_DAC_module_" + ext + ".dat");
351  return;
352  } else if (typeid(data) == typeid(PixelTBMSettings*)) {
353  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelTBMSettings" << std::endl;
354  assert(dir == "tbm");
355  data = (T*)new PixelTBMSettings(fullpath + "TBM_module_" + ext + ".dat");
356  return;
357  } else if (typeid(data) == typeid(PixelDetectorConfig*)) {
358  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelDetectorConfig" << std::endl;
359  assert(dir == "detconfig");
360  data = (T*)new PixelDetectorConfig(fullpath + "detectconfig.dat");
361  return;
362  } else if (typeid(data) == typeid(PixelLowVoltageMap*)) {
363  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill fetch PixelLowVoltageMap" << std::endl;
364  assert(dir == "lowvoltagemap");
365  data = (T*)new PixelLowVoltageMap(fullpath + "lowvoltagemap.dat");
366  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return the PixelLowVoltageMap" << std::endl;
367  return;
368  } else if (typeid(data) == typeid(PixelMaxVsf*)) {
369  //std::cout << "Will fetch PixelMaxVsf" << std::endl;
370  assert(dir == "maxvsf");
371  data = (T*)new PixelMaxVsf(fullpath + "maxvsf.dat");
372  //std::cout << "Will return the PixelMaxVsf" << std::endl;
373  return;
374  } else if (typeid(data) == typeid(PixelNameTranslation*)) {
375  //std::cout << __LINE__ << "]\t[pos::PixelConfigFile::get()]\t\t\t Will return PixelNameTranslation*" << std::endl;
376  assert(dir == "nametranslation");
377  data = (T*)new PixelNameTranslation(fullpath + "translation.dat");
378  return;
379  } else if (typeid(data) == typeid(PixelFEDCard*)) {
380  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelFEDCard" << std::endl;
381  assert(dir == "fedcard");
382  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill open:"<<fullpath+"params_fed_"+ext+".dat"<< std::endl;
383  data = (T*)new PixelFEDCard(fullpath + "params_fed_" + ext + ".dat");
384  return;
385  } else if (typeid(data) == typeid(PixelCalibBase*)) {
386  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelCalibBase" << std::endl;
387  assert(dir == "calib");
388  std::string calibfile = fullpath + "calib.dat";
389  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tLooking for file " << calibfile << std::endl;
390  std::ifstream calibin(calibfile.c_str());
391  if (calibin.good()) {
392  data = (T*)new PixelCalibConfiguration(calibfile);
393  } else {
394  calibfile = fullpath + "delay25.dat";
395  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tNow looking for file " << calibfile << std::endl;
396  std::ifstream delayin(calibfile.c_str());
397  if (delayin.good()) {
398  data = (T*)new PixelDelay25Calib(calibfile);
399  } else {
400  calibfile = fullpath + "fedtestdac.dat";
401  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tNow looking for file " << calibfile << std::endl;
402  std::ifstream delayin(calibfile.c_str());
403  if (delayin.good()) {
404  data = (T*)new PixelFEDTestDAC(calibfile);
405  } else {
406  throw std::runtime_error(
407  "[pos::PixelConfigFile::get()]\t\t\tCan't find calibration file calib.dat or delay25.dat or "
408  "fedtestdac.dat");
409  }
410  }
411  }
412  return;
413  } else if (typeid(data) == typeid(PixelTKFECConfig*)) {
414  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelTKFECConfig" << std::endl;
415  assert(dir == "tkfecconfig");
416  data = (T*)new PixelTKFECConfig(fullpath + "tkfecconfig.dat");
417  return;
418  } else if (typeid(data) == typeid(PixelFECConfig*)) {
419  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelFECConfig" << std::endl;
420  assert(dir == "fecconfig");
421  data = (T*)new PixelFECConfig(fullpath + "fecconfig.dat");
422  return;
423  } else if (typeid(data) == typeid(PixelFEDConfig*)) {
424  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelFEDConfig" << std::endl;
425  assert(dir == "fedconfig");
426  data = (T*)new PixelFEDConfig(fullpath + "fedconfig.dat");
427  return;
428  } else if (typeid(data) == typeid(PixelPortCardConfig*)) {
429  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelPortCardConfig" << std::endl;
430  assert(dir == "portcard");
431  data = (T*)new PixelPortCardConfig(fullpath + "portcard_" + ext + ".dat");
432  return;
433  } else if (typeid(data) == typeid(PixelPortcardMap*)) {
434  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelPortcardMap" << std::endl;
435  assert(dir == "portcardmap");
436  data = (T*)new PixelPortcardMap(fullpath + "portcardmap.dat");
437  return;
438  } else if (typeid(data) == typeid(PixelDelay25Calib*)) {
439  //cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelDelay25Calib" << std::endl;
440  assert(dir == "portcard");
441  data = (T*)new PixelDelay25Calib(fullpath + "delay25.dat");
442  return;
443  } else if (typeid(data) == typeid(PixelTTCciConfig*)) {
444  //cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelTTCciConfig" << std::endl;
445  assert(dir == "ttcciconfig");
446  data = (T*)new PixelTTCciConfig(fullpath + "TTCciConfiguration.txt");
447  return;
448  } else if (typeid(data) == typeid(PixelLTCConfig*)) {
449  //cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelLTCConfig" << std::endl;
450  assert(dir == "ltcconfig");
451  data = (T*)new PixelLTCConfig(fullpath + "LTCConfiguration.txt");
452  return;
453  } else if (typeid(data) == typeid(PixelGlobalDelay25*)) {
454  //std::cout << "[pos::PixelConfigFile::get()]\t\t\tWill return PixelGlobalDelay25" << std::endl;
455  assert(dir == "globaldelay25");
456  data = (T*)new PixelGlobalDelay25(fullpath + "globaldelay25.dat");
457  return;
458  } else {
459  std::cout << "[pos::PixelConfigFile::get()]\t\t\tNo match" << std::endl;
460  assert(0);
461  }
462  } catch (std::exception& e) {
463  std::cout << "[PixelConfigFile::get] Caught exception while constructing configuration object. Will rethrow."
464  << std::endl;
465  throw;
466  }
467  }
468 
469  //----- Method added by Dario (March 10, 2008)
470  template <class T>
472  std::string mthn = "]\t[pos::PixelConfigFile::configurationDataExists()]\t ";
473  /* pos::PixelTimeFormatter * timer = new pos::PixelTimeFormatter("PixelConfigFile::ConfigurationDataExists") ; */
474  unsigned int theKey = key.key();
475 
476  assert(theKey <= configList().size());
477 
478  unsigned int last = path.find_last_of("/");
479  assert(last != (unsigned int)std::string::npos);
480 
481  std::string base = path.substr(0, last);
482  std::string ext = path.substr(last + 1);
483 
484  unsigned int slashpos = base.find_last_of("/");
485  if (slashpos == (unsigned int)std::string::npos) {
486  std::cout << __LINE__ << mthn << "Asking for data of type:" << typeid(data).name() << std::endl;
487  std::cout << __LINE__ << mthn << "On path:" << path << std::endl;
488  std::cout << __LINE__ << mthn << "Recall that you need a trailing /" << std::endl;
489  ::abort();
490  }
491 
492  std::string dir = base.substr(slashpos + 1);
493  /* timer->stopTimer() ; */
494  // std::cout << __LINE__ << mthn << "Extracted dir:" << dir <<std::endl;
495  // std::cout << __LINE__ << mthn << "Extracted base:" << base <<std::endl;
496  // std::cout << __LINE__ << mthn << "Extracted ext :" << ext <<std::endl;
497 
498  unsigned int version = 0;
499  int err = configList()[theKey].find(dir, version);
500  // assert(err==0);
501  if (0 != err) {
502  data = 0;
503  return false;
504  }
505  /* timer->stopTimer() ; */
506  /* delete timer ; */
507 
508  std::ostringstream s1;
509  s1 << version;
510  std::string strversion = s1.str();
511 
512  static std::string directory;
513  directory = std::getenv("PIXELCONFIGURATIONBASE");
514 
515  std::string fullpath = directory + "/" + dir + "/" + strversion + "/";
516 
517  //std::cout << __LINE__ << mthn << "Directory for configuration data:"<<fullpath<<std::endl;
518 
520  if (typeid(data) == typeid(PixelTrimBase*)) {
521  fileName = fullpath + "ROC_Trims_module_" + ext + ".dat";
522  } else if (typeid(data) == typeid(PixelMaskBase*)) {
523  fileName = fullpath + "ROC_Masks_module_" + ext + ".dat";
524  } else if (typeid(data) == typeid(PixelDACSettings*)) {
525  fileName = fullpath + "ROC_DAC_module_" + ext + ".dat";
526  } else if (typeid(data) == typeid(PixelTBMSettings*)) {
527  fileName = fullpath + "TBM_module_" + ext + ".dat";
528  } else if (typeid(data) == typeid(PixelDetectorConfig*)) {
529  fileName = fullpath + "detectconfig.dat";
530  } else if (typeid(data) == typeid(PixelLowVoltageMap*)) {
531  fileName = fullpath + "lowvoltagemap.dat";
532  } else if (typeid(data) == typeid(PixelMaxVsf*)) {
533  fileName = fullpath + "maxvsf.dat";
534  } else if (typeid(data) == typeid(PixelNameTranslation*)) {
535  fileName = fullpath + "translation.dat";
536  } else if (typeid(data) == typeid(PixelFEDCard*)) {
537  fileName = fullpath + "params_fed_" + ext + ".dat";
538  } else if (typeid(data) == typeid(PixelTKFECConfig*)) {
539  fileName = fullpath + "tkfecconfig.dat";
540  } else if (typeid(data) == typeid(PixelFECConfig*)) {
541  fileName = fullpath + "fecconfig.dat";
542  } else if (typeid(data) == typeid(PixelFEDConfig*)) {
543  fileName = fullpath + "fedconfig.dat";
544  } else if (typeid(data) == typeid(PixelPortCardConfig*)) {
545  fileName = fullpath + "portcard_" + ext + ".dat";
546  } else if (typeid(data) == typeid(PixelPortcardMap*)) {
547  fileName = fullpath + "portcardmap.dat";
548  } else if (typeid(data) == typeid(PixelDelay25Calib*)) {
549  fileName = fullpath + "delay25.dat";
550  } else if (typeid(data) == typeid(PixelTTCciConfig*)) {
551  fileName = fullpath + "TTCciConfiguration.txt";
552  } else if (typeid(data) == typeid(PixelLTCConfig*)) {
553  fileName = fullpath + "LTCConfiguration.txt";
554  } else if (typeid(data) == typeid(PixelGlobalDelay25*)) {
555  fileName = fullpath + "globaldelay25.dat";
556  } else if (typeid(data) == typeid(PixelCalibBase*)) {
557  assert(dir == "calib");
558  std::string calibfile = fullpath + "calib.dat";
559  std::ifstream calibin(calibfile.c_str());
560  if (calibin.good()) {
561  std::cout << __LINE__ << mthn << "Found " << calibfile << std::endl;
562  return true;
563  } else {
564  calibfile = fullpath + "delay25.dat";
565  std::ifstream delayin(calibfile.c_str());
566  if (delayin.good()) {
567  std::cout << __LINE__ << mthn << "Found " << calibfile << std::endl;
568  return true;
569  } else {
570  calibfile = fullpath + "fedtestdac.dat";
571  std::ifstream delayin(calibfile.c_str());
572  if (delayin.good()) {
573  std::cout << __LINE__ << mthn << "Found " << calibfile << std::endl;
574  return true;
575  } else {
576  std::cout << mthn << "Can't find calibration file calib.dat or delay25.dat or fedtestdac.dat"
577  << std::endl;
578  return false;
579  }
580  }
581  }
582  } else {
583  std::cout << __LINE__ << mthn << "No match of class type" << std::endl;
584  return false;
585  }
586  /*
587  struct stat * tmp = NULL ;
588  if(stat(fileName.c_str(), tmp)==0)
589  {
590  std::cout << mthn << "Found(stat) " << fileName << std::endl ;
591  return true ;
592  }
593  else
594  {
595  std::cout << mthn << "Not found(stat) " << fileName << std::endl ;
596  return false ;
597  }
598  */
599  std::ifstream in(fileName.c_str());
600  if (!in.good()) {
601  std::cout << __LINE__ << mthn << "Not found " << fileName << std::endl;
602  return false;
603  }
604  in.close();
605  if (DEBUG_CF_)
606  std::cout << __LINE__ << mthn << "Found " << fileName << std::endl;
607  return true;
608  }
609  //----- End of method added by Dario (March 10, 2008)
610 
611  //Returns a pointer to the data found in the path with configuration key.
612  template <class T>
613  static void get(T*& data, std::string path, unsigned int version) {
614  std::string mthn = "]\t[pos::PixelConfigFile::get()]\t\t\t\t ";
615 
616  unsigned int last = path.find_last_of("/");
617  assert(last != (unsigned int)std::string::npos);
618 
619  std::string base = path.substr(0, last);
620  std::string ext = path.substr(last + 1);
621 
622  unsigned int slashpos = base.find_last_of("/");
623  //if (slashpos==std::string::npos) {
624  //std::cout << __LINE__ << mthn << "Asking for data of type:" << typeid(data).name() << std::endl;
625  //std::cout << __LINE__ << mthn << "On path:" << path << std::endl;
626  //std::cout << __LINE__ << mthn << "Recall that you need a trailing /" << std::endl;
627  //::abort();
628  //}
629 
630  std::string dir = base.substr(slashpos + 1);
631 
632  //std::cout << __LINE__ << mthn << "Extracted dir :" << dir <<std::endl;
633  //std::cout << __LINE__ << mthn << "Extracted base:" << base <<std::endl;
634  //std::cout << __LINE__ << mthn << "Extracted ext :" << ext <<std::endl;
635 
636  std::ostringstream s1;
637  s1 << version;
638  std::string strversion = s1.str();
639 
640  static std::string directory;
641  directory = std::getenv("PIXELCONFIGURATIONBASE");
642 
643  std::string fullpath = directory + "/" + dir + "/" + strversion + "/";
644 
645  //std::cout << __LINE__ << mthn << "Directory for configuration data:"<<fullpath<<std::endl;
646 
647  if (typeid(data) == typeid(PixelTrimBase*)) {
648  //std::cout << __LINE__ << mthn << "Will return PixelTrimBase" << std::endl;
649  assert(dir == "trim");
650  data = (T*)new PixelTrimAllPixels(fullpath + "ROC_Trims_module_" + ext + ".dat");
651  return;
652  } else if (typeid(data) == typeid(PixelMaskBase*)) {
653  //std::cout << __LINE__ << mthn << "Will return PixelMaskBase" << std::endl;
654  assert(dir == "mask");
655  data = (T*)new PixelMaskAllPixels(fullpath + "ROC_Masks_module_" + ext + ".dat");
656  return;
657  } else if (typeid(data) == typeid(PixelDACSettings*)) {
658  //std::cout << __LINE__ << mthn << "Will return PixelDACSettings" << std::endl;
659  assert(dir == "dac");
660  data = (T*)new PixelDACSettings(fullpath + "ROC_DAC_module_" + ext + ".dat");
661  return;
662  } else if (typeid(data) == typeid(PixelTBMSettings*)) {
663  //std::cout << __LINE__ << mthn << "Will return PixelTBMSettings" << std::endl;
664  assert(dir == "tbm");
665  data = (T*)new PixelTBMSettings(fullpath + "TBM_module_" + ext + ".dat");
666  return;
667  } else if (typeid(data) == typeid(PixelDetectorConfig*)) {
668  //std::cout << __LINE__ << mthn << "Will return PixelDACSettings" << std::endl;
669  assert(dir == "detconfig");
670  data = (T*)new PixelDetectorConfig(fullpath + "detectconfig.dat");
671  return;
672  } else if (typeid(data) == typeid(PixelLowVoltageMap*)) {
673  //std::cout << __LINE__ << mthn << "Will fetch1 PixelLowVoltageMap" << std::endl;
674  assert(dir == "lowvoltagemap");
675  data = (T*)new PixelLowVoltageMap(fullpath + "detectconfig.dat");
676  //std::cout << __LINE__ << mthn << "Will return1 the PixelLowVoltageMap" << std::endl;
677  return;
678  } else if (typeid(data) == typeid(PixelMaxVsf*)) {
679  //std::cout << __LINE__ << mthn << "Will fetch1 PixelMaxVsf" << std::endl;
680  assert(dir == "maxvsf");
681  data = (T*)new PixelMaxVsf(fullpath + "maxvsf.dat");
682  //std::cout << __LINE__ << mthn << "Will return1 the PixelMaxVsf" << std::endl;
683  return;
684  } else if (typeid(data) == typeid(PixelNameTranslation*)) {
685  //std::cout << __LINE__ << mthn << "Will return PixelNameTranslation" << std::endl;
686  assert(dir == "nametranslation");
687  data = (T*)new PixelNameTranslation(fullpath + "translation.dat");
688  return;
689  } else if (typeid(data) == typeid(PixelFEDCard*)) {
690  //std::cout << __LINE__ << mthn << "Will return PixelFEDCard" << std::endl;
691  assert(dir == "fedcard");
692  //std::cout << __LINE__ << mthn << "Will open:"<<fullpath+"params_fed_"+ext+".dat"<< std::endl;
693  data = (T*)new PixelFEDCard(fullpath + "params_fed_" + ext + ".dat");
694  return;
695  } else if (typeid(data) == typeid(PixelCalibBase*)) {
696  //std::cout << __LINE__ << mthn << "Will return PixelCalibBase" << std::endl;
697  assert(base == "calib");
698  std::string calibfile = fullpath + "calib.dat";
699  //std::cout << mthn << "Looking for file " << calibfile << std::endl;
700  std::ifstream calibin(calibfile.c_str());
701  if (calibin.good()) {
702  data = (T*)new PixelCalibConfiguration(calibfile);
703  } else {
704  calibfile = fullpath + "delay25.dat";
705  //std::cout << __LINE__ << mthn << "Now looking for file " << calibfile << std::endl;
706  std::ifstream delayin(calibfile.c_str());
707  if (delayin.good()) {
708  data = (T*)new PixelDelay25Calib(calibfile);
709  } else {
710  calibfile = fullpath + "fedtestdac.dat";
711  //std::cout << __LINE__ << mthn << "Now looking for file " << calibfile << std::endl;
712  std::ifstream delayin(calibfile.c_str());
713  if (delayin.good()) {
714  data = (T*)new PixelFEDTestDAC(calibfile);
715  } else {
716  std::cout << __LINE__ << mthn << "Can't find calibration file calib.dat or delay25.dat or fedtestdac.dat"
717  << std::endl;
718  data = 0;
719  }
720  }
721  }
722  return;
723  } else if (typeid(data) == typeid(PixelTKFECConfig*)) {
724  //std::cout << __LINE__ << mthn << "Will return PixelTKFECConfig" << std::endl;
725  assert(dir == "tkfecconfig");
726  data = (T*)new PixelTKFECConfig(fullpath + "tkfecconfig.dat");
727  return;
728  } else if (typeid(data) == typeid(PixelFECConfig*)) {
729  //std::cout << __LINE__ << mthn << "Will return PixelFECConfig" << std::endl;
730  assert(dir == "fecconfig");
731  data = (T*)new PixelFECConfig(fullpath + "fecconfig.dat");
732  return;
733  } else if (typeid(data) == typeid(PixelFEDConfig*)) {
734  //std::cout << __LINE__ << mthn << "Will return PixelFEDConfig" << std::endl;
735  assert(dir == "fedconfig");
736  data = (T*)new PixelFEDConfig(fullpath + "fedconfig.dat");
737  return;
738  } else if (typeid(data) == typeid(PixelPortCardConfig*)) {
739  //std::cout << __LINE__ << mthn << "Will return PixelPortCardConfig" << std::endl;
740  assert(dir == "portcard");
741  data = (T*)new PixelPortCardConfig(fullpath + "portcard_" + ext + ".dat");
742  return;
743  } else if (typeid(data) == typeid(PixelPortcardMap*)) {
744  //std::cout << __LINE__ << mthn << "Will return PixelPortcardMap" << std::endl;
745  assert(dir == "portcardmap");
746  data = (T*)new PixelPortcardMap(fullpath + "portcardmap.dat");
747  return;
748  } else if (typeid(data) == typeid(PixelDelay25Calib*)) {
749  //cout << __LINE__ << mthn << "Will return PixelDelay25Calib" << std::endl;
750  assert(dir == "portcard");
751  data = (T*)new PixelDelay25Calib(fullpath + "delay25.dat");
752  return;
753  } else if (typeid(data) == typeid(PixelTTCciConfig*)) {
754  //cout << __LINE__ << mthn << "Will return PixelTTCciConfig" << std::endl;
755  assert(dir == "ttcciconfig");
756  data = (T*)new PixelTTCciConfig(fullpath + "TTCciConfiguration.txt");
757  return;
758  } else if (typeid(data) == typeid(PixelLTCConfig*)) {
759  //cout << __LINE__ << mthn << "Will return PixelLTCConfig" << std::endl;
760  assert(dir == "ltcconfig");
761  data = (T*)new PixelLTCConfig(fullpath + "LTCConfiguration.txt");
762  return;
763  } else if (typeid(data) == typeid(PixelGlobalDelay25*)) {
764  //std::cout << __LINE__ << mthn << "Will return PixelGlobalDelay25" << std::endl;
765  assert(dir == "globaldelay25");
766  data = (T*)new PixelGlobalDelay25(fullpath + "globaldelay25.dat");
767  return;
768  } else {
769  std::cout << __LINE__ << mthn << "No class match" << std::endl;
770  assert(0);
771  data = 0;
772  return;
773  }
774  }
775 
776  template <class T>
777  static void get(std::map<std::string, T*>& pixelObjects, PixelConfigKey key) {
778  typename std::map<std::string, T*>::iterator iObject = pixelObjects.begin();
779 
780  for (; iObject != pixelObjects.end(); ++iObject) {
781  get(iObject->second, iObject->first, key);
782  }
783  }
784 
786  //std::cout << "[pos::PixelConfigFile::makeNewVersion()]\t\tInserting data on path:"<<path<<std::endl;
787  struct stat stbuf;
788  std::string directory = std::getenv("PIXELCONFIGURATIONBASE");
789  directory += "/";
790  directory += path;
791  if (stat(directory.c_str(), &stbuf) != 0) {
792  std::cout << "[pos::PixelConfigFile::makeNewVersion()]\t\tThe path:" << path << " does not exist." << std::endl;
793  std::cout << "[pos::PixelConfigFile::makeNewVersion()]\t\tFull path:" << directory << std::endl;
794  return -1;
795  }
796  directory += "/";
797  int version = -1;
798  do {
799  version++;
800  std::ostringstream s1;
801  s1 << version;
802  std::string strversion = s1.str();
803  dir = directory + strversion;
804  //std::cout << "[pos::PixelConfigFile::makeNewVersion()]\t\tWill check for version:"<<dir<<std::endl;
805  } while (stat(dir.c_str(), &stbuf) == 0);
806  //std::cout << "[pos::PixelConfigFile::makeNewVersion()]\t\tThe new version is:"<<version<<std::endl;
807  mkdir(dir.c_str(), 0777);
808  return version;
809  }
810 
811  template <class T>
812  static int put(const T* object, std::string path) {
814  int version = makeNewVersion(path, dir);
815  object->writeASCII(dir);
816  return version;
817  }
818 
819  template <class T>
820  static int put(std::vector<T*> objects, std::string path) {
821  std::cout << "[pos::PixelConfigFile::put()]\t\t# of objects to write: " << objects.size() << std::endl;
823  int version = makeNewVersion(path, dir);
824  for (unsigned int i = 0; i < objects.size(); i++) {
825  // std::cout << "[pos::PixelConfigFile::put()]\t\t\t\t\tWill write i="<<i<<" ptr: "<<objects[i]<<std::endl;
826  objects[i]->writeASCII(dir);
827  }
828  return version;
829  }
830 
831  private:
832  static bool& getForceAliasesReload() {
833  static bool forceAliasesReload = false;
834  return forceAliasesReload;
835  }
836  static bool& getForceConfigReload() {
837  static bool forceConfigReload = false;
838  return forceConfigReload;
839  }
840  };
841 
842 } // namespace pos
843 #endif
size
Write out results.
This class specifies which TKFEC boards are used and how they are addressed.
This class specifies which delay25 channels are delayed over the entire pixel detector and by how muc...
unsigned int getVersion(std::string path, std::string alias)
std::vector< std::pair< std::string, std::string > > versionAliases()
This class specifies which detector components are used in the configuration (and eventually should s...
static void addAlias(std::string alias, unsigned int key, std::vector< std::pair< std::string, std::string > > versionaliases)
void readfile(std::string filename)
This class specifies which FEC boards are used and how they are addressed.
static void addAlias(std::string alias, unsigned int key)
static bool & getForceAliasesReload()
This class implements..
pathVersionAliasMmap getVersionData()
static std::vector< pathAliasPair > getConfigAliases(std::string path)
static PixelAliasList & getAlias()
void updateConfigAlias(std::string path, unsigned int version, std::string alias, PixelConfigList &config)
std::vector< std::pair< std::string, unsigned int > > versions()
Definition: PixelConfig.h:62
void add(std::string dir, unsigned int version)
Definition: PixelConfig.h:30
This class provides the mapping between portcards and the modules controlled by the card...
static std::map< std::string, unsigned int > getAliases_map()
static int put(const T *object, std::string path)
base
Main Program
Definition: newFWLiteAna.py:92
This class specifies which FEC boards are used and how they are addressed.
This class implements..
static PixelConfigList & configList()
std::vector< pathAliasPair > getConfigAliases(std::string path)
static std::vector< std::pair< std::string, unsigned int > > getVersions(pos::PixelConfigKey key)
unsigned int key(unsigned int i)
This class provides a translation from the naming documents standard to specify the ROC to the corres...
U second(std::pair< T, U > const &p)
config
Definition: looper.py:291
static void addVersionAlias(std::string path, unsigned int version, std::string alias)
This class is responsible for manipulating the DACsettings of a ROC.
This class manages data and files used in the Delay25 calibration.
This file contains the base class for "pixel configuration data" management.
void readfile(std::string filename)
Base class for pixel calibration procedures.
This class specifies which TKFEC boards are used and how they are addressed.
This class implements..
static unsigned int getVersion(std::string path, std::string alias)
This class implements the steps that are used in a scan over Threshold and CalDelay.
This class implements..
std::map< std::string, vectorVAPairs > pathVersionAliasMmap
This class implements the configuration key which actually just is an integer.
This is the documentation about PixelDetectorConfig...
static std::vector< std::pair< std::string, unsigned int > > getAliases()
The class to handle &#39;aliases.txt&#39;.
static void forceAliasesReload(bool m)
This is the documentation about PixelLTCConfig...
static pos::pathVersionAliasMmap getVersionData(std::string koc)
This is the documentation about PixelLowVoltageMap...
std::string name(unsigned int i)
void insertVersionAlias(PixelVersionAlias &anAlias)
static int put(std::vector< T * > objects, std::string path)
This class provide a base class for the pixel ROC dac data for the pixel FEC configuration.
This is the documentation about PixelMaskAllPixels...
unsigned int add(PixelConfig &aConfig)
This is the documentation about PixelMaskBase...
Definition: PixelMaskBase.h:36
static bool & getForceConfigReload()
This is the documentation about PixelNameTranslation...
This class implements..
void addVersionAlias(std::string path, std::string alias)
void insertAlias(PixelConfigAlias &anAlias)
unsigned int key()
std::vector< std::string > getVersionAliases(std::string path)
This class implements..
static std::string getPath(std::string path, PixelConfigKey key)
unsigned int nAliases()
static unsigned int makeKey(std::vector< std::pair< std::string, unsigned int > > versions)
This class implements the configuration key which actually just is an integer.
This class manages data and files used in the Delay25 calibration.
This class implements..
This class provides a base class for the pixel trim data for the pixel FEC configuration.
static std::vector< std::string > getVersionAliases(std::string path)
This is the documentation about PixelNameTranslation...
This class implements..
def mkdir(path)
Definition: eostools.py:251
This class specifies the maximum Vsf setting that should be used for each ROC.
PixelConfigAlias * versionAliases(std::string aliasName)
static pos::pathVersionAliasMmap getVersionData()
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
This is the documentation about PixelFEDConfig...
#define DEBUG_CF_
void reload(std::string filename)
static int makeNewVersion(std::string path, std::string &dir)
This class implements..
Definition: PixelTrimBase.h:45
This is the documentation about PixelMaxVsf...
Definition: PixelMaxVsf.h:26
This class implements the steps that are used in a scan over Threshold and CalDelay.
static void forceConfigReload(bool m)
static bool getVersionAliases(std::string configAlias, unsigned int &key, std::vector< std::pair< std::string, std::string > > &versionAliases)
This is the documentation about PixelFEDCard...
Definition: PixelFEDCard.h:27
This class implements..
Definition: memstream.h:15
tmp
align.sh
Definition: createJobs.py:716
long double T
This class specifies the settings on the TKPCIFEC and the settings on the portcard.
This class implements..
static PixelConfigList & getConfig()
static bool configurationDataExists(T *&data, std::string path, PixelConfigKey key)
This class specifies which delay25 channels are delayed over the entire pixel detector and by how muc...
This class implements..
Definition: PixelConfig.h:20
This is the documentation about PixelTBMSettings...
This class implements the steps that are used in a scan over Threshold and CalDelay.