/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Diff of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.75 by mocchiut, Tue Jan 27 11:37:39 2009 UTC revision 1.80 by pam-fi, Wed Mar 25 14:42:36 2009 UTC
# Line 397  PamLevel2::PamLevel2(){ Line 397  PamLevel2::PamLevel2(){
397   * If no options are specified, the default is assumed. Default is:   * If no options are specified, the default is assumed. Default is:
398   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
399   */   */
400  PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){  PamLevel2::PamLevel2(TString ddir,TString llist,TString detlist){
401      Initialize();      Initialize();
402      TList*  listf = GetListOfLevel2Files(ddir,list);      TList*  listf = GetListOfLevel2Files(ddir,llist);
403      GetPamTree(listf,detlist);      if(listf)GetPamTree(listf,detlist);
404      GetRunTree(listf);      if(listf)GetRunTree(listf);
405  };  };
406    
407  PamLevel2::PamLevel2(TString ddir,TList *list,TString detlist){  PamLevel2::PamLevel2(TString ddir,TList *llist,TString detlist){
408      Initialize();      Initialize();
409      GetPamTree(list,detlist);      GetPamTree(llist,detlist);
410      GetRunTree(list);      GetRunTree(llist);
411  };  };
412  /**  /**
413   * Constructor   * Constructor
# Line 416  PamLevel2::PamLevel2(TString ddir,TList Line 416  PamLevel2::PamLevel2(TString ddir,TList
416   * Default trees/branches are loaded. Default is:   * Default trees/branches are loaded. Default is:
417   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB   * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB
418   */   */
419  PamLevel2::PamLevel2(TString ddir,TString list){  PamLevel2::PamLevel2(TString ddir,TString llist){
420      Initialize();      Initialize();
421      TList*  listf = GetListOfLevel2Files(ddir,list);      TList*  listf = GetListOfLevel2Files(ddir,llist);
422      GetPamTree(listf,"");      GetPamTree(listf,"");
423      GetRunTree(listf);      GetRunTree(listf);
424  };  };
# Line 1867  TTree *PamLevel2::GetPamTree(TFile *f, T Line 1867  TTree *PamLevel2::GetPamTree(TFile *f, T
1867  TList*  PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){  TList*  PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){
1868                    
1869      TString wdir = gSystem->WorkingDirectory();      TString wdir = gSystem->WorkingDirectory();
1870        
     //    if(ddir=="")ddir = wdir;  
 //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);  
1871      if ( ddir != ""){      if ( ddir != ""){
1872          cout << "Level2 data directory : "<<  ddir << endl;          cout << "Level2 data directory : "<<  ddir << endl;
1873      } else {      } else {
# Line 1878  TList*  PamLevel2::GetListOfLevel2Files( Line 1876  TList*  PamLevel2::GetListOfLevel2Files(
1876      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
1877      contents->SetOwner();      contents->SetOwner();
1878            
1879  //    char *fullpath;      // --------------------------------------
1880  //    const char *fullpath;      // case 1 : input file/file-list provided
1881            // --------------------------------------
     // if no input file list is given:    
1882      if ( flisttxt != "" ){      if ( flisttxt != "" ){
1883                    
1884  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){                  // --------------------------------------
1885  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){          // a list of files given as input
1886  //          cout <<"File "<<flisttxt<<" not found"<<endl;          // --------------------------------------
 //          return 0;  
 //      }        
 //      flisttxt = fullpath;  
1887          if ( !flisttxt.EndsWith(".root") ){          if ( !flisttxt.EndsWith(".root") ){
1888    
1889              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              TString dir = gSystem->DirName(flisttxt);
1890    //          cout << " List directory "<<dir<<endl;
1891                if(dir == "." || dir == "")
1892                    flisttxt = gSystem->ConcatFileName(wdir.Data(),gSystem->BaseName(flisttxt));
1893    //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1894    
1895              if( !gSystem->ChangeDirectory(ddir) ){              if( !gSystem->ChangeDirectory(ddir) ){
1896                  cout << "Cannot change directory : "<<ddir<<endl;                  cout << "Cannot change directory : "<<ddir<<endl;
# Line 1903  TList*  PamLevel2::GetListOfLevel2Files( Line 1901  TList*  PamLevel2::GetListOfLevel2Files(
1901              ifstream in;              ifstream in;
1902              in.open(flisttxt, ios::in); //open input file list              in.open(flisttxt, ios::in); //open input file list
1903              if(!in.good()){              if(!in.good()){
1904                  cout <<" ERROR opening the file "<<endl;                  cout <<" TList*  PamLevel2::GetListOfLevel2Files(TString, TString) --> ERROR opening the file "<<endl;
1905                  gSystem->ChangeDirectory(wdir); // back to the working directory                  gSystem->ChangeDirectory(wdir); // back to the working directory
1906                  return 0;                  return 0;
1907              }                }  
1908              int line=0;              int line=0;
1909                // ...........................
1910                // loop over file-list records
1911                // ...........................
1912              while (1) {              while (1) {
1913                  TString file;                  TString file;
1914                  in >> file;                  in >> file;
1915                  if (!in.good()) break;                  if (!in.good()) break;
1916                  line++;                  line++;
1917  //          cout <<"(1) " << file << endl;                  cout <<"(*) " << file << endl;
1918                  if(file.IsNull()){                  if(file.IsNull()){
1919                      cout << "-- list interrupted at line "<<line <<endl;                      cout << "-- list interrupted at line "<<line <<endl;
1920                      break;                      break;
1921                  }                  }
1922                  if(file.Contains("#"))file = file(0,file.First("#"));                  if(file.Contains("#"))file = file(0,file.First("#"));
1923  //          cout <<"(2) " << file << endl;                  //
1924  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){                  // take only root files
1925  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){                  //
1926                  if( file.EndsWith(".root") ){                  if( file.EndsWith(".root") ){
1927                      TString filedir;                      TString filedir;
1928                        cout << ddir << endl;
1929                      if (ddir != ""){                      if (ddir != ""){
1930                          filedir = ddir; // take the input dir                          filedir = ddir; // take the input dir
1931                      } else {                      } else {
1932                          gSystem->ChangeDirectory(wdir); // back to the working directory                          gSystem->ChangeDirectory(wdir); // back to the working directory
1933                          filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir                          filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir
1934                      };                      };
1935                        filedir.Append("/");
1936                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));                      char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file));
1937                      contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                      contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1938                        cout << fullpath << endl;
1939                      delete fullpath;                      delete fullpath;
1940                  }                  }
1941  //          }else{  //          }else{
# Line 1939  TList*  PamLevel2::GetListOfLevel2Files( Line 1943  TList*  PamLevel2::GetListOfLevel2Files(
1943  //          };  //          };
1944              };              };
1945              in.close();              in.close();
1946            // --------------------------------------
1947            // a single root file given as input
1948            // --------------------------------------
1949          } else {          } else {
1950              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));              if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#"));
1951              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
1952              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1953              delete fullpath;              delete fullpath;
1954          };                };      
1955        // ---------------------------------------------------------------------------------
1956        // case 2 : no input file/file-list provided --> read all files insede the directory
1957        // ---------------------------------------------------------------------------------
1958      }else{      }else{
1959                    
1960          cout << "No input file list given."<<endl;          cout << "No input file list given."<<endl;
# Line 1957  TList*  PamLevel2::GetListOfLevel2Files( Line 1967  TList*  PamLevel2::GetListOfLevel2Files(
1967    
1968          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);          TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir);
1969          TList *temp = datadir->GetListOfFiles();          TList *temp = datadir->GetListOfFiles();
1970            if(!temp)return 0;
1971  //              temp->Print();  //              temp->Print();
1972  //              cout << "*************************************" << endl;  //              cout << "*************************************" << endl;
1973                    
# Line 2724  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2735  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2735                          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time                          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time
2736                      }                      }
2737                      totdltime[2]--;                              //event counter                      totdltime[2]--;                              //event counter
2738                      cout << endl;                      if(DBG){
2739                      cout << "n.events     : "<<totdltime[2]<<endl;                          cout << endl;
2740                      cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;                          cout << "n.events     : "<<totdltime[2]<<endl;
2741                      cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;                                cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl;
2742                            cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl;          
2743                        }
2744                  }else{                  }else{
2745                      totdltime[0]=0;//live-time                      totdltime[0]=0;//live-time
2746                      totdltime[1]=0;//dead-time                      totdltime[1]=0;//dead-time
2747                      totdltime[2]=0;                             //event counter                      totdltime[2]=0;                             //event counter
2748                      cout << " *** JUMP RUN *** irun "<<irun<<endl;                      if(DBG)cout << " *** JUMP RUN *** irun "<<irun<<endl;
2749                  }                  }
2750                  /// add an entry                  /// add an entry
2751                  if(run_tree_clone)                  if(run_tree_clone)
# Line 2780  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2793  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2793              irunt = irun - irunoffset[run_tree->GetTreeNumber()];              irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2794              if ( gltsync ) delete gltsync; // Emiliano              if ( gltsync ) delete gltsync; // Emiliano
2795              if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano              if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2796              gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc); // Emiliano              gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); // Emiliano
2797              if ( dbc ) dbc->Close(); // Emiliano              if ( dbc ) dbc->Close(); // Emiliano
2798              if(gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT)>gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ){ // Emiliano              if(gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT)>gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ){ // Emiliano
2799                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;                  cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl;
# Line 3123  void  PamLevel2::GetWhichTrees(TFile* f) Line 3136  void  PamLevel2::GetWhichTrees(TFile* f)
3136      }      }
3137    
3138      TList *lk = f->GetListOfKeys();      TList *lk = f->GetListOfKeys();
3139        if(!lk)return;
3140      TIter next(lk);      TIter next(lk);
3141      TKey *key =0;      TKey *key =0;
3142    
# Line 3445  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3459  Bool_t  PamLevel2::CheckLevel2File(TStri
3459              if(GP){              if(GP){
3460                  Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();                  Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3461                  if( nev && nevt!=nev){                  if( nev && nevt!=nev){
3462                      cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl;                      cout << "File: "<< f->GetName() <<" discarded ---- h20 tree has "<<nevt<<" events instead of "<<nev<< endl;
3463                      return false;                      return false;
3464                  }                  }
3465                  nev=nevt;                  nev=nevt;
# Line 3737  void PamLevel2::CreateCloneTrees(TFile * Line 3751  void PamLevel2::CreateCloneTrees(TFile *
3751      };      };
3752      // GPamela      // GPamela
3753      if(GP) {      if(GP) {
3754          pam_tree_clone[i] = new TTree("h20","PAMELA orbital info  ");            pam_tree_clone[i] = new TTree("h20","GPAMELA info ");  
3755          pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split          pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3756          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3757          i++;          i++;
# Line 3833  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3847  Int_t PamLevel2::GetEntry(Long64_t iee){
3847      //-------------------------------      //-------------------------------
3848      ii = iee;      ii = iee;
3849      if( !pam_tree->GetEntry(ii) ){            if( !pam_tree->GetEntry(ii) ){      
3850          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;        cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl;
3851          return 0;        return 0;
3852      }      }
   
3853      //      //
3854      // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.      // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0.
3855      // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not      // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not

Legend:
Removed from v.1.75  
changed lines
  Added in v.1.80

  ViewVC Help
Powered by ViewVC 1.1.23