diff --git a/src/tests/PsiRoot/TPsiRunHeader.cpp b/src/tests/PsiRoot/TPsiRunHeader.cpp index ee6800b9..ccf655e2 100644 --- a/src/tests/PsiRoot/TPsiRunHeader.cpp +++ b/src/tests/PsiRoot/TPsiRunHeader.cpp @@ -59,7 +59,7 @@ ClassImp(TPsiRunProperty) */ TPsiRunProperty::TPsiRunProperty() { - fName = "n/a"; + fLabel = "n/a"; fValue = 0.0; fError = 0.0; fUnit = "n/a"; @@ -76,23 +76,8 @@ TPsiRunProperty::TPsiRunProperty() * \param error * \param unit */ -TPsiRunProperty::TPsiRunProperty(TObjString &name, Double_t value, Double_t error, TObjString &unit) : - fName(name), fValue(value), fError(error), fUnit(unit) -{ -} - -//-------------------------------------------------------------------------- -// Constructor -//-------------------------------------------------------------------------- -/** - *
Constructor. - * - * \param name - * \param value - * \param error - * \param unit - */ -TPsiRunProperty::TPsiRunProperty(TString &name, Double_t value, Double_t error, TString &unit) : fName(name), fValue(value), fError(error), fUnit(unit) +TPsiRunProperty::TPsiRunProperty(TString &label, Double_t value, Double_t error, TString &unit) : + fLabel(label), fValue(value), fError(error), fUnit(unit) { } @@ -118,16 +103,16 @@ ClassImp(TPsiRunHeader) */ TPsiRunHeader::TPsiRunHeader() { - fVersion.SetString("00 - version: $Id$"); - fRunTitle.SetString("01 - run title: n/a"); - fRunNumber.SetString("02 - run number: -1"); - fLaboratory.SetString("03 - laboratory: n/a"); - fInstrument.SetString("04 - instrument: n/a"); - fSetup.SetString("05 - setup: n/a"); - fSample.SetString("06 - sample: n/a"); - fOrientation.SetString("07 - orientation: n/a"); - fPropertiesList.Expand(0); // init to size 0 - fProperties.Expand(0); // init to size 0 + fVersion = TString("$Id$"); + fRunTitle = TString("n/a"); + fRunNumber = -1; + fLaboratory = TString("n/a"); + fInstrument = TString("n/a"); + fSetup = TString("n/a"); + fSample = TString("n/a"); + fOrientation = TString("n/a"); + + fHeader.Expand(0); // init to size 0 } //-------------------------------------------------------------------------- @@ -138,238 +123,83 @@ TPsiRunHeader::TPsiRunHeader() */ TPsiRunHeader::~TPsiRunHeader() { - fPropertiesList.Delete(); - fProperties.Delete(); + fProperties.clear(); + fHeader.Delete(); } //-------------------------------------------------------------------------- -// GetVersion (public) -//-------------------------------------------------------------------------- -/** - *
- */ -TString TPsiRunHeader::GetVersion() const -{ - TString str("??"); - - Int_t idx = fVersion.GetString().First(":"); - if ((idx < 0) || (idx+2 > fVersion.GetString().Length())) - return str; - - str = fVersion.GetString(); - str.Replace(0, idx+2, 0, 0); - - return str; -} - -//-------------------------------------------------------------------------- -// GetRunTitle (public) -//-------------------------------------------------------------------------- -/** - *
- */ -TString TPsiRunHeader::GetRunTitle() const -{ - return GetInfoString(fRunTitle); -} - -//-------------------------------------------------------------------------- -// SetRunTitle (public) +// GetHeader (public) //-------------------------------------------------------------------------- /** *
* - * \param runTitle */ -void TPsiRunHeader::SetRunTitle(TString runTitle) +TObjArray* TPsiRunHeader::GetHeader() { - char str[1024]; - sprintf(str, "%02d - run title: %s", TPRH_RUN_TITLE_IDX, runTitle.Data()); + // make sure that previous header is removed + fHeader.Expand(0); - fRunTitle.SetString(str); -} + char str[1024], fmt[1024]; + TObjString *tostr; -//-------------------------------------------------------------------------- -// GetRunNumber (public) -//-------------------------------------------------------------------------- -/** - *
- */
-Int_t TPsiRunHeader::GetRunNumber() const
-{
- TObjArray *tokens = 0;
- TObjString *ostr = 0;
- TString str("");
- Int_t ival=-999;
+ // add version
+ sprintf(str, "%02d - Version: %s", TPRH_VERSION_IDX+1, fVersion.Data());
+ tostr = new TObjString(str);
+ fHeader.AddLast(tostr);
- tokens = fRunNumber.GetString().Tokenize(":");
- if (!tokens) { // couldn't get tokens
- return ival;
- }
- if (tokens->GetEntries() != 2) { // wrong number of tokens
- delete tokens;
- return ival;
+ // add run title
+ sprintf(str, "%02d - Run Title: %s", TPRH_RUN_TITLE_IDX+1, fRunTitle.Data());
+ tostr = new TObjString(str);
+ fHeader.AddLast(tostr);
+
+ // add run number
+ sprintf(str, "%02d - Run Number: %d", TPRH_RUN_NUMBER_IDX+1, fRunNumber);
+ tostr = new TObjString(str);
+ fHeader.AddLast(tostr);
+
+ // add laboratory
+ sprintf(str, "%02d - Laboratory: %s", TPRH_LABORATORY_IDX+1, fLaboratory.Data());
+ tostr = new TObjString(str);
+ fHeader.AddLast(tostr);
+
+ // add instrument
+ sprintf(str, "%02d - Instrument: %s", TPRH_INSTRUMENT_IDX+1, fInstrument.Data());
+ tostr = new TObjString(str);
+ fHeader.AddLast(tostr);
+
+ // add setup
+ sprintf(str, "%02d - Setup: %s", TPRH_SETUP_IDX+1, fSetup.Data());
+ tostr = new TObjString(str);
+ fHeader.AddLast(tostr);
+
+ // add sample
+ sprintf(str, "%02d - Sample: %s", TPRH_SAMPLE_IDX+1, fSample.Data());
+ tostr = new TObjString(str);
+ fHeader.AddLast(tostr);
+
+ // add orientation
+ sprintf(str, "%02d - Orientation: %s", TPRH_ORIENTATION_IDX+1, fOrientation.Data());
+ tostr = new TObjString(str);
+ fHeader.AddLast(tostr);
+
+ // add properties
+ UInt_t digit=0;
+ for (UInt_t i=0; i
- *
- * \param runNumber
- */
-void TPsiRunHeader::SetRunNumber(Int_t runNumber)
-{
- char str[1024];
- sprintf(str, "%02d - run number: %06d", TPRH_RUN_NUMBER_IDX, runNumber);
-
- fRunNumber.SetString(str);
-}
-
-//--------------------------------------------------------------------------
-// GetLab (public)
-//--------------------------------------------------------------------------
-/**
- *
- */
-TString TPsiRunHeader::GetLab() const
-{
- return GetInfoString(fLaboratory);
-}
-
-//--------------------------------------------------------------------------
-// SetLab (public)
-//--------------------------------------------------------------------------
-/**
- *
- *
- * \param lab
- */
-void TPsiRunHeader::SetLab(TString lab)
-{
- char str[1024];
- sprintf(str, "%02d - laboratory: %s", TPRH_LABORATORY_IDX, lab.Data());
-
- fLaboratory.SetString(str);
-}
-
-//--------------------------------------------------------------------------
-// GetInstrument (public)
-//--------------------------------------------------------------------------
-/**
- *
- */
-TString TPsiRunHeader::GetInstrument() const
-{
- return GetInfoString(fInstrument);
-}
-
-//--------------------------------------------------------------------------
-// SetInstrument (public)
-//--------------------------------------------------------------------------
-/**
- *
- *
- * \param instrument
- */
-void TPsiRunHeader::SetInstrument(TString instrument)
-{
- char str[1024];
- sprintf(str, "%02d - instrument: %s", TPRH_INSTRUMENT_IDX, instrument.Data());
-
- fInstrument.SetString(str);
-}
-
-//--------------------------------------------------------------------------
-// GetSetup (public)
-//--------------------------------------------------------------------------
-/**
- *
- */
-TString TPsiRunHeader::GetSetup() const
-{
- return GetInfoString(fSetup);
-}
-
-//--------------------------------------------------------------------------
-// SetSetup (public)
-//--------------------------------------------------------------------------
-/**
- *
- *
- * \param setup
- */
-void TPsiRunHeader::SetSetup(TString setup)
-{
- char str[1024];
- sprintf(str, "%02d - setup: %s", TPRH_SETUP_IDX, setup.Data());
-
- fSetup.SetString(str);
-}
-
-//--------------------------------------------------------------------------
-// GetSample (public)
-//--------------------------------------------------------------------------
-/**
- *
- */
-TString TPsiRunHeader::GetSample() const
-{
- return GetInfoString(fSample);
-}
-
-//--------------------------------------------------------------------------
-// SetSample (public)
-//--------------------------------------------------------------------------
-/**
- *
- *
- * \param sample
- */
-void TPsiRunHeader::SetSample(TString sample)
-{
- char str[1024];
- sprintf(str, "%02d - sample: %s", TPRH_SAMPLE_IDX, sample.Data());
-
- fSample.SetString(str);
-}
-
-//--------------------------------------------------------------------------
-// GetOrientation (public)
-//--------------------------------------------------------------------------
-/**
- *
- */
-TString TPsiRunHeader::GetOrientation() const
-{
- return GetInfoString(fOrientation);
-}
-
-//--------------------------------------------------------------------------
-// SetOrientation (public)
-//--------------------------------------------------------------------------
-/**
- *
- *
- * \param orientation
- */
-void TPsiRunHeader::SetOrientation(TString orientation)
-{
- char str[1024];
- sprintf(str, "%02d - orientation: %s", TPRH_ORIENTATION_IDX, orientation.Data());
-
- fOrientation.SetString(str);
+ return &fHeader;
}
//--------------------------------------------------------------------------
@@ -382,15 +212,7 @@ void TPsiRunHeader::SetOrientation(TString orientation)
*/
void TPsiRunHeader::AddProperty(TPsiRunProperty &property)
{
- TPsiRunProperty *prop = (TPsiRunProperty*) property.Clone();
- fProperties.AddLast(prop);
-
- char str[1024];
- TObjString *tostr;
- sprintf(str, "%02d - %s: %lf +- %lf (%s)", TPRH_OFFSET+fPropertiesList.GetLast(),
- prop->GetName().GetString().Data(), prop->GetValue(), prop->GetError(), prop->GetUnit().GetString().Data());
- tostr = new TObjString(str);
- fPropertiesList.AddLast(tostr);
+ fProperties.push_back(property);
}
//--------------------------------------------------------------------------
@@ -406,17 +228,8 @@ void TPsiRunHeader::AddProperty(TPsiRunProperty &property)
*/
void TPsiRunHeader::AddProperty(TString name, Double_t value, Double_t error, TString unit)
{
- TPsiRunProperty prop(name, value, error, unit);
- TPsiRunProperty *p_prop = (TPsiRunProperty*) prop.Clone();
-
- fProperties.AddLast(p_prop);
-
- char str[1024];
- TObjString *tostr;
- sprintf(str, "%02d - %s: %lf +- %lf (%s)", TPRH_OFFSET+fPropertiesList.GetLast(),
- name.Data(), value, error, unit.Data());
- tostr = new TObjString(str);
- fPropertiesList.AddLast(tostr);
+ TPsiRunProperty property(name, value, error, unit);
+ fProperties.push_back(property);
}
//--------------------------------------------------------------------------
@@ -428,46 +241,43 @@ void TPsiRunHeader::AddProperty(TString name, Double_t value, Double_t error, TS
void TPsiRunHeader::DumpHeader() const
{
int old_width = cout.width();
- TPsiRunProperty *prop;
// get maximal length of the property names
int name_width = 8; // init to max. length of fixed names like: version, etc.
- for (Int_t i=0; i<=fProperties.GetLast(); i++) {
- prop = (TPsiRunProperty*)(fProperties[i]);
- if (prop->GetName().GetString().Length() > name_width)
- name_width = prop->GetName().GetString().Length();
+ for (UInt_t i=0; i Check decimal place of val. If val > 1.0, the function will return 0, otherwise
+ * the first decimal place found will be returned.
*
- * \param tostr a TObjString with a content structure "%s: %s".
+ * \param val value from which the first significant digit shall be determined
*/
-TString TPsiRunHeader::GetInfoString(const TObjString &tostr) const
+UInt_t TPsiRunHeader::GetDecimalPlace(Double_t val)
{
- TObjArray *tokens = 0;
- TObjString *ostr = 0;
- TString str("??");
+ UInt_t digit = 0;
- tokens = tostr.GetString().Tokenize(":");
- if (!tokens) { // couldn't get tokens
- return str;
- }
- if (tokens->GetEntries() != 2) { // wrong number of tokens
- delete tokens;
- return str;
+ if (val < 1.0) {
+ UInt_t count=1;
+ do {
+ val *= 10.0;
+ if (val > 1.0)
+ digit = count;
+ count++;
+ } while ((digit == 0) || (count > 20));
}
- ostr = dynamic_cast