1 #include "VersionManager.hxx" 2 #include "BasicTypes.hxx" 20 PackageVersion::PackageVersion(
const std::string& name,
const std::string& version){
47 Versioning::Versioning():
HLClonesArray(
"config",
"VERSION",
"PackageVersion",NMAXPACKAGES){
54 void Versioning::AddProduction(ProdId_h prodId,
const std::string& prodName,
const std::string& prodLowVersion,
const std::string& prodHighVersion){
57 _prodId.push_back(prodId);
58 _prodName.push_back(prodName);
59 _prodLowVersion.push_back(prodLowVersion);
60 _prodHighVersion.push_back(prodHighVersion);
67 for (UInt_t i=0;i<_prodId.size();i++){
68 if( !CheckBeforeVersion(softVersion, _prodLowVersion[i]) && CheckBeforeVersion(softVersion, _prodHighVersion[i]))
72 return UNKNOWN_PRODUCTION;
79 return ConvertProduction(GetProduction(softVersion));
83 std::string Versioning::ConvertProduction(ProdId_h prod){
86 for (UInt_t i=0;i<_prodId.size();i++){
87 if (prod == _prodId[i])
return _prodName[i];
93 bool Versioning::GetSoftwareVersionRangeForProduction(ProdId_h prodId, std::string& lowVersion, std::string& highVersion){
96 for (UInt_t i=0;i<_prodId.size();i++){
97 if (_prodId[i] == prodId){
98 lowVersion = _prodLowVersion[i];
99 highVersion= _prodHighVersion[i];
113 std::string prodLow, prodHigh;
116 GetSoftwareVersionRangeForProduction(prodND280, prodLow, prodHigh);
119 ProdId_h prodInputFile = GetProduction(version);
122 std::cerr <<
"nd280AnalysisTools compiled with " << ConvertProduction(prodND280) <<
" (software version: " << prodLow <<
" - " << prodHigh <<
") file. " << std::endl;
123 std::cerr <<
"Checking for compatibility version with current file (software version: " << version <<
")" << std::endl;
124 if (prodInputFile != prodND280){
126 std::cerr <<
"*************************************************" << std::endl;
127 std::cerr <<
"*************************************************" << std::endl;
128 std::cerr <<
"WARNING: Running over a " << ConvertProduction(prodInputFile) <<
" file !!!!!" << std::endl;
129 std::cerr <<
"oaAnalysis data classes definition could be incompatible !!!!" << std::endl;
130 std::cerr <<
"You should compile nd280AnalysisTools with the proper file and then recompile highland2 from scratch !!!" << std::endl;
131 std::cerr <<
"You could also disable version check with command line option -v" << std::endl;
132 std::cerr <<
"*************************************************" << std::endl;
133 std::cerr <<
"*************************************************" << std::endl;
136 std::cout <<
"---> OK. Running over a " << ConvertProduction(prodND280) <<
" file" << std::endl;
143 bool Versioning::CheckBeforeVersion(
const std::string& version,
const std::string& version0){
148 ParseSoftwareVersion(version, v, r, p);
149 ParseSoftwareVersion(version0, v0,r0,p0);
151 if (v<v0)
return true;
153 if (r<r0)
return true;
155 if (p<p0)
return true;
164 void Versioning::ParseSoftwareVersion(
const std::string& version,
int& v,
int& r,
int& p) {
167 int vloc = version.find(
"v");
168 int rloc = version.find(
"r");
169 int ploc = version.find(
"p");
170 int size = version.length();
172 if ((
size_t)vloc == std::string::npos) {
173 std::cerr <<
"*************************************************" << std::endl;
174 std::cerr <<
"*************************************************" << std::endl;
175 std::cerr <<
"WARNING: SoftwareVersion '" << version <<
"' is not a valid format. This is probably and OLD highland FlatTree !" << std::endl;
176 std::cerr <<
"You could disable version check with command line option -v" << std::endl;
177 std::cerr <<
"*************************************************" << std::endl;
178 std::cerr <<
"*************************************************" << std::endl;
182 if ((
size_t)rloc == std::string::npos) {
184 v = std::atoi(version.substr(vloc+1, size - vloc-1).c_str());
187 }
else if ((
size_t)ploc == std::string::npos) {
189 v = std::atoi(version.substr(vloc+1, rloc - vloc-1).c_str());
190 r = std::atoi(version.substr(rloc+1, size - rloc-1).c_str());
194 v = std::atoi(version.substr(vloc+1, rloc - vloc-1).c_str());
195 r = std::atoi(version.substr(rloc+1, ploc - rloc-1).c_str());
196 p = std::atoi(version.substr(ploc+1, size - ploc-1).c_str());
204 for (UInt_t i=0;i<_packages.size();i++){
205 if (_packages[i]->
Name() == name){
206 if (_packages[i]->
Version() != version){
207 std::cerr <<
"*************************************************" << std::endl;
208 std::cerr <<
"*************************************************" << std::endl;
209 std::cerr <<
"ERROR: Package '" << name <<
"' has been added twice with two different versions "<< _packages[i]->Version() <<
" and " << version <<
" !!!!" << std::endl;
210 std::cerr <<
"*************************************************" << std::endl;
211 std::cerr <<
"*************************************************" << std::endl;
219 _packages.push_back(pack);
220 (*_objects)[_NObjects++] = pack;
230 ReadClonesArray(file);
233 for (
int i=0;i<_NObjects;i++){
235 _packages.push_back(pack);
243 std::cout <<
" ------ List of highland2 package Versions ---------" << std::endl;
245 sprintf(out,
"%3s: %-30s %-15s",
"#",
"package",
"version");
246 std::cout << out <<
"\n" << std::endl;
248 for (UInt_t i=0;i<_packages.size();i++){
250 sprintf(out,
"%3d: %-30s %-15s", i, pack->
Name().c_str(), pack->
Version().c_str());
251 std::cout << out << std::endl;
253 std::cout <<
" ----------------------------------------------------" << std::endl;
bool CheckVersionCompatibility(const std::string &versionInput, ProdId_h prodND280)
Check compatibility between input file software version and file used to compile nd280AnalysisTools.
const std::string & Version() const
Return the version of this package.
void ReadVersions(const std::string &file)
Read package names and versions use to produce this file.
void AddPackage(const std::string &name, const std::string &version)
Add a package.
std::string _version
The name of this package.
ProdId_h GetProduction(const std::string softVersion)
Get the enum of the production corresponding to a given sofware version.
static Versioning & Get(void)
return the singleton
void DumpVersions()
dump package names and versions
std::string _name
The name of this package.
void AddProduction(ProdId_h prodId, const std::string &prodName, const std::string &prodLowVersion, const std::string &prodHighVersion)
Add a production.
const std::string & Name() const
Return the name of this package.
std::string GetProductionName(const std::string softVersion)
Get the name of the production corresponding to a given sofware version.