Re: your mail

From: Canguo Li (licg@hpws7.ihep.ac.cn)
Date: Fri Dec 04 1998 - 09:12:31 MET


Dear Alexander:

 Thank you very much for offering answer and help to my question on how to 
read key'ed free formatted ascii data. I've tried to understand your code
(perhaps a schematic one). I believe it does the job. However, it seems 
FFKEY is called for each integer or float number or an 1-d array. Then does 
this mean a card can contain only a single integer or a float number
or an 1-d array?

> ffkey_(key,ptr,Nvar,type,strlen(key),strlen(type));

  Is this the way to call fortran subroutine ffkey_ (in FFREAD package) --
adding 2 more arguments strlen(key), strlen(type) in the call? I understand
fortran would require this info, but is the order implementation-independent?

 Then I still need to "order" some features for the evolving ROOT, that
utilities for reading key'ed free format data cards be available.
I'm still in the process studying Rene Brun's reply(thanks to Rene), and 
learning ROOT basics. I hope the answer is already in the ROOT.

--Canguo
 
On Mon, 30 Nov 1998, Alexander Zvyagin wrote:

> Below is the example of ROOT class with function that produce FFREAD keys.
> Notes:
> 1. All FFREAD keys must be data members of a ROOT class.
> 2. Data memebers of class Parameter may be
>    Float_t (for REAL) or (U)Int_t (for INTEGER).
> 3. One-dimension arrays are supported.
> 4. The first symbol of data memeber name will removed. (Removing leading
>    'f','g' or 'k' symbols.)
> 
> ------------------------------------------------------------------------------
> //////////////////////////////////////////////////////////////////////////////
> 
> // Example of GEANT UGINIT subroutine.
> 
> const int FFREAD_SIZE=2000;
> float cfread_[FFREAD_SIZE];
> 
> void UGINIT(void)
> {
>   GINIT();
> 
>   FFINIT(FFREAD_SIZE);
>   FFSET("SIZE",32);
>   Parameters P;
>   P.CreateFFREADcards();
>   GFFGO();
>   P.Dump();
> 
>   //....
> }
> 
> //////////////////////////////////////////////////////////////////////////////
> 
> class Parameters : public TObject
> {
>   public:
> 
>     void                CreateFFREADcards      (void);
>     virtual            ~Parameters             (void) {}
>                         Parameters             (void) :// For default values.
>                                                   fPar (0.01)
>                                                 { fDim[0]=0; fDim[1]=1;}
> 
>     Float_t             fPar;                   // Par      Set your name!
>     Int_t               fDim[2];                // Dim      Set your name!
> 
>   private:
> 
>   ClassDef(Parameters,1)                       // Parameters
> };
> 
> //////////////////////////////////////////////////////////////////////////////
> 
> void ffkey_( const char *key, void *ptr, const int &Nvar, const char *type,
>              int,int);
> inline void FFKEY(const char *key, void *ptr, int Nvar, const char *type)
> { ffkey_(key,ptr,Nvar,type,strlen(key),strlen(type)); }
> 
> void
> Parameters::CreateFFREADcards(void)
> {
>   cout << __PRETTY_FUNCTION__ << "\n";
> 
>   TIter next(Class()->GetListOfDataMembers());                           
> 
>   while( TDataMember *obj = (TDataMember*)next() )
>   {
>     if( !strcmp("fgIsA",obj->GetName()) )               // Skip this variable
>       continue;
> 
> //  cout << obj -> GetName()                            << "\n"
> //       << obj -> GetDataType() -> GetTypeName()       << "\n"
> //       << obj -> GetDataType() -> GetFullTypeName()   << "\n"
> //       << obj -> GetOffset()                          << "\n"
> //       << obj -> GetArrayDim()                        << "\n"
> //       << obj -> GetMaxIndex(0)                       << "\n"
> //       << "-----------------------------------------------\n";
>     
>     cout << obj->GetName();                             // Print variable name
>     for( int i=strlen(obj->GetName()); i<22; i++ )      // Add spaces for good
>       cout << ' ';                                      // print.
> 
>     cout << obj->GetDataType()->GetFullTypeName();      // Print variable type
>     for( int i=strlen(obj->GetDataType()->GetFullTypeName()); i<18; i++ ) 
>       cout << ' ';                                // Add spaces for good print
> 
>     if( strlen(obj->GetName())<2 || obj->GetName()[0]!='f' )
>     {
>       cout << "Bad name. Skipped.\n";
>       continue;
>     }
> 
>     char type[11]="";
> 
>     if( !strcmp("int"   , obj -> GetDataType() -> GetTypeName()) )
>       strcpy(type,"INTEGER");
> 
>     if( !strcmp("float" , obj -> GetDataType() -> GetTypeName()) )
>       strcpy(type,"REAL");
> 
>     if( *type == 0 )
>     {
>       cout << "Unknown type.\n";
>       continue;
>     }
> 
>     int size;
>     switch( obj->GetArrayDim() )
>     {
>       case 0:   size = 1;                       break;
>       case 1:   size = obj->GetMaxIndex(0);     break;
>       default:
>              cout << "Only one dimensional arrays are supported. Skipped.\n";
>              continue;
>     }
> 
>     cout.form("amount=%d\n",size);
> 
>     FFKEY( obj->GetName()+1 , (void*)((int)this + (int)obj->GetOffset()) ,
>            size , type );
>   }
> }
> 
> //////////////////////////////////////////////////////////////////////////////
> 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:40 MET