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