some slight improvement in the error handling
This commit is contained in:
45
src/external/MusrRoot/TMusrRunHeader.cpp
vendored
45
src/external/MusrRoot/TMusrRunHeader.cpp
vendored
@ -214,9 +214,9 @@ ClassImp(TMusrRunHeader)
|
|||||||
/**
|
/**
|
||||||
* <p>Constructor.
|
* <p>Constructor.
|
||||||
*
|
*
|
||||||
* \param quite if set to true, warnings will be omited. Default is false.
|
* \param quiet if set to true, warnings will be omited. Default is false.
|
||||||
*/
|
*/
|
||||||
TMusrRunHeader::TMusrRunHeader(bool quite) : fQuite(quite)
|
TMusrRunHeader::TMusrRunHeader(bool quiet) : fQuiet(quiet)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
@ -228,11 +228,11 @@ TMusrRunHeader::TMusrRunHeader(bool quite) : fQuite(quite)
|
|||||||
* <p>Constructor.
|
* <p>Constructor.
|
||||||
*
|
*
|
||||||
* \param fileName file name of the MusrRoot file.
|
* \param fileName file name of the MusrRoot file.
|
||||||
* \param quite if set to true, warnings will be omited. Default is false.
|
* \param quiet if set to true, warnings will be omited. Default is false.
|
||||||
*/
|
*/
|
||||||
TMusrRunHeader::TMusrRunHeader(const char *fileName, bool quite)
|
TMusrRunHeader::TMusrRunHeader(const char *fileName, bool quiet)
|
||||||
{
|
{
|
||||||
fQuite = quite;
|
fQuiet = quiet;
|
||||||
Init(TString(fileName));
|
Init(TString(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,7 +564,7 @@ void TMusrRunHeader::Set(TString pathName, TString value)
|
|||||||
UInt_t i=0;
|
UInt_t i=0;
|
||||||
for (i=0; i<fStringObj.size(); i++) {
|
for (i=0; i<fStringObj.size(); i++) {
|
||||||
if (!fStringObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
if (!fStringObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
||||||
if (!fQuite)
|
if (!fQuiet)
|
||||||
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
||||||
fStringObj[i].SetType("TString");
|
fStringObj[i].SetType("TString");
|
||||||
fStringObj[i].SetValue(value);
|
fStringObj[i].SetValue(value);
|
||||||
@ -598,7 +598,7 @@ void TMusrRunHeader::Set(TString pathName, Int_t value)
|
|||||||
UInt_t i=0;
|
UInt_t i=0;
|
||||||
for (i=0; i<fIntObj.size(); i++) {
|
for (i=0; i<fIntObj.size(); i++) {
|
||||||
if (!fIntObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
if (!fIntObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
||||||
if (!fQuite)
|
if (!fQuiet)
|
||||||
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
||||||
fIntObj[i].SetType("Int_t");
|
fIntObj[i].SetType("Int_t");
|
||||||
fIntObj[i].SetValue(value);
|
fIntObj[i].SetValue(value);
|
||||||
@ -632,7 +632,7 @@ void TMusrRunHeader::Set(TString pathName, Double_t value)
|
|||||||
UInt_t i=0;
|
UInt_t i=0;
|
||||||
for (i=0; i<fDoubleObj.size(); i++) {
|
for (i=0; i<fDoubleObj.size(); i++) {
|
||||||
if (!fDoubleObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
if (!fDoubleObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
||||||
if (!fQuite)
|
if (!fQuiet)
|
||||||
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
||||||
fDoubleObj[i].SetType("Double_t");
|
fDoubleObj[i].SetType("Double_t");
|
||||||
fDoubleObj[i].SetValue(value);
|
fDoubleObj[i].SetValue(value);
|
||||||
@ -666,7 +666,7 @@ void TMusrRunHeader::Set(TString pathName, TMusrRunPhysicalQuantity value)
|
|||||||
UInt_t i=0;
|
UInt_t i=0;
|
||||||
for (i=0; i<fMusrRunPhysQuantityObj.size(); i++) {
|
for (i=0; i<fMusrRunPhysQuantityObj.size(); i++) {
|
||||||
if (!fMusrRunPhysQuantityObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
if (!fMusrRunPhysQuantityObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
||||||
if (!fQuite)
|
if (!fQuiet)
|
||||||
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
||||||
fMusrRunPhysQuantityObj[i].SetType("TMusrRunHeader");
|
fMusrRunPhysQuantityObj[i].SetType("TMusrRunHeader");
|
||||||
fMusrRunPhysQuantityObj[i].SetValue(value);
|
fMusrRunPhysQuantityObj[i].SetValue(value);
|
||||||
@ -700,7 +700,7 @@ void TMusrRunHeader::Set(TString pathName, TStringVector value)
|
|||||||
UInt_t i=0;
|
UInt_t i=0;
|
||||||
for (i=0; i<fStringVectorObj.size(); i++) {
|
for (i=0; i<fStringVectorObj.size(); i++) {
|
||||||
if (!fStringVectorObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
if (!fStringVectorObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
||||||
if (!fQuite)
|
if (!fQuiet)
|
||||||
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
||||||
fStringVectorObj[i].SetType("TStringVector");
|
fStringVectorObj[i].SetType("TStringVector");
|
||||||
fStringVectorObj[i].SetValue(value);
|
fStringVectorObj[i].SetValue(value);
|
||||||
@ -734,7 +734,7 @@ void TMusrRunHeader::Set(TString pathName, TIntVector value)
|
|||||||
UInt_t i=0;
|
UInt_t i=0;
|
||||||
for (i=0; i<fIntVectorObj.size(); i++) {
|
for (i=0; i<fIntVectorObj.size(); i++) {
|
||||||
if (!fIntVectorObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
if (!fIntVectorObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
||||||
if (!fQuite)
|
if (!fQuiet)
|
||||||
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
||||||
fIntVectorObj[i].SetType("TIntVector");
|
fIntVectorObj[i].SetType("TIntVector");
|
||||||
fIntVectorObj[i].SetValue(value);
|
fIntVectorObj[i].SetValue(value);
|
||||||
@ -768,7 +768,7 @@ void TMusrRunHeader::Set(TString pathName, TDoubleVector value)
|
|||||||
UInt_t i=0;
|
UInt_t i=0;
|
||||||
for (i=0; i<fDoubleVectorObj.size(); i++) {
|
for (i=0; i<fDoubleVectorObj.size(); i++) {
|
||||||
if (!fDoubleVectorObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
if (!fDoubleVectorObj[i].GetPathName().CompareTo(pathName, TString::kIgnoreCase)) {
|
||||||
if (!fQuite)
|
if (!fQuiet)
|
||||||
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
cerr << endl << ">> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl;
|
||||||
fDoubleVectorObj[i].SetType("TDoubleVector");
|
fDoubleVectorObj[i].SetType("TDoubleVector");
|
||||||
fDoubleVectorObj[i].SetValue(value);
|
fDoubleVectorObj[i].SetValue(value);
|
||||||
@ -843,8 +843,8 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
|||||||
|
|
||||||
// get the run header label
|
// get the run header label
|
||||||
label = GetLabel(str);
|
label = GetLabel(str);
|
||||||
if (label == "n/a")
|
if (label == "n/a") // not a TMusrRunHeader object, hence ignore it
|
||||||
return false;
|
continue;
|
||||||
|
|
||||||
// get the run header 'value'
|
// get the run header 'value'
|
||||||
strValue = GetStrValue(str);
|
strValue = GetStrValue(str);
|
||||||
@ -854,6 +854,8 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
|||||||
|
|
||||||
// get type from map
|
// get type from map
|
||||||
type = GetType(str);
|
type = GetType(str);
|
||||||
|
if (type == "n/a") // not a TMusrRunHeader object, hence ignore it
|
||||||
|
continue;
|
||||||
|
|
||||||
if (type == "TString") {
|
if (type == "TString") {
|
||||||
Set(pathName, strValue);
|
Set(pathName, strValue);
|
||||||
@ -1302,7 +1304,10 @@ TString TMusrRunHeader::GetLabel(TString str)
|
|||||||
Ssiz_t idx1 = str.First('-');
|
Ssiz_t idx1 = str.First('-');
|
||||||
Ssiz_t idx2 = str.First(':');
|
Ssiz_t idx2 = str.First(':');
|
||||||
if ((idx1 == -1) || (idx2 == -1)) {
|
if ((idx1 == -1) || (idx2 == -1)) {
|
||||||
cerr << endl << ">> TMusrRunHeader::GetLabel(): **ERROR** str='" << str << "', seems not correctly encoded." << endl;
|
if (!fQuiet) {
|
||||||
|
cerr << endl << ">> TMusrRunHeader::GetLabel(): **WARNING** str='" << str << "', seems not correctly encoded.";
|
||||||
|
cerr << endl << ">> Will omit it." << endl;
|
||||||
|
}
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1331,7 +1336,10 @@ TString TMusrRunHeader::GetStrValue(TString str)
|
|||||||
Ssiz_t idx1 = str.First(':');
|
Ssiz_t idx1 = str.First(':');
|
||||||
Ssiz_t idx2 = str.Last('-');
|
Ssiz_t idx2 = str.Last('-');
|
||||||
if ((idx1 == -1) || (idx2 == -1)) {
|
if ((idx1 == -1) || (idx2 == -1)) {
|
||||||
cerr << endl << ">> TMusrRunHeader::GetStrValue(): **ERROR** str='" << str << "', seems not correctly encoded." << endl;
|
if (!fQuiet) {
|
||||||
|
cerr << endl << ">> TMusrRunHeader::GetStrValue(): **WARNING** str='" << str << "', seems not correctly encoded.";
|
||||||
|
cerr << endl << ">> Will omit it." << endl;
|
||||||
|
}
|
||||||
return strValue;
|
return strValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1359,7 +1367,10 @@ TString TMusrRunHeader::GetType(TString str)
|
|||||||
Ssiz_t pos = str.Last('@');
|
Ssiz_t pos = str.Last('@');
|
||||||
|
|
||||||
if (pos == -1) { // i.e. NOT found
|
if (pos == -1) { // i.e. NOT found
|
||||||
cerr << endl << ">> TMusrRunHeader::GetType(): **ERROR** str=" << str << " seems to be an invalid MusrROOT run header string." << endl;
|
if (!fQuiet) {
|
||||||
|
cerr << endl << ">> TMusrRunHeader::GetType(): **WARNING** str=" << str << " seems to be an invalid MusrROOT run header string.";
|
||||||
|
cerr << endl << ">> Will omit it." << endl;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
src/external/MusrRoot/TMusrRunHeader.h
vendored
6
src/external/MusrRoot/TMusrRunHeader.h
vendored
@ -125,8 +125,8 @@ private:
|
|||||||
class TMusrRunHeader : public TObject
|
class TMusrRunHeader : public TObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TMusrRunHeader(bool quite=false);
|
TMusrRunHeader(bool quiet=false);
|
||||||
TMusrRunHeader(const char *fileName, bool quite=false);
|
TMusrRunHeader(const char *fileName, bool quiet=false);
|
||||||
virtual ~TMusrRunHeader();
|
virtual ~TMusrRunHeader();
|
||||||
|
|
||||||
virtual TString GetFileName() { return fFileName; }
|
virtual TString GetFileName() { return fFileName; }
|
||||||
@ -158,7 +158,7 @@ public:
|
|||||||
virtual void DrawHeader();
|
virtual void DrawHeader();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool fQuite;
|
bool fQuiet;
|
||||||
TString fFileName;
|
TString fFileName;
|
||||||
TString fVersion;
|
TString fVersion;
|
||||||
|
|
||||||
|
@ -50,21 +50,35 @@ void closeFile(TFile *f)
|
|||||||
|
|
||||||
void read_musrRoot_runHeader_syntax()
|
void read_musrRoot_runHeader_syntax()
|
||||||
{
|
{
|
||||||
cout << endl << "usage: read_musrRoot_runHeader [<fileName>] | --version";
|
cout << endl << "usage: read_musrRoot_runHeader [<fileName> [--all-messages]] | --version";
|
||||||
cout << endl << " <fileName> is the file name including the extention root, e.g. test.root";
|
cout << endl << " <fileName> is the file name including the extention root, e.g. test.root";
|
||||||
|
cout << endl << " --all-messages: display all warnings.";
|
||||||
|
cout << endl << " --version: display the current version.";
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2) {
|
if (argc == 1) {
|
||||||
read_musrRoot_runHeader_syntax();
|
read_musrRoot_runHeader_syntax();
|
||||||
return 1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(argv[1], "--version")) {
|
if (argc == 2) {
|
||||||
cout << endl << "read_musrRoot_runHeader version: " << PMUSR_VERSION << " / $Id$" << endl << endl;
|
if (!strcmp(argv[1], "--version")) {
|
||||||
return 0;
|
cout << endl << "read_musrRoot_runHeader version: " << PMUSR_VERSION << " / $Id$" << endl << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool quiet = true;
|
||||||
|
if (argc == 3) {
|
||||||
|
if (!strcmp(argv[2], "--all-messages")) {
|
||||||
|
quiet = false;
|
||||||
|
} else {
|
||||||
|
read_musrRoot_runHeader_syntax();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the file back and extract the header info
|
// read the file back and extract the header info
|
||||||
@ -82,7 +96,7 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TMusrRunHeader *header = new TMusrRunHeader(argv[1]);
|
TMusrRunHeader *header = new TMusrRunHeader(argv[1], quiet);
|
||||||
|
|
||||||
if (!header->ExtractAll(runHeader)) {
|
if (!header->ExtractAll(runHeader)) {
|
||||||
cerr << endl << ">> **ERROR** couldn't extract all RunHeader information :-(" << endl << endl;
|
cerr << endl << ">> **ERROR** couldn't extract all RunHeader information :-(" << endl << endl;
|
||||||
|
Reference in New Issue
Block a user