//*-- Author :    Damir Buskulic   11/01/00

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// VConditionNames                                                      //
//                                                                      //
// List of strings containing the names of the conditions defined       //
// in the database.                                                     //
// Trying to add a name that is already there doesn't do anything       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "VConditionNames.h"
#include "TNamed.h"

ClassImp(VConditionNames)

//______________________________________________________________________________
VConditionNames::VConditionNames() : TObject()
{
//   Condition names default constructor
   mConditionNames = new THashList();
   mNCNames = 0;
}

//______________________________________________________________________________
VConditionNames::~VConditionNames()
{
//   Condition names destructor
   mConditionNames->Delete();
   delete mConditionNames;
}

//______________________________________________________________________________
 void VConditionNames::AddConditionName(const Text_t* name, const Text_t* varnames)
{
// Adds the name of a condition as well as variables names
   
   if (mConditionNames->FindObject(name)) return;
   TNamed* newname = new TNamed(name,varnames);
   mConditionNames->Add(newname);
   mNCNames++;
}

//______________________________________________________________________________
 const Text_t* VConditionNames::GetConditionName(Int_t num)
{
// Retrieves a name at index num
   
   TNamed* name = (TNamed*)(mConditionNames->At(num));
   if (name) {
      return name->GetName();
   }
   return 0;
}

//______________________________________________________________________________
 const Text_t* VConditionNames::GetConditionVars(Int_t num)
{
// Retrieves a name at index num
   
   TNamed* name = (TNamed*)(mConditionNames->At(num));
   if (name) {
      return name->GetTitle();
   }
   return 0;
}

//______________________________________________________________________________
 Bool_t VConditionNames::CheckConditionName(const Text_t* name, const Text_t* varname)
{
// Checks if a name is present in the list
   
   const Text_t* posvar, *endvar, *begvar, *oldbegvar;
   const Text_t* fvar;
   
   TNamed* fname = (TNamed*)(mConditionNames->FindObject(name));
   if (fname) {
      fvar = fname->GetTitle();
      if (strlen(varname)==0) return 1;
      posvar = strstr(fvar,varname);
      if (posvar) {
         begvar = fvar;
//     searches for the blank preceeding the name to be sure
//     that the name is the right one and not only part of it
         oldbegvar=begvar;
         while (begvar<=posvar && begvar) {
            oldbegvar = begvar;
            begvar = strstr(begvar+1," ");
         }
         begvar = oldbegvar;
         if (*begvar==' ') begvar++;
         if (begvar == posvar) {
            endvar = strstr(posvar," ");
            if (!endvar) endvar = fvar + strlen(fvar);
            if ((int)strlen(varname) == endvar-posvar) return 1;
         }
      }
   }
   return 0;
}

//______________________________________________________________________________
 Int_t VConditionNames::IndexOf(const Text_t* name)
{
// Returns the index of a name in the list
   
   TObject* obj = mConditionNames->FindObject(name);
   if (obj) return mConditionNames->IndexOf(obj);
   return -1;
}

//______________________________________________________________________________
 Int_t VConditionNames::IndexOfVar(const Text_t* condname, const Text_t* varname)
{
// Returns the index of a variable "varname" in the list of variables
// corresponding to condition "condname" in the list
   
   const Text_t* posvar, *endvar, *searchindex;
   const Text_t* fvar;
         int     varindex;
         int     nameok;
   
   if (strlen(varname)==0) return -1;

   TNamed* fname = (TNamed*)(mConditionNames->FindObject(condname));
   if (fname) {
      fvar = fname->GetTitle();
      nameok = 0;
      posvar = strstr(fvar,varname);
      if (posvar) {
         endvar = strstr(posvar," ");
         if (!endvar) endvar = fvar + strlen(fvar);
         if ((int)strlen(varname) == endvar-posvar) nameok = 1;
      }
      varindex = 0;
      searchindex = fvar;
      if (nameok) {
         while (searchindex!=posvar) {
            searchindex = strstr(searchindex," ");
            searchindex++;
            varindex++;
         }
         return varindex;
      }
   }
   return -1;
}

//______________________________________________________________________________
 void VConditionNames::Print()
{
// Prints the list of conditions
   
   printf("Number of conditions : %dn",mNCNames);
   for (int i=0;i<mNCNames;i++) {
      printf("condition : %20s  variables : %s n",GetConditionName(i),GetConditionVars(i));
   }
}


- ROOT page - VEGA page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to , or contact with any questions or problems regarding ROOT or VEGA.