/[PAMELA software]/PadmeAmidala/src/RunGlue.cpp
ViewVC logotype

Diff of /PadmeAmidala/src/RunGlue.cpp

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

revision 1.12 by mocchiut, Wed Dec 10 13:15:59 2008 UTC revision 1.16 by mocchiut, Fri Jan 30 16:17:31 2009 UTC
# Line 42  RunGlue::RunGlue(TSQLServer *da, UInt_t Line 42  RunGlue::RunGlue(TSQLServer *da, UInt_t
42      runmode = false;      runmode = false;
43      createlist = true;      createlist = true;
44    };    };
45      fUpgrade = true;
46    //    //
47    //  lList = new TList();    //  lList = new TList();
48    //    //
# Line 394  Bool_t RunGlue::OpenFile(){ Line 395  Bool_t RunGlue::OpenFile(){
395      return(false);      return(false);
396    } else {    } else {
397      //      //
398        // try to lock tables and work on a db level to avoid multiple file simultaneous access
399        //
400        stringstream oss;
401        //  
402        if ( fUpgrade ){
403          oss.str("");
404          oss << "lock table GL_ROOT write;";
405          TSQLResult *result = 0;
406          TSQLRow *row = 0;
407          result = dbc->Query(oss.str().c_str());
408          oss.str("");
409          oss << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';";
410          result = dbc->Query(oss.str().c_str());
411          row = result->Next();
412          if ( row ){
413            printf("Error opening target file (does %s exist? already in the DB? are the permissions ok?)\n",(this->GetFilename()).Data());
414            return(false);
415          } else {
416            oss.str("");
417            oss << "insert into GL_ROOT (PATH,NAME) values ('$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";      
418            result = dbc->Query(oss.str().c_str());
419          };
420          oss.str("");
421          oss << "unlock tables;";
422          result = dbc->Query(oss.str().c_str());
423        };
424        //    Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );
425        Target = TFile::Open((this->GetFilename()).Data(), "NEW" );    
426        //    
427      printf(" Output file does not exist, creating it\n");      printf(" Output file does not exist, creating it\n");
428      //      //
429      Long64_t maxsize = 99900000000LL;        Long64_t maxsize = 99900000000LL;  
430      //      //
431      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );      if ( !Target || Target->IsZombie()) {
432          printf("Error opening target file (does %s exist? are the permissions ok?)\n",(this->GetFilename()).Data());
433          //      exit(1);
434          return(false);
435        }
436        //
437        Target->Write();
438        //
439      //fastMethod = kTRUE;      //fastMethod = kTRUE;
440      fastMethod = kFALSE;      fastMethod = kFALSE;
441      //          //    
     //      
     if ( !Target || Target->IsZombie()) {  
       printf("Error opening target file (does %s exist?)\n",(this->GetFilename()).Data());  
       exit(1);  
     }  
442      //      //
443      TTree::SetMaxTreeSize(maxsize);      TTree::SetMaxTreeSize(maxsize);
444      Target->SetCompressionLevel(2);      //    Target->SetCompressionLevel(2);
445        Target->SetCompressionLevel(3);
446      //Target->SetCompressionLevel(5);      //Target->SetCompressionLevel(5);
447      //      //
448      fOpen = true;      fOpen = true;
# Line 472  void RunGlue::UpdateDB(TList *dlist){ Line 505  void RunGlue::UpdateDB(TList *dlist){
505    };    };
506    //    //
507    myquery.str("");    myquery.str("");
   //  myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";  
   myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";  
   if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());  
   //  
   pResult = dbc->Query(myquery.str().c_str());  
   if ( !pResult ){  
     printf(" ERROR WRITING ON DB!\n");  
     return;  
   };  
   myquery.str("");  
508    myquery << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';";    myquery << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';";
509    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
510    //    //
# Line 497  void RunGlue::UpdateDB(TList *dlist){ Line 520  void RunGlue::UpdateDB(TList *dlist){
520    } else {    } else {
521      idl2 = (UInt_t)atoll(Row->GetField(0));      idl2 = (UInt_t)atoll(Row->GetField(0));
522    };    };
523      myquery.str("");
524      //  myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
525      //  myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
526      myquery << "update GL_ROOT set ID_RAW=" << idr << " where ID=" << idl2 << ";";
527      if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
528      //
529      pResult = dbc->Query(myquery.str().c_str());
530      if ( !pResult ){
531        printf(" ERROR WRITING ON DB!\n");
532        return;
533      };
534    //    //
535    //    //
536    //    //
# Line 533  void RunGlue::MergeRootfile(TList *sourc Line 567  void RunGlue::MergeRootfile(TList *sourc
567    //    //
568    if ( li ) li->Delete();    if ( li ) li->Delete();
569    li = new PamLevel2(wd,sourcelist,fDList);    li = new PamLevel2(wd,sourcelist,fDList);
570      li->SetSELLI(2);
571    //    //
572    Target->cd();    Target->cd();
573    //    //
# Line 547  void RunGlue::MergeRootfile(TList *sourc Line 582  void RunGlue::MergeRootfile(TList *sourc
582    };    };
583    Target->cd();    Target->cd();
584    li->WriteCloneTrees();    li->WriteCloneTrees();
585    printf(" file %s \n",Target->GetName());    printf("Written file %s \n",Target->GetName());
586    //  Target->Write();    //  Target->Write();
587    TTree *slist = (TTree*)Target->Get("SelectionList");    //  TTree *slist = (TTree*)Target->Get("SelectionList");
588    slist->Delete("all");    //  slist->Delete("all");
589    Target->Close();    Target->Close();
590    
591  //   //  //   //
# Line 754  void RunGlue::MergeRootfile(TList *sourc Line 789  void RunGlue::MergeRootfile(TList *sourc
789  };  };
790    
791    
792  Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){  // Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){
793     // We must have been passed a file, we will use it  //    // We must have been passed a file, we will use it
794     // later to reset the compression level of the branches.  //    // later to reset the compression level of the branches.
795     if (!file) {  //    if (!file) {
796        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
797       printf(" 19 \n");  //      printf(" 19 \n");
798       return 0;  //      return 0;
799     }  //    }
800     printf(" 20 \n");  //    printf(" 20 \n");
801    
802     // Options  //    // Options
803     Bool_t fastClone = kFALSE;  //    Bool_t fastClone = kFALSE;
804     TString opt = option;  //    TString opt = option;
805     opt.ToLower();  //    opt.ToLower();
806     if (opt.Contains("fast")) {  //    if (opt.Contains("fast")) {
807        fastClone = kTRUE;  //       fastClone = kTRUE;
808        printf(" 21 \n");  //       printf(" 21 \n");
809     }  //    }
810     // The chain tree must have a list of branches  //    // The chain tree must have a list of branches
811     // because we may try to change their basket  //    // because we may try to change their basket
812     // size later.  //    // size later.
813     TObjArray* lbranches = mychain->GetListOfBranches();  //    TObjArray* lbranches = mychain->GetListOfBranches();
814     if (!lbranches) {  //    if (!lbranches) {
815        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
816       printf(" 22 \n");  //      printf(" 22 \n");
817        return 0;  //       return 0;
818     }  //    }
819    
820     //   file->cd();  //    //   file->cd();
821     // The chain must have a current tree because  //    // The chain must have a current tree because
822     // that is the one we will clone.  //    // that is the one we will clone.
823     //   if (!fTree) {  //    //   if (!fTree) {
824        // -- LoadTree() has not yet been called, no current tree.  //       // -- LoadTree() has not yet been called, no current tree.
825        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
826     //      return 0;  //    //      return 0;
827     //   }  //    //   }
828    
829     // Copy the chain's current tree without  //    // Copy the chain's current tree without
830     // copying any entries, we will do that later.  //    // copying any entries, we will do that later.
831     printf(" 23 \n");  //    printf(" 23 \n");
832     TTree* newTree = mychain->CloneTree(0);  //    TTree* newTree = mychain->CloneTree(0);
833     if (!newTree) {  //    if (!newTree) {
834        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
835       printf(" 24 \n");  //      printf(" 24 \n");
836        return 0;  //       return 0;
837     }  //    }
838     printf(" 25 \n");  //    printf(" 25 \n");
839    
840    
841     // Strip out the (potential) directory name.  //    // Strip out the (potential) directory name.
842     // FIXME: The merged chain may or may not have the  //    // FIXME: The merged chain may or may not have the
843     //        same name as the original chain.  This is  //    //        same name as the original chain.  This is
844     //        bad because the chain name determines the  //    //        bad because the chain name determines the
845     //        names of the trees in the chain by default.  //    //        names of the trees in the chain by default.
846     printf(" 26 \n");  //    printf(" 26 \n");
847     newTree->SetName(gSystem->BaseName(mychain->GetName()));  //    newTree->SetName(gSystem->BaseName(mychain->GetName()));
848     printf(" 27 \n");  //    printf(" 27 \n");
849    
850     // FIXME: Why do we do this?  //    // FIXME: Why do we do this?
851     //   newTree->SetAutoSave(-1);  //    //   newTree->SetAutoSave(-1);
852     newTree->SetAutoSave(900000000000000LL);  //    newTree->SetAutoSave(900000000000000LL);
853    
854     printf(" 28 \n");  //    printf(" 28 \n");
855     // Circularity is incompatible with merging, it may  //    // Circularity is incompatible with merging, it may
856     // force us to throw away entries, which is not what  //    // force us to throw away entries, which is not what
857     // we are supposed to do.  //    // we are supposed to do.
858     newTree->SetCircular(0);  //    newTree->SetCircular(0);
859    
860     // Reset the compression level of the branches.  //    // Reset the compression level of the branches.
861     if (opt.Contains("c")) {  //    if (opt.Contains("c")) {
862        TBranch* branch = 0;  //       TBranch* branch = 0;
863        TIter nextb(newTree->GetListOfBranches());  //       TIter nextb(newTree->GetListOfBranches());
864        while ((branch = (TBranch*) nextb())) {  //       while ((branch = (TBranch*) nextb())) {
865          printf(" 29 \n");  //      printf(" 29 \n");
866           branch->SetCompressionLevel(file->GetCompressionLevel());  //          branch->SetCompressionLevel(file->GetCompressionLevel());
867        }  //       }
868     }  //    }
869    
870     printf(" 30 \n");  //    printf(" 30 \n");
871     // Reset the basket size of the branches.  //    // Reset the basket size of the branches.
872     if (basketsize > 1000) {  //    if (basketsize > 1000) {
873        TBranch* branch = 0;  //       TBranch* branch = 0;
874        TIter nextb(newTree->GetListOfBranches());  //       TIter nextb(newTree->GetListOfBranches());
875        while ((branch = (TBranch*) nextb())) {  //       while ((branch = (TBranch*) nextb())) {
876          printf(" 31 \n");  //      printf(" 31 \n");
877           branch->SetBasketSize(basketsize);  //          branch->SetBasketSize(basketsize);
878        }  //       }
879     }  //    }
880    
881     printf(" 32 \n");  //    printf(" 32 \n");
882     Long64_t nentries = mychain->GetEntriesFast();  //    Long64_t nentries = mychain->GetEntriesFast();
883     //Long64_t nentries = mychain->GetEntries();  //    //Long64_t nentries = mychain->GetEntries();
884    
885     // Copy the entries.  //    // Copy the entries.
886     if (fastClone) {  //    if (fastClone) {
887        // For each tree in the chain.  //       // For each tree in the chain.
888        for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {  //       for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
889           if (mychain->LoadTree(i) < 0) {  //          if (mychain->LoadTree(i) < 0) {
890              break;  //             break;
891           }  //          }
892           TTreeCloner cloner(mychain->GetTree(), newTree, option);  //          TTreeCloner cloner(mychain->GetTree(), newTree, option);
893           if (cloner.IsValid()) {  //          if (cloner.IsValid()) {
894              newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());  //             newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
895              cloner.Exec();  //             cloner.Exec();
896           } else {  //          } else {
897              if (mychain->GetFile()) {  //             if (mychain->GetFile()) {
898                printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());  //            printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
899                 //            } else {  //             //            } else {
900                 //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);  //             //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
901              }  //             }
902           }  //          }
903        }  //       }
904     } else {  //    } else {
905       printf(" 33 %llu \n",nentries);  //      printf(" 33 %llu \n",nentries);
906       mychain->Print();  //      mychain->Print();
907       for (Long64_t i = 0; i < nentries; i++) {  //      for (Long64_t i = 0; i < nentries; i++) {
908         printf(" i %llu \n",i);  //        printf(" i %llu \n",i);
909         // for (Long64_t i = 0; i < 1; i++) {  //        // for (Long64_t i = 0; i < 1; i++) {
910           if (mychain->GetEntry(i) <= 0) {  //          if (mychain->GetEntry(i) <= 0) {
911              break;  //             break;
912           }  //          }
913           newTree->Fill();  //          newTree->Fill();
914        }  //       }
915        printf(" 34 \n");  //       printf(" 34 \n");
916     }  //    }
917    
918     // Write the new tree header.  //    // Write the new tree header.
919     printf(" 35 \n");  //    printf(" 35 \n");
920     newTree->Write();  //    newTree->Write();
921    
922     printf(" 36 \n");  //    printf(" 36 \n");
923     // Get our return value.  //    // Get our return value.
924     Int_t nfiles = newTree->GetFileNumber() + 1;  //    Int_t nfiles = newTree->GetFileNumber() + 1;
925    
926     // Close and delete the current file of the new tree.  //    // Close and delete the current file of the new tree.
927     if (!opt.Contains("keep")) {  //    if (!opt.Contains("keep")) {
928        // FIXME: What happens to fDirectory in newTree here?  //       // FIXME: What happens to fDirectory in newTree here?
929        delete newTree->GetCurrentFile();  //       delete newTree->GetCurrentFile();
930     }  //    }
931     return nfiles;  //    return nfiles;
932  }  // }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.23