--- DarthVader/RunInfo/src/RunInfo.cpp	2006/07/18 10:58:52	1.5
+++ DarthVader/RunInfo/src/RunInfo.cpp	2007/11/26 08:01:15	1.17
@@ -2,8 +2,10 @@
 #include <sstream>
 //
 #include <TObject.h>
+#include <TChain.h>
 #include <TSystem.h>
-#include <TArrayL.h>
+#include <TSystemFile.h>
+#include <TArrayI.h>
 #include <TFile.h>
 #include <TTree.h>
 #include <TDirectory.h>
@@ -20,6 +22,10 @@
 //
 
 SoftInfo::SoftInfo() {
+  Clear();
+}
+
+void SoftInfo::Clear(Option_t *t){
   TRIG_ver = "";
   TOF_ver = "";
   AC_ver = "";
@@ -28,7 +34,59 @@
   CAL_ver = "";
   ND_ver = "";
   S4_ver = "";  
+  DV_ver = "";
+}
+
+UInt_t SoftInfo::GetSWinfo(TString Detector){
+  TString sver;
+  UInt_t version = 0;
+  if ( !strcmp(Detector.Data(),"TRIG") ){
+    sver = TRIG_ver;
+  }; 
+  if ( !strcmp(Detector.Data(),"TOF") ){
+    sver = TOF_ver;
+  }; 
+  if ( !strcmp(Detector.Data(),"AC") ){
+    sver = AC_ver;
+  }; 
+  if ( !strcmp(Detector.Data(),"TRK") ){
+    sver = TRK_ver;
+  }; 
+  if ( !strcmp(Detector.Data(),"CALO") ){
+    sver = CAL_ver;
+  }; 
+  if ( !strcmp(Detector.Data(),"S4") ){
+    sver = S4_ver;
+  }; 
+  if ( !strcmp(Detector.Data(),"DV") ){
+    sver = DV_ver;
+  }; 
+  if ( !strcmp(Detector.Data(),"ND") ){
+    sver = ND_ver;
+  }; 
+  if ( !strcmp(Detector.Data(),"ORB") ){
+    sver = ORB_ver;
+  }; 
+  sver.ReplaceAll("v",1," ",1);
+  sver.ReplaceAll("r",1," ",1);
+  version = (UInt_t)sver.Atoi();
+  return(version);
+};
+
+/**
+ * Fills a struct cSoftInfo with values from a SoftInfo object (to put data into a F77 common).
+ */
+void SoftInfo::GetLevel2Struct(cSoftInfo *l2) const{
+  l2->FillTrigWith(TRIG_ver);
+  l2->FillTofWith(TOF_ver);
+  l2->FillAcWith(AC_ver);
+  l2->FillTrkWith(TRK_ver);
+  l2->FillOrbWith(ORB_ver);
+  l2->FillCalWith(CAL_ver);
+  l2->FillNdWith(ND_ver);
+  l2->FillS4With(S4_ver);
 }
+/***********************/
 
 ItoRunInfo::ItoRunInfo() {
   reprocessing = false;
@@ -36,20 +94,13 @@
   isreadonly = true;
   first_file_entry = 0;
   last_file_entry = 0;
-  file_entries = 0ULL;
-  totnorun = 0LL;
+  file_entries = 0;
+  totnorun = 0;
+  this->GL_RUN::Clear();
   version = new SoftInfo();
-  version->TRIG_ver = "";
-  version->TOF_ver = "";
-  version->AC_ver = "";
-  version->TRK_ver = "";
-  version->CAL_ver = "";
-  version->ND_ver = "";
-  version->S4_ver = "";  
-  version->ORB_ver = "";  
   norun = 0;
-  runlist = new TArrayL(0,NULL);
-  file = new TFile();
+  runlist = new TArrayI(500);
+  file = NULL;
   newtree = new TTree();
 }
 
@@ -58,26 +109,41 @@
   file=(TFile*)processFl;
   dbc=NULL;
   processFolder = "";
-  idRun = 0ULL;
+  idRun = 0;
   Detector = "NONE";
   //
   reprocessing = false;
   updating = false;
   first_file_entry = 0;
   last_file_entry = 0;
-  file_entries = 0ULL;
+  file_entries = 0;
   version = new SoftInfo();
-  version->TRIG_ver = "";
-  version->TOF_ver = "";
-  version->AC_ver = "";
-  version->TRK_ver = "";
-  version->ORB_ver = "";
-  version->CAL_ver = "";
-  version->ND_ver = "";
-  version->S4_ver = "";  
+  //  glrun = new GL_RUN();
   norun = 0;
   totnorun = 0;
-  //  runlist = new TArrayL(0,NULL);
+  runlist = new TArrayI(500);
+  //
+}
+
+
+
+TChain *ItoRunInfo::GetRunTree(TList *fl){
+  //
+  TChain *Tout = new TChain("Run");	
+  // loop over files and create chains	
+  TIter next(fl);
+  TSystemFile *questo = 0;
+  while ( (questo = (TSystemFile*) next()) ) {
+    TString name =  questo->GetName();
+    Tout->Add(name);
+  };
+  //
+  Tout->SetBranchAddress("RunInfo", GetPointerToRI());
+  printf("Run          : set branch address RunInfo\n");
+  Tout->SetBranchAddress("SoftInfo", GetPointerToSI());
+  printf("Software     : set branch address SoftInfo\n");
+  //
+  return Tout;    		
   //
 }
 
@@ -91,23 +157,70 @@
   updating = false;
   first_file_entry = 0;
   last_file_entry = 0;
-  file_entries = 0ULL;
+  file_entries = 0;
   version = new SoftInfo();
-  version->TRIG_ver = "";
-  version->TOF_ver = "";
-  version->AC_ver = "";
-  version->TRK_ver = "";
-  version->ORB_ver = "";
-  version->CAL_ver = "";
-  version->ND_ver = "";
-  version->S4_ver = "";  
   norun = 0;
   totnorun = 0;
-  runlist = new TArrayL(0,NULL);
+  runlist = new TArrayI(500);
+  //
+}
+
+void ItoRunInfo::CopyFromTo(GL_RUN *glrun,GL_RUN *newrun,SoftInfo *sinfo, SoftInfo *newver){
+  //
+  if ( glrun && newrun ){
+    //
+    //    printf("copy \n");
+    //
+    newrun->ID = glrun->ID                         ;
+    newrun->ID_RUN_FRAG = glrun-> ID_RUN_FRAG                ;
+    newrun->ID_ROOT_L0 = glrun->ID_ROOT_L0                 ;
+    newrun->ID_ROOT_L2 = glrun->ID_ROOT_L2                 ;
+    newrun->RUNHEADER_TIME = glrun->RUNHEADER_TIME             ;
+    newrun->RUNTRAILER_TIME = glrun->RUNTRAILER_TIME            ;
+    newrun->EV_FROM = glrun->EV_FROM                    ; 
+    newrun->EV_TO = glrun->EV_TO                      ; 
+    newrun->TRK_CALIB_USED = glrun->TRK_CALIB_USED             ;
+    newrun->EFF_WRK_SCHEDULE = glrun->EFF_WRK_SCHEDULE           ;
+    newrun->PRH_VAR_TRG_MODE_A = glrun->PRH_VAR_TRG_MODE_A         ;
+    newrun->PRH_VAR_TRG_MODE_B = glrun->PRH_VAR_TRG_MODE_B         ;
+    newrun->ACQ_BUILD_INFO =glrun->ACQ_BUILD_INFO             ;
+    newrun->ACQ_VAR_INFO = glrun->ACQ_VAR_INFO               ;
+    newrun->RUNHEADER_OBT = glrun->RUNHEADER_OBT              ;
+    newrun->RUNTRAILER_OBT = glrun->RUNTRAILER_OBT             ;
+    newrun->RUNHEADER_PKT = glrun->RUNHEADER_PKT              ;
+    newrun->RUNTRAILER_PKT = glrun->RUNTRAILER_PKT             ;
+    newrun->NEVENTS = glrun->NEVENTS                    ;
+    newrun->LAST_TIMESYNC = glrun->LAST_TIMESYNC              ;
+    newrun->OBT_TIMESYNC = glrun->OBT_TIMESYNC               ;
+    newrun->COMPILATIONTIMESTAMP = glrun->COMPILATIONTIMESTAMP       ;
+    newrun->FAV_WRK_SCHEDULE = glrun->FAV_WRK_SCHEDULE           ;
+    newrun->RM_ACQ_AFTER_CALIB = glrun->RM_ACQ_AFTER_CALIB         ;
+    newrun->RM_ACQ_SETTING_MODE = glrun->RM_ACQ_SETTING_MODE        ;
+    newrun->PKT_COUNTER = glrun->PKT_COUNTER                ;
+    newrun->PKT_READY_COUNTER = glrun->PKT_READY_COUNTER          ;
+    newrun->TRK_CALIB_USED = glrun->TRK_CALIB_USED             ;
+    newrun->CAL_DSP_MASK  = glrun->CAL_DSP_MASK               ;
+    newrun->BOOT_NUMBER  = glrun->BOOT_NUMBER                ;
+    newrun->VALIDATION  = glrun->VALIDATION                 ;
+    //
+  };
   //
+  if ( newver && sinfo ){
+    //
+    newver->TRIG_ver = sinfo->TRIG_ver;
+    newver->TOF_ver = sinfo->TOF_ver;
+    newver->AC_ver = sinfo->AC_ver;
+    newver->TRK_ver = sinfo->TRK_ver;
+    newver->ORB_ver = sinfo->ORB_ver;
+    newver->CAL_ver = sinfo->CAL_ver;
+    newver->S4_ver = sinfo->S4_ver;
+    newver->DV_ver = sinfo->DV_ver;
+    newver->ND_ver = sinfo->ND_ver;
+    //
+  };
 }
 
-Int_t ItoRunInfo::Update(ULong64_t run, TString Detector, TString Version){
+Int_t ItoRunInfo::Update(UInt_t run, TString Detector, TString Version){
   //
   isreadonly = false;
   idRun = run;
@@ -126,46 +239,16 @@
   SoftInfo *oldver = new SoftInfo();
   SoftInfo *newver = new SoftInfo();
   //
-  ID = 0ULL;
-  ID_REG_RUN = 0ULL;
-  ID_REG_RUN_L2 = 0ULL;
-  RUNHEADER_TIME = 0ULL;
-  RUNTRAILER_TIME = 0ULL;
-  EV_REG_PHYS_FROM = 0; 
-  EV_REG_PHYS_TO = 0;  
-  EV_REG_RUNHEADER = 0;  
-  EV_REG_RUNTRAILER = 0;  
-  TRK_CALIB_USED = 0;
-  EFF_WRK_SCHEDULE = 0;
-  PRH_VAR_TRG_MODE_A = 0;
-  PRH_VAR_TRG_MODE_B = 0;
-  ACQ_BUILD_INFO = 0;
-  ACQ_VAR_INFO = 0; 
-  version->TRIG_ver = "";
-  version->TOF_ver = "";
-  version->AC_ver = "";
-  version->TRK_ver = "";
-  version->ORB_ver = "";
-  version->CAL_ver = "";
-  version->ND_ver = "";
-  version->S4_ver = "";  
+  this->GL_RUN::Clear();
+  version->Clear();
   //
   norun = 0;
-  runlist = new TArrayL(0,NULL);
-  //runlist->Reset();
   //
   Bool_t found = false;
   Int_t error = 0;
   //
-  //  TFile *temprfile = 0;
-  //  TTree *temprrun = 0;
-  //  stringstream temprname;
-  //  stringstream tempdir;
-  //  const char* routdir = gSystem->DirName(gSystem->DirName(file->GetPath()));
-  //
   TTree *oldtree = 0;
   //
-  //
   // Try to get the tree Run in the processed file
   //
   oldtree = (TTree*)file->Get("Run");  
@@ -181,6 +264,7 @@
     version->ORB_ver = Version;
     version->CAL_ver = Version;    
     version->S4_ver = Version;
+    version->DV_ver = Version;
     version->ND_ver = Version;
   } else {
     if ( !strcmp(Detector.Data(),"TRIG") ) version->TRIG_ver = Version;
@@ -189,9 +273,10 @@
     if ( !strcmp(Detector.Data(),"TRK") ) version->TRK_ver = Version;
     if ( !strcmp(Detector.Data(),"CALO") ) version->CAL_ver = Version;
     if ( !strcmp(Detector.Data(),"S4") ) version->S4_ver = Version;
+    if ( !strcmp(Detector.Data(),"DV") ) version->DV_ver = Version;
     if ( !strcmp(Detector.Data(),"ND") ) version->ND_ver = Version;
     if ( !strcmp(Detector.Data(),"ORB") ) version->ORB_ver = Version;
-    if ( strcmp(Detector.Data(),"TRIG") && strcmp(Detector.Data(),"TOF") &&  strcmp(Detector.Data(),"AC") && strcmp(Detector.Data(),"TRK") &&  strcmp(Detector.Data(),"CALO") && strcmp(Detector.Data(),"S4") && strcmp(Detector.Data(),"ND") && strcmp(Detector.Data(),"ORB") ) return(-804);
+    if ( strcmp(Detector.Data(),"TRIG") && strcmp(Detector.Data(),"TOF") &&  strcmp(Detector.Data(),"AC") && strcmp(Detector.Data(),"TRK") &&  strcmp(Detector.Data(),"CALO") && strcmp(Detector.Data(),"S4") && strcmp(Detector.Data(),"ND") && strcmp(Detector.Data(),"ORB") && strcmp(Detector.Data(),"DV") ) return(-804);
   };
   //
   if ( !oldtree ) {
@@ -202,34 +287,6 @@
     //
   } else {
     //
-//     temprname.str("");
-//     temprname << routdir;
-//     temprname << "/" << processFolder.Data();
-//     gSystem->MakeDirectory(temprname.str().c_str());
-//     tempdir.str("");
-//     tempdir << temprname.str().c_str();
-//     temprname << "/runinfo_run";
-//     temprname << idRun << ".root";  
-//     if ( debug ) printf(" file temporaneo is %s \n",temprname.str().c_str());
-//     //
-//     temprfile = new TFile(temprname.str().c_str(),"RECREATE");
-//     //
-//     temprrun = new TTree();
-//     //
-//     if ( !temprfile ) return(-805);
-//     if ( !oldtree ) return(-806);
-//     if ( !temprrun ) return(-807);
-//     //
-//     temprrun = oldtree->CloneTree(-1,"fast");    
-//     //
-//     temprfile->cd();
-//     temprrun->SetName("Run-old");
-//     temprfile->Write();
-//     if ( temprrun ) temprrun->Delete();
-//     temprfile->Close();   
-//     //
-//     oldtree->Delete("all");
-    //
     updating = true;
     if ( debug ) printf(" RunInfo: updating versioning information \n");
     //
@@ -245,49 +302,24 @@
   //  
   //
   if ( !updating ){
-    if ( idRun == 0ULL ){
+    if ( idRun == 0 ){
       if ( debug ) printf("\n RUNINFO - ERROR: reprocessing data but no RunInfo tree in Level2 file. \n");
       return(-805);
     };
     //
-    runlist = new TArrayL(1);
-    //
     error = Query_GL_RUN(idRun, dbc);
     //
     if ( error ){
       if ( debug ) printf("\n RUNINFO - ERROR: Query_GL_RUN exited with non zero error\n");
       return(error);
     };
-    if ( ID == 0ULL ){
-      if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %llu \n",idRun);
+    if ( ID == 0 ){
+      if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %u \n",idRun);
       return(-5);
     };
     //
     //
-    //
-    newrun->ID = ID;
-    newrun->ID_REG_RUN = ID_REG_RUN;
-    newrun->ID_REG_RUN_L2 = ID_REG_RUN_L2;
-    newrun->RUNHEADER_TIME = RUNHEADER_TIME;
-    newrun->RUNTRAILER_TIME = RUNTRAILER_TIME;
-    newrun->EV_REG_PHYS_FROM = EV_REG_PHYS_FROM;
-    newrun->EV_REG_PHYS_TO = EV_REG_PHYS_TO;
-    newrun->EV_REG_RUNHEADER = EV_REG_RUNHEADER;
-    newrun->EV_REG_RUNTRAILER = EV_REG_RUNTRAILER;
-    newrun->TRK_CALIB_USED = TRK_CALIB_USED;
-    newrun->EFF_WRK_SCHEDULE = EFF_WRK_SCHEDULE;
-    newrun->PRH_VAR_TRG_MODE_A = PRH_VAR_TRG_MODE_A;
-    newrun->PRH_VAR_TRG_MODE_B = PRH_VAR_TRG_MODE_B;
-    newrun->ACQ_BUILD_INFO = ACQ_BUILD_INFO;
-    newrun->ACQ_VAR_INFO = ACQ_VAR_INFO;
-    newver->TRIG_ver = version->TRIG_ver;
-    newver->TOF_ver = version->TOF_ver;
-    newver->AC_ver = version->AC_ver;
-    newver->TRK_ver = version->TRK_ver;
-    newver->ORB_ver = version->ORB_ver;
-    newver->CAL_ver = version->CAL_ver;
-    newver->S4_ver = version->S4_ver;
-    newver->ND_ver = version->ND_ver;
+    CopyFromTo((GL_RUN*)this,newrun,version,newver);
     //
     // fill the tree;
     //
@@ -296,15 +328,14 @@
     totnorun = 1;
     reprocessing = false;
     first_file_entry = 0;
-    last_file_entry = (UInt_t)(EV_REG_PHYS_TO - EV_REG_PHYS_FROM);
+    if ( EV_TO >= EV_FROM ) last_file_entry = (UInt_t)(EV_TO - EV_FROM);
     norun = 1;
-    runlist->AddAt((Long64_t)ID,0);
+    runlist->AddAt((Int_t)ID,0);
     //
     newtree->SetName("Run");
     //
     file->cd();
-    //    file->Write("Run");
-    //newtree->Delete();
+    //
     delete newver;
     delete newrun;
     delete oldver;
@@ -314,15 +345,16 @@
     //
   } else {
     //
-    //    temprfile = new TFile(temprname.str().c_str(),"READ");
-    //    oldtree = (TTree*)temprfile->Get("Run-old");
     //
     oldtree->SetBranchAddress("RunInfo",&oldrun);
     oldtree->SetBranchAddress("SoftInfo",&oldver);
     //
     totnorun = oldtree->GetEntries();
     //
-    runlist = new TArrayL((Int_t)totnorun);
+    if ( totnorun > 500 ){
+      if ( debug ) printf("\n RUNINFO - ERROR: can not handle more than 500 runs!\n");
+      return(-806);
+    };
     //
     found = false;
     //
@@ -330,37 +362,15 @@
       //
       oldtree->GetEntry(run);
       //
-      newrun->ID = oldrun->ID;
-      newrun->ID_REG_RUN = oldrun->ID_REG_RUN;
-      newrun->ID_REG_RUN_L2 = oldrun->ID_REG_RUN_L2;
-      newrun->RUNHEADER_TIME = oldrun->RUNHEADER_TIME;
-      newrun->RUNTRAILER_TIME = oldrun->RUNTRAILER_TIME;
-      newrun->EV_REG_PHYS_FROM = oldrun->EV_REG_PHYS_FROM;
-      newrun->EV_REG_PHYS_TO = oldrun->EV_REG_PHYS_TO;
-      newrun->EV_REG_RUNHEADER = oldrun->EV_REG_RUNHEADER;
-      newrun->EV_REG_RUNTRAILER = oldrun->EV_REG_RUNTRAILER;
-      newrun->TRK_CALIB_USED = oldrun->TRK_CALIB_USED;
-      newrun->EFF_WRK_SCHEDULE = oldrun->EFF_WRK_SCHEDULE;
-      newrun->PRH_VAR_TRG_MODE_A = oldrun->PRH_VAR_TRG_MODE_A;
-      newrun->PRH_VAR_TRG_MODE_B = oldrun->PRH_VAR_TRG_MODE_B;
-      newrun->ACQ_BUILD_INFO = oldrun->ACQ_BUILD_INFO;
-      newrun->ACQ_VAR_INFO = oldrun->ACQ_VAR_INFO;
-      newver->TRIG_ver = oldver->TRIG_ver;
-      newver->TOF_ver = oldver->TOF_ver;
-      newver->AC_ver = oldver->AC_ver;
-      newver->TRK_ver = oldver->TRK_ver;
-      newver->ORB_ver = oldver->ORB_ver;
-      newver->CAL_ver = oldver->CAL_ver;
-      newver->S4_ver = oldver->S4_ver;
-      newver->ND_ver = oldver->ND_ver;
+      CopyFromTo(oldrun,newrun,oldver,newver);
       //
-      file_entries += (oldrun->EV_REG_PHYS_TO - oldrun->EV_REG_PHYS_FROM + 1);
+      file_entries += (oldrun->EV_TO - oldrun->EV_FROM + 1);
       //
       if ( debug ) printf("totnorun %i idRun %i newrun->ID %i \n",(int)totnorun,(int)idRun,(int)newrun->ID);
       //
-      if ( idRun == 0ULL || idRun == newrun->ID ) {
+      if ( idRun == 0 || idRun == newrun->ID ) {
 	//
-	if ( debug ) printf(" Updating run number %llu \n",idRun);
+	if ( debug ) printf(" Updating run number %u \n",idRun);
 	//
 	found = true;
 	//
@@ -378,21 +388,8 @@
  	    return(error);
  	  };
 	  //
-	  newrun->ID = ID;
-	  newrun->ID_REG_RUN = ID_REG_RUN;
-	  newrun->ID_REG_RUN_L2 = ID_REG_RUN_L2;
-	  newrun->RUNHEADER_TIME = RUNHEADER_TIME;
-	  newrun->RUNTRAILER_TIME = RUNTRAILER_TIME;
-	  newrun->EV_REG_PHYS_FROM = EV_REG_PHYS_FROM;
-	  newrun->EV_REG_PHYS_TO = EV_REG_PHYS_TO;
-	  newrun->EV_REG_RUNHEADER = EV_REG_RUNHEADER;
-	  newrun->EV_REG_RUNTRAILER = EV_REG_RUNTRAILER;
-	  newrun->TRK_CALIB_USED = TRK_CALIB_USED;
-	  newrun->EFF_WRK_SCHEDULE = EFF_WRK_SCHEDULE;
-	  newrun->PRH_VAR_TRG_MODE_A = PRH_VAR_TRG_MODE_A;
-	  newrun->PRH_VAR_TRG_MODE_B = PRH_VAR_TRG_MODE_B;
-	  newrun->ACQ_BUILD_INFO = ACQ_BUILD_INFO;
-	  newrun->ACQ_VAR_INFO = ACQ_VAR_INFO;
+	  CopyFromTo((GL_RUN*)this,newrun,NULL,NULL);
+	  //
 	} else {
 	  //
 	  if ( !strcmp(Detector.Data(),"TRIG") ){
@@ -403,6 +400,7 @@
 	    newver->ORB_ver = oldver->ORB_ver;
 	    newver->CAL_ver = oldver->CAL_ver;
 	    newver->S4_ver = oldver->S4_ver;
+	    newver->DV_ver = oldver->DV_ver;
 	    newver->ND_ver = oldver->ND_ver;
 	    if ( strcmp(oldver->TRIG_ver.Data(),"") ) reprocessing = true;
 	  };
@@ -413,6 +411,7 @@
 	    newver->TRK_ver = oldver->TRK_ver;
 	    newver->ORB_ver = oldver->ORB_ver;
 	    newver->CAL_ver = oldver->CAL_ver;
+	    newver->DV_ver = oldver->DV_ver;
 	    newver->S4_ver = oldver->S4_ver;
 	    newver->ND_ver = oldver->ND_ver;
 	    if ( strcmp(oldver->TOF_ver.Data(),"") ) reprocessing = true;
@@ -423,6 +422,7 @@
 	    newver->TRK_ver = oldver->TRK_ver;
 	    newver->ORB_ver = oldver->ORB_ver;
 	    newver->CAL_ver = oldver->CAL_ver;
+	    newver->DV_ver = oldver->DV_ver;
 	    newver->S4_ver = oldver->S4_ver;
 	    newver->ND_ver = oldver->ND_ver;
 	    newver->AC_ver = version->AC_ver;
@@ -433,6 +433,7 @@
 	    newver->TOF_ver = oldver->TOF_ver;
 	    newver->CAL_ver = oldver->CAL_ver;
 	    newver->ORB_ver = oldver->ORB_ver;
+	    newver->DV_ver = oldver->DV_ver;
 	    newver->S4_ver = oldver->S4_ver;
 	    newver->ND_ver = oldver->ND_ver;
 	    newver->AC_ver = oldver->AC_ver;
@@ -444,6 +445,7 @@
 	    newver->TOF_ver = oldver->TOF_ver;
 	    newver->CAL_ver = oldver->CAL_ver;
 	    newver->TRK_ver = oldver->TRK_ver;
+	    newver->DV_ver = oldver->DV_ver;
 	    newver->S4_ver = oldver->S4_ver;
 	    newver->ND_ver = oldver->ND_ver;
 	    newver->AC_ver = oldver->AC_ver;
@@ -453,6 +455,7 @@
 	  if ( !strcmp(Detector.Data(),"CALO") ){
 	    newver->TRIG_ver = oldver->TRIG_ver;
 	    newver->TOF_ver = oldver->TOF_ver;
+	    newver->DV_ver = oldver->DV_ver;
 	    newver->S4_ver = oldver->S4_ver;
 	    newver->ORB_ver = oldver->ORB_ver;
 	    newver->ND_ver = oldver->ND_ver;
@@ -469,12 +472,26 @@
 	    newver->TRK_ver = oldver->TRK_ver;
 	    newver->ORB_ver = oldver->ORB_ver;
 	    newver->CAL_ver = oldver->CAL_ver;
+	    newver->DV_ver = oldver->DV_ver;
 	    newver->S4_ver = version->S4_ver;
 	    if ( strcmp(oldver->S4_ver.Data(),"") ) reprocessing = true;
 	  };
+	  if ( !strcmp(Detector.Data(),"DV") ){
+	    newver->TRIG_ver = oldver->TRIG_ver;
+	    newver->TOF_ver = oldver->TOF_ver;
+	    newver->ND_ver = oldver->ND_ver;
+	    newver->AC_ver = oldver->AC_ver;
+	    newver->TRK_ver = oldver->TRK_ver;
+	    newver->ORB_ver = oldver->ORB_ver;
+	    newver->CAL_ver = oldver->CAL_ver;
+	    newver->S4_ver = oldver->S4_ver;
+	    newver->DV_ver = version->DV_ver;
+	    if ( strcmp(oldver->DV_ver.Data(),"") ) reprocessing = true;
+	  };
 	  if ( !strcmp(Detector.Data(),"ND") ){
 	    newver->TRIG_ver = oldver->TRIG_ver;
 	    newver->TOF_ver = oldver->TOF_ver;
+	    newver->DV_ver = oldver->DV_ver;
 	    newver->S4_ver = oldver->S4_ver;
 	    newver->AC_ver = oldver->AC_ver;
 	    newver->ORB_ver = oldver->ORB_ver;
@@ -485,10 +502,10 @@
 	  };
 	};
 	//
-	last_file_entry = first_file_entry + (oldrun->EV_REG_PHYS_TO - oldrun->EV_REG_PHYS_FROM + 1);
+	if ( oldrun->EV_TO >= oldrun->EV_FROM ) last_file_entry = first_file_entry + (oldrun->EV_TO - oldrun->EV_FROM + 1);
 	//
       } else {
-	if ( !found ) first_file_entry += (oldrun->EV_REG_PHYS_TO - oldrun->EV_REG_PHYS_FROM + 1);
+	if ( !found ) first_file_entry += (oldrun->EV_TO - oldrun->EV_FROM + 1);
       };
       //
       file->cd();
@@ -496,21 +513,17 @@
       //
     };
     //
-    //    temprfile->Close();
-    //    gSystem->Unlink(temprname.str().c_str());
-    //    if ( ismydir ) gSystem->Unlink(tempdir.str().c_str());
     file->cd();
     if ( oldtree ) oldtree->Delete("all");
     newtree->SetName("Run");
-    //    file->Write("Run");
-    //    newtree->Delete();
+    //
     delete newver;
     delete newrun;
     delete oldver;
     delete oldrun;
     //
     if ( !found ){
-      if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %llu \n",idRun);
+      if ( debug ) printf("\n RUNINFO - ERROR: no run with ID_RUN = %u \n",idRun);
       return(-5);
     };
     //
@@ -519,7 +532,7 @@
   return(0);
 }
 
-Int_t ItoRunInfo::Read(ULong64_t idRun){
+Int_t ItoRunInfo::Read(UInt_t idRun){
   //
   isreadonly = true;
   //
@@ -546,7 +559,10 @@
     //
     totnorun = newtree->GetEntries();
     //
-    runlist = new TArrayL((Int_t)totnorun);
+    if ( totnorun > 500 ){
+      if ( debug ) printf("\n RUNINFO - ERROR: can not handle more than 500 runs!\n");
+      return(-806);
+    };
     //
     first_file_entry = 0;
     //
@@ -554,38 +570,16 @@
       //
       newtree->GetEntry(run);
       //
-      file_entries += (newrun->EV_REG_PHYS_TO - newrun->EV_REG_PHYS_FROM + 1);
+      file_entries += (newrun->EV_TO - newrun->EV_FROM + 1);
       //
       if ( debug ) printf("totnorun %i  newrun->ID %i \n",(int)totnorun,(int)newrun->ID);
       //
-      ID = newrun->ID;
-      ID_REG_RUN = newrun->ID_REG_RUN;
-      ID_REG_RUN_L2 = newrun->ID_REG_RUN_L2;
-      RUNHEADER_TIME = newrun->RUNHEADER_TIME;
-      RUNTRAILER_TIME = newrun->RUNTRAILER_TIME;
-      EV_REG_PHYS_FROM = newrun->EV_REG_PHYS_FROM;
-      EV_REG_PHYS_TO = newrun->EV_REG_PHYS_TO;
-      EV_REG_RUNHEADER = newrun->EV_REG_RUNHEADER;
-      EV_REG_RUNTRAILER = newrun->EV_REG_RUNTRAILER;
-      TRK_CALIB_USED = newrun->TRK_CALIB_USED;
-      EFF_WRK_SCHEDULE = newrun->EFF_WRK_SCHEDULE;
-      PRH_VAR_TRG_MODE_A = newrun->PRH_VAR_TRG_MODE_A;
-      PRH_VAR_TRG_MODE_B = newrun->PRH_VAR_TRG_MODE_B;
-      ACQ_BUILD_INFO = newrun->ACQ_BUILD_INFO;
-      ACQ_VAR_INFO = newrun->ACQ_VAR_INFO;
-      version->TRIG_ver = newver->TRIG_ver;
-      version->TOF_ver = newver->TOF_ver;
-      version->AC_ver = newver->AC_ver;
-      version->TRK_ver = newver->TRK_ver;
-      version->ORB_ver = newver->ORB_ver;
-      version->CAL_ver = newver->CAL_ver;
-      version->S4_ver = newver->S4_ver;
-      version->ND_ver = newver->ND_ver;
-      if ( idRun == ID || idRun == 0ULL ){
+      CopyFromTo(newrun,(GL_RUN*)this,newver,version);
+      if ( idRun == ID || idRun == 0 ){
 	runlist->AddAt(newrun->ID,norun);
 	norun++;
       };
-      last_file_entry = first_file_entry + (newrun->EV_REG_PHYS_TO - newrun->EV_REG_PHYS_FROM + 1);
+      if ( newrun->EV_TO >= newrun->EV_FROM ) last_file_entry = first_file_entry + (newrun->EV_TO - newrun->EV_FROM + 1);
     };
   };
   if ( debug ) printf("norun %i \n",(int)norun);
@@ -602,14 +596,15 @@
   updating = false;
   first_file_entry = 0;
   last_file_entry = 0;
-  file_entries = 0ULL;
+  file_entries = 0;
   norun = 0;
-  runlist = new TArrayL(0,NULL);
-  file = new TFile();  
+  delete runlist;
+  //  file = new TFile();  
+  file = 0;  
   if ( isreadonly ) newtree->Delete();
 }
 
-void ItoRunInfo::Clear(){
+void ItoRunInfo::Clear(Option_t *t){
   if ( newtree ) newtree->Delete();
 }
 
@@ -621,7 +616,7 @@
   //
   if ( entry > (UInt_t)last_file_entry ){
     for ( UInt_t nrun = 0; nrun < norun; nrun++){  
-      if ( ID == (ULong64_t)runlist->At(nrun) ) {
+      if ( ID == (UInt_t)runlist->At(nrun) ) {
 	startfrom = nrun+1;
 	break;
       };
@@ -635,7 +630,7 @@
  retry:
   //
   for ( UInt_t nrun = startfrom; nrun < norun; nrun++){  
-    GetRunInfo((ULong64_t)runlist->At(nrun));
+    GetRunInfo((UInt_t)runlist->At(nrun));
     if ( entry >= (UInt_t)first_file_entry && entry <= (UInt_t)last_file_entry ){
       return((UInt_t)runlist->At(nrun));
     };
@@ -648,7 +643,7 @@
   return(0);
 }
 
-Int_t ItoRunInfo::GetRunInfo(ULong64_t run){
+Int_t ItoRunInfo::GetRunInfo(UInt_t run){
   Bool_t found = false;
   SoftInfo *nwver = new SoftInfo();
   GL_RUN *nwrun = new GL_RUN();
@@ -664,34 +659,12 @@
   for ( UInt_t nrun = 0; nrun < totnorun; nrun++){  
     newtree->GetEntry(nrun);
     //
-    if ( nwrun->ID == run || run == 0ULL ){
-      ID = nwrun->ID;
-      ID_REG_RUN = nwrun->ID_REG_RUN;
-      ID_REG_RUN_L2 = nwrun->ID_REG_RUN_L2;
-      RUNHEADER_TIME = nwrun->RUNHEADER_TIME;
-      RUNTRAILER_TIME = nwrun->RUNTRAILER_TIME;
-      EV_REG_PHYS_FROM = nwrun->EV_REG_PHYS_FROM;
-      EV_REG_PHYS_TO = nwrun->EV_REG_PHYS_TO;
-      EV_REG_RUNHEADER = nwrun->EV_REG_RUNHEADER;
-      EV_REG_RUNTRAILER = nwrun->EV_REG_RUNTRAILER;
-      TRK_CALIB_USED = nwrun->TRK_CALIB_USED;
-      EFF_WRK_SCHEDULE = nwrun->EFF_WRK_SCHEDULE;
-      PRH_VAR_TRG_MODE_A = nwrun->PRH_VAR_TRG_MODE_A;
-      PRH_VAR_TRG_MODE_B = nwrun->PRH_VAR_TRG_MODE_B;
-      ACQ_BUILD_INFO = nwrun->ACQ_BUILD_INFO;
-      ACQ_VAR_INFO = nwrun->ACQ_VAR_INFO;
-      version->TRIG_ver = nwver->TRIG_ver;
-      version->TOF_ver = nwver->TOF_ver;
-      version->AC_ver = nwver->AC_ver;
-      version->TRK_ver = nwver->TRK_ver;
-      version->ORB_ver = nwver->ORB_ver;
-      version->CAL_ver = nwver->CAL_ver;
-      version->S4_ver = nwver->S4_ver;
-      version->ND_ver = nwver->ND_ver;
+    if ( nwrun->ID == run || run == 0 ){
+      CopyFromTo(nwrun,(GL_RUN*)this,nwver,version);
       found = true;
-      last_file_entry = first_file_entry + (nwrun->EV_REG_PHYS_TO - nwrun->EV_REG_PHYS_FROM + 1);
+      if ( nwrun->EV_TO >= nwrun->EV_FROM ) last_file_entry = first_file_entry + (nwrun->EV_TO - nwrun->EV_FROM + 1);
     };
-    if ( !found ) first_file_entry += (nwrun->EV_REG_PHYS_TO - nwrun->EV_REG_PHYS_FROM + 1);
+    if ( !found ) first_file_entry += (nwrun->EV_TO - nwrun->EV_FROM + 1);
   };
   delete nwver;
   delete nwrun;