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