					RunInfo


 class RunInfo : public TObject


	Inheritance Chart:

		TObject <- RunInfo


 Methods:

	private:

	public:


 Data Members:

	private:

	public:
		    ULong64_t ID;
		    ULong64_t ID_REG_RUN;
		    ULong64_t ID_REG_RUN_L2;
		    ULong64_t RUNHEADER_TIME;
		    ULong64_t RUNTRAILER_TIME;
		    Int_t EV_REG_PHYS_FROM; 
		    Int_t EV_REG_PHYS_TO;  
		    Int_t EV_REG_RUNHEADER;  
		    Int_t EV_REG_RUNTRAILER;  
		    Int_t TRK_CALIB_USED;
		    Int_t EFFECTIVE_WORKING_SCHEDULE;
		    Int_t PRH_VAR_TRIGGER_MODE_A;
		    Int_t PRH_VAR_TRIGGER_MODE_B;
		    Int_t ACQ_BUILD_INFO;
		    Int_t ACQ_VAR_INFO;
		    TString TRIG_ver;
		    TString TOF_ver;
		    TString AC_ver;
		    TString TRK_ver;
		    TString CAL_ver;
		    TString S4_ver;
		    TString ND_ver;


 Class Description:

	Class needed to copy into the Level2 rootple the information stored in the DB table GL_RUN. 





					ItoRunInfo


 class ItoRunInfo : public TObject


	Inheritance Chart:

		TObject <- ItoRunInfo


 Methods:

	private:

	public:
		    ItoRunInfo();
		    ItoRunInfo(TSQLServer *dbc, TFile *processFile, TString processFolder, ULong64_t idRun, TString Detector, TString Dec_version);
		    ItoRunInfo(TFile *processFile);
		    Int_t Update();
		    Int_t Read();
	            Int_t GetRunInfo(ULong64_t run);
     		    UInt_t GetRunForEntry(UInt_t entry);
    		    Long64_t GetRunEntries(){return(totnorun);};
		    Bool_t IsReprocessing();
		    UInt_t GetFirstFileEntry();
		    UInt_t GetLastFileEntry();
		    ULong64_t GetFileEntries();
		    UInt_t GetNoRun();
		    TArrayL *GetRunList();
		    void Close();


 Data Members:

	private:
		    ULong64_t file_entries;
		    Long64_t totnorun;
		    Int_t first_file_entry;
		    Int_t last_file_entry;
		    UInt_t norun;
		    Bool_t reprocessing;
		    Bool_t updating;
		    TFile *file;
		    TTree *newtree;
		    TArrayL *runlist;
		    ULong64_t idRun;
		    TSQLServer *dbc;
		    TString processFolder;
		    TString Detector;
		    TString Dec_version;

	public:
		    ULong64_t ID;
		    ULong64_t ID_REG_RUN;
		    ULong64_t ID_REG_RUN_L2;
		    ULong64_t RUNHEADER_TIME;
		    ULong64_t RUNTRAILER_TIME;
		    Int_t EV_REG_PHYS_FROM; 
		    Int_t EV_REG_PHYS_TO;  
		    Int_t EV_REG_RUNHEADER;  
		    Int_t EV_REG_RUNTRAILER;  
		    Int_t TRK_CALIB_USED;
		    Int_t EFFECTIVE_WORKING_SCHEDULE;
		    Int_t PRH_VAR_TRIGGER_MODE_A;
		    Int_t PRH_VAR_TRIGGER_MODE_B;
		    Int_t ACQ_BUILD_INFO;
		    Int_t ACQ_VAR_INFO;
		    TString TRIG_ver;
		    TString TOF_ver;
		    TString AC_ver;
		    TString TRK_ver;
		    TString CAL_ver;
		    TString S4_ver;
		    TString ND_ver;


 Class Description:
	
	Interface to the RunInfo class: provides methods which can be used to reprocess RUNs inside a Level2 file.
	

 ItoRunInfo():

 	   Default constructor for RunInfo.


 ItoRunInfo(TSQLServer *dbc, TFile *processFile, ULong64_t idRun, TString Detector, TString Dec_version, Int_t &signal):

	   Constructor to be used with a file opened in "UPDATE" mode, needed to update informations in the file.
	Given a opened sql connection, an opened TFile and the idRun it updates the versioning information for 
	the given detector or creates inside the TFile the TTree run copying data from the GL_RUN table where ID=idRun. 
	Signal is returned in "signal" variable: if less than 0 an error occurred.
	Detector can be:
			"TOF", "TRIG", "AC", "TRK", "CALO", "S4", "ND"
 
	Example:

	...
	#include <RunInfo.h>

	...

	TSQLServer *dbc = 0;
	dbc = TSQLServer::Connect("mysql://localhost/pamelaprod","anonymous","");
	TFile *file = new TFile(processFile.Data(),"UPDATE");
 	const char *caloversion = CaloInfo(false);
	Int_t sgnl = 0;
  	ItoRunInfo *runinfo = new ItoRunInfo(dbc,file,"calorimeterFolder",idRun,"CALO",caloversion);
	sgnl = runinfo->Update()
        if ( sgnl < 0 ) return(sgnl);


 ItoRunInfo(TFile *processFile):

	   Constructor to be used with a file opened in "READ-ONLY" mode, needed only to perform analysis.



 Bool_t IsReprocessing():

	   Returns "true" if the TFile already contained a Run TTree and the "Detector" versioning information was already
	filled; return "false" otherwise.


 UInt_t GetFirstFileEntry();

	   Returns the entry of the TFile which contains the first event of the processed run.


 UInt_t GetFirstFileEntry();

	   Returns the entry of the TFile which contains the last event of the processed run.


 ULong64_t GetFileEntries();

	   Returns the number of entries of the TFile.


 UInt_t GetNoRun():

	   Returns the number of runs to be processed.


 TArrayL *GetRunList():

	   Returns an array of lenght equal to the number of run to be processed in which each elements is the idRun to be 
	processed.
	Example (follows the one above):

	UInt_t numbofrun = runinfo->GetNoRun();
	TArrayL *runlist = runinfo->GetRunList();
	//
	// Loop over the run to be processed
	//
	for (UInt_t irun=0; irun < numbofrun; irun++){
	  //
 	  // get idRun to process
 	  //
	  idRun = runlist->At(irun);
	  //
	  // store run information from GL_RUN in memory
	  // 
          sgnl = runinfo->GetRunInfo(idRun); 
          if ( sgnl < 0 ) return(sgnl);
	  //
	  // process data
	  //
	  printf(" ID_REG_RUN for run %i is %i \n",(int)idRun,(int)runinfo->ID_REG_RUN);
	  printf(" RUNHEADER_TIME for run %i is %i \n",(int)idRun,(int)runinfo->RUNHEADER_TIME);


 Int_t GetRunInfo(ULong64_t idRun):

	   Fill data members with variables of the run "idRun" reading from the file and not from the DB.
	Returns a signal less than zero in case of any error, zero otherwise.
	As example look at the one above.


 UInt_t GetRunForEntry(UInt_t entry);

	   Given the entry number it returns the ID of the run which contains that event.


 Long64_t GetRunEntries(){return(totnorun);};

	   Returns the number of runs contained in the file.


 void Close():

 	   Clear private data memebers.
