/[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.13 by pam-fi, Mon Jan 15 11:51:40 2007 UTC revision 1.18 by pam-fi, Thu Jan 18 08:51:16 2007 UTC
# Line 113  PamLevel2::PamLevel2(){ Line 113  PamLevel2::PamLevel2(){
113      orb_obj   = 0;      orb_obj   = 0;
114    
115      run_obj   = 0;//new GL_RUN();      run_obj   = 0;//new GL_RUN();
116            soft_obj   = 0;// Emiliano
117        irun = -1;
118        runfirstentry = 0ULL;
119        runlastentry = 0ULL;
120    
121      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;
122    
# Line 143  PamLevel2::PamLevel2(){ Line 146  PamLevel2::PamLevel2(){
146  void PamLevel2::Delete(){  void PamLevel2::Delete(){
147                    
148      if(run_obj)delete run_obj;      if(run_obj)delete run_obj;
149        if(soft_obj)delete soft_obj; //Emiliano
150    
151  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
152      if(trk1_obj) delete trk1_obj;            if(trk1_obj) delete trk1_obj;      
# Line 173  void PamLevel2::Delete(){ Line 177  void PamLevel2::Delete(){
177  void PamLevel2::Clear(){  void PamLevel2::Clear(){
178                    
179  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
180      if(run_obj)delete run_obj;  
181    //
182    // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't
183    // want to load them for each event even if they are the same...
184    //
185    //    if(run_obj)delete run_obj;
186    //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
187    //    if(soft_obj) soft_obj->Clear();
188    
189      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
190      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
# Line 209  void *PamLevel2::GetPointerTo(const char Line 220  void *PamLevel2::GetPointerTo(const char
220      TString objname = c;      TString objname = c;
221    
222      if(!objname.CompareTo("TrkLevel1"))  {      if(!objname.CompareTo("TrkLevel1"))  {
223          if(!trk1_obj)  trk1_obj  = new TrkLevel1();          if(!trk1_obj){
224                trk1_obj  = new TrkLevel1();
225                trk1_obj->Set();
226            }
227          return &trk1_obj;          return &trk1_obj;
228      };      };
229      if(!objname.CompareTo("TrkLevel2"))  {      if(!objname.CompareTo("TrkLevel2"))  {
230          if(!trk2_obj)  trk2_obj  = new TrkLevel2();          if(!trk2_obj){  
231                trk2_obj  = new TrkLevel2();
232                trk2_obj->Set();
233            }
234          return &trk2_obj;          return &trk2_obj;
235      };      };
236      if(!objname.CompareTo("TrkHough"))   {      if(!objname.CompareTo("TrkHough"))   {
# Line 225  void *PamLevel2::GetPointerTo(const char Line 242  void *PamLevel2::GetPointerTo(const char
242          return &calo1_obj;          return &calo1_obj;
243      };      };
244      if(!objname.CompareTo("CaloLevel2")) {      if(!objname.CompareTo("CaloLevel2")) {
245          if(!calo2_obj) calo2_obj = new CaloLevel2();          if(!calo2_obj){
246                calo2_obj = new CaloLevel2();
247                calo2_obj->Set();
248            };
249          return &calo2_obj;          return &calo2_obj;
250      };      };
251      if(!objname.CompareTo("ToFLevel2"))  {      if(!objname.CompareTo("ToFLevel2"))  {
252          if(!tof_obj)   tof_obj   = new ToFLevel2();          if(!tof_obj){
253                tof_obj   = new ToFLevel2();
254                tof_obj->Set();
255            }
256          return &tof_obj;          return &tof_obj;
257      };      };
258      if(!objname.CompareTo("TrigLevel2")) {      if(!objname.CompareTo("TrigLevel2")) {
# Line 254  void *PamLevel2::GetPointerTo(const char Line 277  void *PamLevel2::GetPointerTo(const char
277      };      };
278            
279      if(!objname.CompareTo("RunInfo"))return &run_obj;      if(!objname.CompareTo("RunInfo"))return &run_obj;
280    
281        if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano
282    
283      return NULL;      return NULL;
284  };  };
285  //--------------------------------------  //--------------------------------------
# Line 894  TList*  PamLevel2::GetListOfLevel2Files( Line 920  TList*  PamLevel2::GetListOfLevel2Files(
920      TList *contents  = new TList; // create output list      TList *contents  = new TList; // create output list
921      contents->SetOwner();      contents->SetOwner();
922            
923      char *fullpath;  //    char *fullpath;
924    //    const char *fullpath;
925            
926      // if no input file list is given:        // if no input file list is given:  
927      if ( flisttxt != "" ){      if ( flisttxt != "" ){
928                    
929          if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){  //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){        
930              cout <<"File "<<flisttxt<<" not found"<<endl;  //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){
931              return 0;  //          cout <<"File "<<flisttxt<<" not found"<<endl;
932          }        //          return 0;
933  //              flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));  //      }      
934          flisttxt = fullpath;  //      flisttxt = fullpath;
935            
936            flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt));
937    
938          if( !gSystem->ChangeDirectory(ddir) ){          if( !gSystem->ChangeDirectory(ddir) ){
939              cout << "Cannot change directory : "<<ddir<<endl;              cout << "Cannot change directory : "<<ddir<<endl;
940              return 0;              return 0;
# Line 914  TList*  PamLevel2::GetListOfLevel2Files( Line 943  TList*  PamLevel2::GetListOfLevel2Files(
943          cout <<"Input file list : " << flisttxt <<endl;          cout <<"Input file list : " << flisttxt <<endl;
944          ifstream in;          ifstream in;
945          in.open(flisttxt, ios::in); //open input file list          in.open(flisttxt, ios::in); //open input file list
946            if(!in.good()){
947                cout <<" ERROR opening the file "<<endl;
948                gSystem->ChangeDirectory(wdir); // back to the working directory
949                return 0;
950            }      
951          int line=0;          int line=0;
952          while (1) {          while (1) {
953              TString file;              TString file;
# Line 927  TList*  PamLevel2::GetListOfLevel2Files( Line 961  TList*  PamLevel2::GetListOfLevel2Files(
961              }              }
962              if(file.Contains("#"))file = file(0,file.First("#"));              if(file.Contains("#"))file = file(0,file.First("#"));
963  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
964              if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
965    //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
966                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));
967                contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
968              }else{              delete fullpath;
969    //          }else{
970  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
971              };  //          };
972          };          };
973          in.close();          in.close();
974                    
# Line 955  TList*  PamLevel2::GetListOfLevel2Files( Line 990  TList*  PamLevel2::GetListOfLevel2Files(
990          while ( (questo = (TSystemFile*) next()) ) {          while ( (questo = (TSystemFile*) next()) ) {
991              TString name =  questo-> GetName();              TString name =  questo-> GetName();
992              if( name.EndsWith(".root") ){              if( name.EndsWith(".root") ){
993                  char *fullpath;  //              const char *fullpath = gSystem->FindFile(ddir,name);
994                  gSystem->IsFileInIncludePath(name,&fullpath);  //              char *fullpath;
995    //              gSystem->IsFileInIncludePath(name,&fullpath);
996                    char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name));
997                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));
998                    delete fullpath;
999              };              };
1000          }          }
1001          delete temp;          delete temp;
# Line 967  TList*  PamLevel2::GetListOfLevel2Files( Line 1005  TList*  PamLevel2::GetListOfLevel2Files(
1005      gSystem->ChangeDirectory(wdir); // back to the working directory      gSystem->ChangeDirectory(wdir); // back to the working directory
1006  //      cout << endl << "Selected files:" << endl;  //      cout << endl << "Selected files:" << endl;
1007  //      contents->Print();  //      contents->Print();
1008      cout << contents->GetEntries()<<" files selected\n";      cout << contents->GetEntries()<<" files \n";
1009  //      cout << endl;  //      cout << endl;
1010  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;  //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl;
1011      return contents;      return contents;
# Line 1358  TChain *PamLevel2::GetRunTree(TList *fl) Line 1396  TChain *PamLevel2::GetRunTree(TList *fl)
1396            
1397      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1398      cout << "Run         : set branch address RunInfo"<<endl;      cout << "Run         : set branch address RunInfo"<<endl;
1399        R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1400        cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1401            
1402      return R;      return R;
1403            
# Line 1378  TTree *PamLevel2::GetRunTree(TFile *f){ Line 1418  TTree *PamLevel2::GetRunTree(TFile *f){
1418            
1419      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1420      cout << "Run         : set branch address RunInfo"<<endl;      cout << "Run         : set branch address RunInfo"<<endl;
1421        R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1422        cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1423            
1424      return R;      return R;
1425            
1426  }  }
1427    /**
1428     * Update the runinfo informations (to be used to have Run infos event by event basis)
1429     * @param run Pointer to the chain/tree which contains run infos
1430     * @return true if a new run has been read, false if it is still the same run
1431     */
1432    Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev){
1433      //
1434      // check if we have already called once GetEntry, if not call it
1435      //
1436      if ( run->GetEntries() <= 0 ) return(false);
1437      //
1438      Int_t oldrun = irun;
1439      if ( irun < 0 ){
1440        irun = 0;
1441        run->GetEntry(0);
1442        runfirstentry = 0ULL;
1443        runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;
1444      };
1445      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1446        //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1447        irun++;
1448        run->GetEntry(irun);
1449        runfirstentry = runlastentry+1ULL;
1450        runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1451      };
1452      //
1453      if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1454      //
1455      //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1456      //
1457      return(true);    
1458      //
1459    };
1460    /**
1461     * Update the runinfo informations (to be used to have Run infos event by event basis)
1462     * @param run Pointer to the chain/tree which contains run infos
1463     * @return true if a new run has been read, false if it is still the same run
1464     */
1465    Bool_t PamLevel2::UpdateRunInfo(TTree *run, ULong64_t iev){
1466      return(UpdateRunInfo((TChain*)run,iev));
1467    };
1468    
1469  //--------------------------------------  //--------------------------------------
1470  //  //
1471  //  //

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.23