/[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.74 by mocchiut, Tue Dec 16 12:43:08 2008 UTC revision 1.79 by pam-fi, Wed Mar 18 09:02:01 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 2637  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2648  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2648          if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;          if( !GetOrbitalInfo() )cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated "<<endl;
2649          if ( gltsync ) delete gltsync; //Emiliano          if ( gltsync ) delete gltsync; //Emiliano
2650          if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano          if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2651          gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc); //Emiliano          gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); //Emiliano // the "false" means not to use level0 file (not necessary here)
2652          if ( dbc ) dbc->Close();// Emiliano          if ( dbc ) dbc->Close();// Emiliano
2653      };            };      
2654      // ---------------------------------------------------------------      // ---------------------------------------------------------------
# Line 2780  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2791  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2791              irunt = irun - irunoffset[run_tree->GetTreeNumber()];              irunt = irun - irunoffset[run_tree->GetTreeNumber()];
2792              if ( gltsync ) delete gltsync; // Emiliano              if ( gltsync ) delete gltsync; // Emiliano
2793              if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano              if(!dbc || (dbc && !dbc->IsConnected()) )SetDBConnection(); //Emiliano
2794              gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc); // Emiliano              gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0,"ID",dbc,false); // Emiliano
2795              if ( dbc ) dbc->Close(); // Emiliano              if ( dbc ) dbc->Close(); // Emiliano
2796              if(gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT)>gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ){ // Emiliano              if(gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT)>gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ){ // Emiliano
2797                  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 3134  void  PamLevel2::GetWhichTrees(TFile* f)
3134      }      }
3135    
3136      TList *lk = f->GetListOfKeys();      TList *lk = f->GetListOfKeys();
3137        if(!lk)return;
3138      TIter next(lk);      TIter next(lk);
3139      TKey *key =0;      TKey *key =0;
3140    
# Line 3445  Bool_t  PamLevel2::CheckLevel2File(TStri Line 3457  Bool_t  PamLevel2::CheckLevel2File(TStri
3457              if(GP){              if(GP){
3458                  Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();                  Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries();
3459                  if( nev && nevt!=nev){                  if( nev && nevt!=nev){
3460                      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;
3461                      return false;                      return false;
3462                  }                  }
3463                  nev=nevt;                  nev=nevt;
# Line 3737  void PamLevel2::CreateCloneTrees(TFile * Line 3749  void PamLevel2::CreateCloneTrees(TFile *
3749      };      };
3750      // GPamela      // GPamela
3751      if(GP) {      if(GP) {
3752          pam_tree_clone[i] = new TTree("h20","PAMELA orbital info  ");            pam_tree_clone[i] = new TTree("h20","GPAMELA info ");  
3753          pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split          pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split
3754          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
3755          i++;          i++;
# Line 3833  Int_t PamLevel2::GetEntry(Long64_t iee){ Line 3845  Int_t PamLevel2::GetEntry(Long64_t iee){
3845      //-------------------------------      //-------------------------------
3846      ii = iee;      ii = iee;
3847      if( !pam_tree->GetEntry(ii) ){            if( !pam_tree->GetEntry(ii) ){      
3848          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;
3849          return 0;        return 0;
3850      }      }
   
3851      //      //
3852      // ... 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.
3853      // 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.74  
changed lines
  Added in v.1.79

  ViewVC Help
Powered by ViewVC 1.1.23