#include #define ERROR (-1) #define MAX_LINE 1024 #define EIGHT 8 #define NAME "test_nt" /* dummy */ struct { float hmemor[1000000]; } pawc_; struct { int iquest[10]; }quest_; #define h_error (quest_.iquest[0]) /* Table of constant values */ static int c_b1 = 1000000; static int c__23 = 23; static int c__1024 = 1024; static int c__1 = 1; static int c__0 = 0; static int c__99 = 99; int NumberOfEntries=0; static int pawc_initialized=0; extern /* Subroutine */ int hrend_(), hrout_(), hbookn_(), hlimit_(), hropen_(), hfn_(), hgiven_(); int openNtupleFile(char *filename,int n_entries, char *tags) { int i; int tuple_size; if( pawc_initialized == 0) { hlimit_(&c_b1); /* initializing PAW memory */ pawc_initialized=1; } /* opening CERNLIB file for writing */ hropen_(&c__23, "nt", filename, "n", &c__1024, &i, 2L, strlen(filename), 1L); /**********************************************************************/ /* creating CERNLIB ntuple with * name :"nt", * size of tuple ( line, call as you want) : tuple_size , * block size (I don't know what it means, but 1024 works):c__1024, * names of columns (vectors) given by string :tags */ /**********************************************************************/ tuple_size = n_entries; /* I cannot point to argument */ hbookn_(&c__1, "nt", &tuple_size, "rztop", &c__1024, tags, 2L, 5L, 8L); return 0; } #define NAME "test_nt" /* dummy */ int openInputNtupleFile(char *filename,int id) { /* id is Ntuple's id in the file */ int i,_id, _n_entries; _id=id; /* _n_entries=n_entries; */ /* we pass pointers to FORTRAN */ if( pawc_initialized == 0) { hlimit_(&c_b1); /* initializing PAW memory */ pawc_initialized=1; } /* opening CERNLIB file for reading */ /* we don't know a priori the block size */ do { hropen_(&c__23, "nt", filename, " ", &c__0, &i, 2L, strlen(filename), 1L); if( h_error ) break; hrin_(&_id, &c__99/*n_cycles*/,&c__0); if( h_error ) break; hgnpar_(&_id,NAME, strlen(NAME)); if( h_error ) break; hnoent_(&_id,&NumberOfEntries); if( h_error ) break; }while (0); /* do once */ if(h_error)NumberOfEntries=ERROR; return NumberOfEntries; } int getHeader(int id, char *name, int *nvar_pnt, char *tags, float *low, float *high) { hgiven_( &id, name, nvar_pnt, tags, low, high, EIGHT, EIGHT); } int fc_open_input_ntuple_file_(char *filename, int *id_ptr, int len) { openInputNtupleFile(filename, *id_ptr); return NumberOfEntries; } void fillTuple(float *tuple) { hfn_(&c__1, tuple); } void closeNtupleFile() { int i; hrout_(&c__0, &i, " ", 1L); hrend_("nt", 2L); close(c__23); } void closeInputNtupleFile() { hrend_("nt", 2L); close (c__23); } #define LINE_LEN 256 #define ERROR (-1) #define OK 0 #define ONE 1 #define TRUE 1 #define FALSE 0 #define RC_FILE "nt_list.rc" #define RC_OUT_FILE "nt_out.rc" static FILE *fp_in, *fp_out; int fetchNextFile(char *file_name ) { _fetchNextFile(file_name, RC_FILE, &fp_in); } int fetchNextOutFile(char *file_name ) { _fetchNextFile(file_name, RC_OUT_FILE,&fp_out); } int _fetchNextFile(char *file_name, char *rc_file_name, FILE **fpp ) { char *pq, buf[LINE_LEN]; int iq, return_value; static FILE *fp; return_value = ERROR; if( *fpp==NULL ) { *fpp=fopen(rc_file_name, "r"); } do /* once */ { fp=*fpp; if(fp == NULL) break; pq = fgets(buf,LINE_LEN,fp); if ( pq == NULL ) break; iq = sscanf(buf, "%s ",file_name); if( iq != ONE ) break; iq=(int)strlen(file_name); file_name[ iq ] = (char)0; return_value = OK; } while( FALSE ); return return_value; } int fc_fetch_next_file_(char *file_name, int *iq, int len) { *iq=fetchNextFile(file_name); } int getDataFromNtuple(int tuple_id,int number,float data[]) { int error_flag; /* not always it works, so it's better to ignore it */ number +=1; hgnf_(&tuple_id,&number,data,&error_flag); return h_error; }