AsciiNTuple Class Reference

Inheritance diagram for AsciiNTuple:

BLNTuple

List of all members.


Detailed Description

class AsciiNTuple implements a generic ASCII NTuple.

Public Member Functions

 AsciiNTuple (G4String category, G4String name, G4String fields, G4String filename)
 ~AsciiNTuple ()
virtual void appendRow (double data[], int n)
virtual bool readRow (double data[], int ndata)
virtual void annotate (G4String line)
void flush ()
void close ()
void doSummary ()

Private Attributes

FILE * fd
G4String title
int entries
bool * intFields

Constructor & Destructor Documentation

AsciiNTuple::AsciiNTuple ( G4String  category,
G4String  name,
G4String  fields,
G4String  filename 
)

References endsWith(), entries, fd, BLAsciiFile::fopen(), intFields, BLNTuple::nData, BLCommand::splitString(), and title.

00515                                                      : BLNTuple(name,_fields)
00516 {
00517         if(filename == "") filename = name+".txt";
00518         if(filename.find(".txt") == filename.npos)
00519                 filename += ".txt";
00520         fd = BLAsciiFile::fopen(filename);
00521         title = name;
00522         entries = 0;
00523         fields = _fields;
00524 
00525         fprintf(fd,"# %s\n",name.c_str());
00526         G4String s(fields);
00527         nData = 1;
00528         for(;;) {
00529                 G4String::size_type p = s.find(":");
00530                 if(p == s.npos) break;
00531                 s.replace(p,1," ");
00532                 ++nData;
00533         }
00534         fprintf(fd,"#%s\n",s.c_str());
00535 
00536         // initialize intFields[] (compare via endsWith() for ntuple command)
00537         std::vector<G4String> v=BLCommand::splitString(fields,":");
00538         assert(v.size() == (unsigned)nData);
00539         intFields = new bool[nData];
00540         for(int i=0; i<nData; ++i)
00541                 intFields[i] = (endsWith(v[i],"EventID") ||
00542                                 endsWith(v[i],"TrackID") ||
00543                                 endsWith(v[i],"ParentID") || 
00544                                 endsWith(v[i],"PDGid"));
00545 }

AsciiNTuple::~AsciiNTuple (  )  [inline]

References FOR009NTuple::close().

00479 { close(); }


Member Function Documentation

void AsciiNTuple::appendRow ( double  data[],
int  n 
) [virtual]

Implements BLNTuple.

References BLNTuple::doCallbacks(), E, entries, fd, intFields, and BLNTuple::nData.

00548 {
00549         assert(n == nData);
00550         for(int i=0; i<n; ++i) {
00551                 if(intFields[i]) {
00552                         fprintf(fd,"%d ",(int)data[i]);
00553                 } else {
00554                         // make values too small for a float be exactly zero
00555                         if(fabs(data[i]) < 1.0E-44) data[i] = 0.0;
00556                         fprintf(fd,"%.6g ",data[i]);
00557                 }
00558         }
00559         fprintf(fd,"\n");
00560         ++entries;
00561 
00562         doCallbacks(data,n);
00563 }

virtual bool AsciiNTuple::readRow ( double  data[],
int  ndata 
) [inline, virtual]

Implements BLNTuple.

00481 { return false; }

virtual void AsciiNTuple::annotate ( G4String  line  )  [inline, virtual]

Reimplemented from BLNTuple.

00483                 { fprintf(fd,"%s\n",line.c_str()); }

void AsciiNTuple::flush (  )  [inline, virtual]

Implements BLNTuple.

00484 { fflush(fd); }

void AsciiNTuple::close (  )  [inline, virtual]

Implements BLNTuple.

References BLAsciiFile::fclose().

00485 { if(fd != 0) BLAsciiFile::fclose(fd); fd = 0; }

void AsciiNTuple::doSummary (  )  [inline, virtual]

Implements BLNTuple.

References FOR009NTuple::entries, and FOR009NTuple::title.

00486                          {
00487                 printf("NTuple %-15s %8d entries\n",title.c_str(), entries);
00488         }


Member Data Documentation

FILE* AsciiNTuple::fd [private]

Referenced by appendRow(), and AsciiNTuple().

G4String AsciiNTuple::title [private]

Referenced by AsciiNTuple().

int AsciiNTuple::entries [private]

Referenced by appendRow(), and AsciiNTuple().

bool* AsciiNTuple::intFields [private]

Referenced by appendRow(), and AsciiNTuple().


The documentation for this class was generated from the following file:
g4beamline