// Author: Egon Pavlica <http://www.p-ng.si/~pavlica/>

//________________________________________
//  This is data tracks container class
//  to transfer montecarlo simulation data
//  over network
//
// before sending around call Prepare()!
//
// Note: indexes are 1-based!
//
//
// Logs:
//
//  $Log: LContainer.cc,v $
//  Revision 1.9  2004/04/13 14:13:33  cvs
//  hopping is client, that can comunicate only throuth stdin/out
//
//  Revision 1.8  2004/04/09 13:21:05  cvs
//  added cputime logging...
//
//  Revision 1.7  2003/11/15 17:17:26  cvs
//  new scheme is working...
//  Clients (hoppclient) are connected as kLC_AMAX and free socket is given
//  TLServer (lserver) is multithreading
//  LServer (hoppserver) has a file which is always in memory - faster but needs more memory
//
//  Revision 1.6  2003/09/25 10:57:40  cvs
//  added force member to LDataHeader class
//
//  Revision 1.5  2003/07/25 11:36:26  cvs
//  simulation of IV measurements is done with iv program
//  some minority fixes to LDisorder - corrected ft to match the recorded position
//
//  Revision 1.4  2003/07/09 10:53:13  cvs
//  added some verbosity and changed LContainer class. The LData isnt changed. Corrected daemon mode of hoppserv, since network connection is dependend on process pid. So the connection should be opened by child processes.
//
//  Revision 1.3  2003/07/01 12:17:18  cvs
//  New LData organization. data is stored in TH2F histograms. This enables easier manipulation. Found a bug in drawing averaged velocity vs time. The average number was calcuated over whole times.
//
//  Revision 1.2  2003/06/26 09:27:11  cvs
//  added log fields...
//

#include "LContainer.h"
#include <iostream>

ClassImp(LContainer)

 LContainer::LContainer(){
  //default constructor
  fjobID=0;      //identification of job
  fmax=0;         //max number of bins
  fN=0;           //number of tracks
  fp=0;       //pointers to position tracks
  fe=0;       // pointer to energy tracks
  fttime=0;    //[fN] pointer to ttime 
  fcpu_time=0;    //[fN] pointer to cputime 
  ftrackn=0;    //[fN] pointer to trackn
  flog=0;
  cur=0;//very important
}

 LContainer::LContainer(const Long_t jobID,const Int_t bins,const Int_t ntracks){
  //another constructor
  fjobID=jobID;      //identification of job
  fmax=bins;         //max number of bins
  fN=ntracks;           //number of tracks
  fp=0;       //pointers to position tracks
  fe=0;       // pointer to energy tracks
  fttime=0;    //[fN] pointer to ttime 
  fcpu_time=0;    //[fN] pointer to cputime 
  ftrackn=0;    //[fN] pointer to trackn
  flog=0;
  cur=0; //very important
}

 LContainer::LContainer(const LDataHeader* header){
  //same as other constructor
  fjobID=header->GetJobID();      //identification of job
  fmax=header->fmax;         //max number of bins
  fN=header->fN1;           //number of tracks
  fp=0;       //pointers to position tracks
  fe=0;       // pointer to energy tracks
  fttime=0;    //[fN] pointer to ttime 
  fcpu_time=0;    //[fN] pointer to cputime 
  ftrackn=0;    //[fN] pointer to trackn
  flog=0;
  cur=0;//very important
}

 LContainer::~LContainer(){
  //default destructor
  if (ftrackn) { Tdelete(ftrackn,1); ftrackn=0;}  
  if (fttime) { Tdelete(fttime,1); fttime=0;}  
  if (fcpu_time) { Tdelete(fcpu_time,1); fcpu_time=0;}  
  if (fe) { Tdelete(fe,1); fe=0; }  
  if (fp) { Tdelete(fp,1); fp=0; }  
  if (flog) { delete flog; flog=0; }  
  cur=0;
}

Int_t 
 LContainer::Add(const Int_t n,const Float_t* track,const Float_t* tracke,const Float_t ttime,Double_t cputime){
  //use this to adding data from LDisorder
  //return 1 if successful and 0 if not 
  //this add track, tracke and ttime to fp, fe and fttime arrays and 
  //moves cur++

  if (!cur) {
    Tnew(fp,1,fN,1,fmax);
    Tnew(fe,1,fN,1,fmax);
    Tnew(fttime,1,fN);
    Tnew(fcpu_time,1,fN);
    Tnew(ftrackn,1,fN);
    cur=1;//where to store
  }
  
  if (cur>fN) {
    if (fverbose) std::cerr<<"Error:LContainer:Adding to full container!! - ignoringn";
    return 0;
  }
  
  for(Int_t i=1;i<=fmax;i++){
    fp[cur][i]=track[i];
    fe[cur][i]=tracke[i];
  }
  fttime[cur]=ttime;
  fcpu_time[cur]=cputime;
  ftrackn[cur]=n;
  
  cur++;
  return 1;
}

LContainer*
 LContainer::Prepare(){
  //control if all places are full
  //then returns itself
  //if some place is empty, then creates new class and returns that
  //but that is time consuming!!
  if (!cur){
    if (fverbose) std::cerr<<"Error:LContainer:Preparin empty container!! - ignoringn";
    return 0;
  }
  if (cur>fN+1){
    if (fverbose) std::cout<<"Warning:LContainer:Preparin half filled container!! -ignoringn";
    //    LContainer* temp=new LContainer(fjobID,fmax,cur-1);
    //  for(Int_t i=1;i<cur;i++)
    //  temp->Add(fp[i],fe[i],fttime[i]);
    // return temp;
    return 0;
  }
  return this;
}

void
 LContainer::Print(Option_t* option)const{
  //this is for debuging 
  //it prints the contents of container
  std::cout<<fjobID<<std::endl;
  std::cout<<fmax<<std::endl;
  std::cout<<fN<<std::endl;
  for (Int_t i=1; i<=fN;i++){
    std::cout<<fttime[i]<<std::endl;
    std::cout<<fcpu_time[i]<<std::endl;
    std::cout<<ftrackn[i]<<std::endl;
    for (Int_t j=1;j<=fmax;j++)
      std::cout<<fp[i][j]<<"t";
    std::cout<<std::endl;
    for (Int_t j=1;j<=fmax;j++)
      std::cout<<fe[i][j]<<"t";
    std::cout<<std::endl;
  }
}

void
 LContainer::SetLog(const char* bla){
  //copy bla to log field
  if (flog) delete flog;
  flog=new TString(bla);
}

const char*
 LContainer::GetLog(){
  //return log field
  if (!flog) return 0;
  return flog->Data();
}
      

void 
 LContainer::Streamer(TBuffer &R__b){
  //special streamer for LContainer
  if(R__b.IsReading()){
    Version_t R__v;
    R__v=R__b.ReadVersion();
    TObject::Streamer(R__b);
    R__b>>fjobID;
    R__b>>fmax;
    R__b>>fN;

    if (!flog) flog=new TString();
    R__b>>*flog;
    //    std::cout<<"debug1"<<std::endl;

    //    Tdelete(fp,1);
    if (!fp) Tnew(fp,1,fN,1,fmax);
    for(Int_t i=1;i<=fN;i++)
      R__b.ReadFastArray(fp[i]+1,fmax);
    //Tdelete(fe,1);
    if(!fe) Tnew(fe,1,fN,1,fmax);
    for(Int_t i=1;i<=fN;i++)
      R__b.ReadFastArray(fe[i]+1,fmax);
    //    Tdelete(fttime,1);
    if(!fttime) Tnew(fttime,1,fN);
    R__b.ReadFastArray(fttime+1,fN);
    if (R__v > 2) {
      if(!fcpu_time) Tnew(fcpu_time,1,fN);
      R__b.ReadFastArray(fcpu_time+1,fN);
    }

    if(!ftrackn) Tnew(ftrackn,1,fN);
    R__b.ReadFastArray(ftrackn+1,fN);
  } else {
    //    Prepare();
    Version_t R__v=LContainer::IsA()->GetClassVersion();
    R__b.WriteVersion(LContainer::IsA());
    TObject::Streamer(R__b);
    R__b<<fjobID;
    R__b<<fmax;
    R__b<<fN;

    if (!flog) flog=new TString("no log");
    R__b<<*flog;
    //    std::cout<<flog->Data()<<std::endl;

    for(Int_t i=1;i<=fN;i++)
      R__b.WriteFastArray(fp[i]+1,fmax);

    for(Int_t i=1;i<=fN;i++)
      R__b.WriteFastArray(fe[i]+1,fmax);

    R__b.WriteFastArray(fttime+1,fN);
    if (R__v > 2) {
      R__b.WriteFastArray(fcpu_time+1,fN);
    }
    R__b.WriteFastArray(ftrackn+1,fN);

  }
}
    









ROOT 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 ROOT support, or contact the developers with any questions or problems regarding ROOT.