CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Fireworks/Core/src/fwPaths.cc

Go to the documentation of this file.
00001 #include "Fireworks/Core/interface/fwPaths.h"
00002 #include "Fireworks/Core/interface/fwLog.h"      
00003 #include "TString.h"
00004 #include "TSystem.h"
00005 #include "TPRegexp.h"
00006 #include <iostream>
00007 #include <fstream>
00008 
00009 namespace fireworks  {
00010 
00011 const TString datadir("/src/Fireworks/Core/") ;          
00012 const TString p1 = gSystem->Getenv("CMSSW_BASE") + datadir;      
00013 const TString p2 = gSystem->Getenv("CMSSW_RELEASE_BASE") + datadir;
00014 
00015 void setPath( TString& v)
00016 {
00017    if (gSystem->AccessPathName(p1 + v) == kFALSE)
00018    {
00019       v.Prepend(p1);
00020       return;
00021    }
00022 
00023    v.Prepend(p2);
00024    if (gSystem->AccessPathName(v))
00025       fwLog(fwlog::kError) << "Can't access path " << v << std::endl;
00026 }
00027 
00028 
00029 
00030 void getDecomposedVersion(const TString& s, int* out)
00031 {
00032    TPMERegexp re("CMSSW_(\\d+)_(\\d+)_(\\d+)");
00033    re.Match(s);
00034    if (re.NMatches() > 3)
00035    {
00036       out[0] = re[1].Atoi();
00037       out[1] = re[2].Atoi();
00038       out[2] = re[3].Atoi();
00039    }
00040 }
00041 
00042 
00043 
00044 int* supportedDataFormatsVersion()
00045 {
00046    static int mm[] = {0, 0, 0};
00047 
00048    if (!mm[0]) {
00049       TString v;
00050       if (gSystem->Getenv("CMSSW_VERSION"))
00051       {
00052          v = gSystem->Getenv("CMSSW_VERSION");
00053 
00054       }
00055       else
00056       {
00057          TString versionFileName = gSystem->Getenv("CMSSW_BASE");
00058          versionFileName += "/src/Fireworks/Core/data/version.txt";
00059          ifstream fs(versionFileName);
00060          TString infoText;
00061          infoText.ReadLine(fs); infoText.ReadLine(fs);
00062          fs.close();
00063          v = &infoText[13];
00064       }
00065 
00066       getDecomposedVersion(v, &mm[0]);
00067    }
00068 
00069    return &mm[0];
00070 }
00071 
00072 bool acceptDataFormatsVersion(TString& processConfigurationVersion)
00073 {
00074    int data[] = {0, 0, 0};
00075    getDecomposedVersion(processConfigurationVersion, data);
00076 
00077 
00078    int* running = supportedDataFormatsVersion();
00079    if ((data[0] == 6 && running[0] == 5 && running[1] > 1) ||
00080        (data[0] == 5 && data[1] > 1 && running[0] == 6))
00081       return true;
00082    else
00083       return data[0] == running[0];
00084 }
00085 
00086 }