/[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.13 by mocchiut, Thu Dec 11 10:41:11 2008 UTC revision 1.25 by mocchiut, Fri Oct 17 15:58:41 2014 UTC
# Line 31  RunGlue::RunGlue(TSQLServer *da, UInt_t Line 31  RunGlue::RunGlue(TSQLServer *da, UInt_t
31    run = ru;    run = ru;
32    dir = di;    dir = di;
33    //    //
34      discarded = false;
35      //
36    wd = gSystem->WorkingDirectory();      wd = gSystem->WorkingDirectory();  
37    //    //
38    outdir = wrkdi;    outdir = wrkdi;
# Line 42  RunGlue::RunGlue(TSQLServer *da, UInt_t Line 44  RunGlue::RunGlue(TSQLServer *da, UInt_t
44      runmode = false;      runmode = false;
45      createlist = true;      createlist = true;
46    };    };
47      fUpgrade = true;
48    //    //
49    //  lList = new TList();    //  lList = new TList();
50    //    //
# Line 114  TList *RunGlue::GetRunList(){ Line 117  TList *RunGlue::GetRunList(){
117      TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);      TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);
118      //      //
119      UInt_t lowerlimit = llim->GetSec();      UInt_t lowerlimit = llim->GetSec();
120      UInt_t upperlimit = lowerlimit + 86401;      UInt_t upperlimit = lowerlimit + 86400;
121      //      //
122      if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);      if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);
123      //      //
# Line 173  TList *RunGlue::GetRunList(){ Line 176  TList *RunGlue::GetRunList(){
176        if ( li->CheckLevel2File(thisrun) ){        if ( li->CheckLevel2File(thisrun) ){
177          lList->Add(su);          lList->Add(su);
178        } else {        } else {
179                  if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));          if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));
180            discarded = true;
181        };        };
182        //        //
183      };      };
# Line 218  TList *RunGlue::GetRunList(){ Line 222  TList *RunGlue::GetRunList(){
222              fNlist++;              fNlist++;
223            } else {            } else {
224              if ( DebugMode() ) printf(" RUN %s DISCARDED \n",fullpath.Data());              if ( DebugMode() ) printf(" RUN %s DISCARDED \n",fullpath.Data());
225                discarded = true;
226            };            };
227            //            //
228          };          };
# Line 281  TList *RunGlue::GetRunList(){ Line 286  TList *RunGlue::GetRunList(){
286      TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);      TTimeStamp *llim = new TTimeStamp(YY,MM,DD,0,0,0,0,true,0);
287      //      //
288      UInt_t lowerlimit = llim->GetSec();      UInt_t lowerlimit = llim->GetSec();
289      UInt_t upperlimit = lowerlimit + 86401;      UInt_t upperlimit = lowerlimit + 86400;
290      //      //
291      if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);      if ( DebugMode() ) printf(" YY %u MM %u DD %u ll %u ul %u \n",YY,MM,DD,lowerlimit,upperlimit);
292      //      //
# Line 344  TList *RunGlue::GetRunList(){ Line 349  TList *RunGlue::GetRunList(){
349          if ( DebugMode() ) printf(" RUN %s ADDED \n",Row->GetField(0));          if ( DebugMode() ) printf(" RUN %s ADDED \n",Row->GetField(0));
350        } else {        } else {
351          if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));          if ( DebugMode() ) printf(" RUN %s DISCARDED \n",Row->GetField(0));
352            discarded = true;
353        };        };
354        //        //
355      };      };
# Line 394  Bool_t RunGlue::OpenFile(){ Line 400  Bool_t RunGlue::OpenFile(){
400      return(false);      return(false);
401    } else {    } else {
402      //      //
403        // try to lock tables and work on a db level to avoid multiple file simultaneous access
404        //
405        stringstream oss;
406        //  
407        if ( fUpgrade ){
408          oss.str("");
409          oss << "lock table GL_ROOT write;";
410          TSQLResult *result = 0;
411          TSQLRow *row = 0;
412          result = dbc->Query(oss.str().c_str());
413          oss.str("");
414          oss << "select ID from GL_ROOT where NAME='" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "';";
415          result = dbc->Query(oss.str().c_str());
416          row = result->Next();
417          if ( row ){
418            printf("Error opening target file (does %s exist? already in the DB? are the permissions ok?)\n",(this->GetFilename()).Data());
419            return(false);
420          } else {
421            oss.str("");
422            oss << "insert into GL_ROOT (PATH,NAME) values ('$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";      
423            result = dbc->Query(oss.str().c_str());
424          };
425          oss.str("");
426          oss << "unlock tables;";
427          result = dbc->Query(oss.str().c_str());
428        };
429        //    Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );
430        Target = TFile::Open((this->GetFilename()).Data(), "NEW" );    
431        //    
432      printf(" Output file does not exist, creating it\n");      printf(" Output file does not exist, creating it\n");
433      //      //
434      Long64_t maxsize = 99900000000LL;        Long64_t maxsize = 99900000000LL;  
435      //      //
436      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );      if ( !Target || Target->IsZombie()) {
437          printf("Error opening target file (does %s exist? are the permissions ok?)\n",(this->GetFilename()).Data());
438          //      exit(1);
439          return(false);
440        }
441        //
442        Target->Write();
443        //
444      //fastMethod = kTRUE;      //fastMethod = kTRUE;
445      fastMethod = kFALSE;      fastMethod = kFALSE;
446      //          //    
     //      
     if ( !Target || Target->IsZombie()) {  
       printf("Error opening target file (does %s exist?)\n",(this->GetFilename()).Data());  
       exit(1);  
     }  
447      //      //
448      TTree::SetMaxTreeSize(maxsize);      TTree::SetMaxTreeSize(maxsize);
449      //    Target->SetCompressionLevel(2);      //    Target->SetCompressionLevel(2);
# Line 473  void RunGlue::UpdateDB(TList *dlist){ Line 510  void RunGlue::UpdateDB(TList *dlist){
510    };    };
511    //    //
512    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("");  
513    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() << "';";
514    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
515    //    //
# Line 498  void RunGlue::UpdateDB(TList *dlist){ Line 525  void RunGlue::UpdateDB(TList *dlist){
525    } else {    } else {
526      idl2 = (UInt_t)atoll(Row->GetField(0));      idl2 = (UInt_t)atoll(Row->GetField(0));
527    };    };
528      myquery.str("");
529      //  myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
530      //  myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
531      myquery << "update GL_ROOT set ID_RAW=" << idr << " where ID=" << idl2 << ";";
532      if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
533      //
534      pResult = dbc->Query(myquery.str().c_str());
535      if ( !pResult ){
536        printf(" ERROR WRITING ON DB!\n");
537        return;
538      };
539    //    //
540    //    //
541    //    //
# Line 532  void RunGlue::MergeRootfile(TList *sourc Line 570  void RunGlue::MergeRootfile(TList *sourc
570    //    //
571    merged = true;    merged = true;
572    //    //
573    if ( li ) li->Delete();    //  if ( li ) li->Delete();
574    li = new PamLevel2(wd,sourcelist,fDList);    PamLevel2 *nli = new PamLevel2(wd,sourcelist,fDList);
575      nli->SetSELLI(2);
576    //    //
577    Target->cd();    Target->cd();
578    //    //
579    li->CreateCloneTrees(Target);    nli->CreateCloneTrees(Target);
580    ULong64_t nevents = li->GetEntries();    //
581      /*  nli->GetCloneTree("Tracker")->SetAutoSave(900000000000000LL);
582      nli->GetCloneTree("Trigger")->SetAutoSave(900000000000000LL);
583      nli->GetCloneTree("Calorimeter")->SetAutoSave(900000000000000LL);
584      nli->GetCloneTree("S4")->SetAutoSave(900000000000000LL);
585      nli->GetCloneTree("Anticounter")->SetAutoSave(900000000000000LL);
586      nli->GetCloneTree("NeutronD")->SetAutoSave(900000000000000LL);
587      nli->GetCloneTree("OrbitalInfo")->SetAutoSave(900000000000000LL);
588      nli->GetCloneTree("Run")->SetAutoSave(900000000000000LL);
589      nli->GetCloneTree("ToF")->SetAutoSave(900000000000000LL);*/
590      //
591      ULong64_t nevents = nli->GetEntries();        
592    printf(" NEVENTS %llu \n",nevents);    printf(" NEVENTS %llu \n",nevents);
593    for(ULong64_t iev=0; iev<nevents; iev++){    for(ULong64_t iev=0; iev<nevents; iev++){
594      li->Clear();      nli->Clear();
595      if( li->GetEntry(iev) ){      if( nli->GetEntry(iev) ){
596        li->FillCloneTrees();        nli->FillCloneTrees();
597      };      };
598    };    };
599      //
600      TTree *P = nli->GetCloneTree("ProcessingInfo");
601      ProcInfo *procinfo = 0;
602      if ( P ){
603        procinfo = nli->GetProcInfo();
604      } else {
605        procinfo = new ProcInfo();    
606      }
607      procinfo->runID = run;
608      TTimeStamp *dt = new TTimeStamp();
609      procinfo->date = dt->AsString();
610      delete dt;
611      TString isok;
612      if ( discarded ){
613        isok = " WARNING, files were discarded while merging! ";
614      } else {
615        isok = " The level2 merging was OK!";
616      }
617      procinfo->commandLine = Form("PadmeAmidala: %s",isok.Data());
618      procinfo->outputFilename = Target->GetName();
619      procinfo->localDir = gSystem->WorkingDirectory();
620      procinfo->uname = gSystem->GetFromPipe("uname -a");
621      procinfo->DB = Form("mysql://%s/%s",dbc->GetHost(),dbc->GetDB());
622      if ( P ) P->Fill();
623      //
624    Target->cd();    Target->cd();
625    li->WriteCloneTrees();    nli->WriteCloneTrees();
626    printf("Written file %s \n",Target->GetName());    printf("Written file %s \n",Target->GetName());
627    //  Target->Write();    //  Target->Write();
628    TTree *slist = (TTree*)Target->Get("SelectionList");    //  TTree *slist = (TTree*)Target->Get("SelectionList");
629    slist->Delete("all");    //  slist->Delete("all");
630      if ( !P ){
631        TChain *PC = new TChain("ProcessingInfo");
632        // loop over files and create chains
633        TIter next(sourcelist);
634        TSystemFile *questo = 0;
635        while ((questo = (TSystemFile*) next())) {
636          TString name = questo->GetName();
637          PC->Add(name);
638        }
639        if ( P->GetEntries() ){
640          TTree *Pclone = PC->CloneTree();
641          //
642          
643          Pclone->SetBranchAddress("ProcInfo",&procinfo);
644          Pclone->Fill();
645          
646          Target->cd();
647          Pclone->Write("ProcessingInfo",TObject::kOverwrite);
648          PC->Delete();
649          PC=0;
650        }
651      }
652      //  
653    Target->Close();    Target->Close();
654    
655  //   //  //   //
# Line 755  void RunGlue::MergeRootfile(TList *sourc Line 853  void RunGlue::MergeRootfile(TList *sourc
853  };  };
854    
855    
856  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){
857     // We must have been passed a file, we will use it  //    // We must have been passed a file, we will use it
858     // later to reset the compression level of the branches.  //    // later to reset the compression level of the branches.
859     if (!file) {  //    if (!file) {
860        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
861       printf(" 19 \n");  //      printf(" 19 \n");
862       return 0;  //      return 0;
863     }  //    }
864     printf(" 20 \n");  //    printf(" 20 \n");
865    
866     // Options  //    // Options
867     Bool_t fastClone = kFALSE;  //    Bool_t fastClone = kFALSE;
868     TString opt = option;  //    TString opt = option;
869     opt.ToLower();  //    opt.ToLower();
870     if (opt.Contains("fast")) {  //    if (opt.Contains("fast")) {
871        fastClone = kTRUE;  //       fastClone = kTRUE;
872        printf(" 21 \n");  //       printf(" 21 \n");
873     }  //    }
874     // The chain tree must have a list of branches  //    // The chain tree must have a list of branches
875     // because we may try to change their basket  //    // because we may try to change their basket
876     // size later.  //    // size later.
877     TObjArray* lbranches = mychain->GetListOfBranches();  //    TObjArray* lbranches = mychain->GetListOfBranches();
878     if (!lbranches) {  //    if (!lbranches) {
879        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
880       printf(" 22 \n");  //      printf(" 22 \n");
881        return 0;  //       return 0;
882     }  //    }
883    
884     //   file->cd();  //    //   file->cd();
885     // The chain must have a current tree because  //    // The chain must have a current tree because
886     // that is the one we will clone.  //    // that is the one we will clone.
887     //   if (!fTree) {  //    //   if (!fTree) {
888        // -- LoadTree() has not yet been called, no current tree.  //       // -- LoadTree() has not yet been called, no current tree.
889        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
890     //      return 0;  //    //      return 0;
891     //   }  //    //   }
892    
893     // Copy the chain's current tree without  //    // Copy the chain's current tree without
894     // copying any entries, we will do that later.  //    // copying any entries, we will do that later.
895     printf(" 23 \n");  //    printf(" 23 \n");
896     TTree* newTree = mychain->CloneTree(0);  //    TTree* newTree = mychain->CloneTree(0);
897     if (!newTree) {  //    if (!newTree) {
898        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
899       printf(" 24 \n");  //      printf(" 24 \n");
900        return 0;  //       return 0;
901     }  //    }
902     printf(" 25 \n");  //    printf(" 25 \n");
903    
904    
905     // Strip out the (potential) directory name.  //    // Strip out the (potential) directory name.
906     // FIXME: The merged chain may or may not have the  //    // FIXME: The merged chain may or may not have the
907     //        same name as the original chain.  This is  //    //        same name as the original chain.  This is
908     //        bad because the chain name determines the  //    //        bad because the chain name determines the
909     //        names of the trees in the chain by default.  //    //        names of the trees in the chain by default.
910     printf(" 26 \n");  //    printf(" 26 \n");
911     newTree->SetName(gSystem->BaseName(mychain->GetName()));  //    newTree->SetName(gSystem->BaseName(mychain->GetName()));
912     printf(" 27 \n");  //    printf(" 27 \n");
913    
914     // FIXME: Why do we do this?  //    // FIXME: Why do we do this?
915     //   newTree->SetAutoSave(-1);  //    //   newTree->SetAutoSave(-1);
916     newTree->SetAutoSave(900000000000000LL);  //    newTree->SetAutoSave(900000000000000LL);
917    
918     printf(" 28 \n");  //    printf(" 28 \n");
919     // Circularity is incompatible with merging, it may  //    // Circularity is incompatible with merging, it may
920     // force us to throw away entries, which is not what  //    // force us to throw away entries, which is not what
921     // we are supposed to do.  //    // we are supposed to do.
922     newTree->SetCircular(0);  //    newTree->SetCircular(0);
923    
924     // Reset the compression level of the branches.  //    // Reset the compression level of the branches.
925     if (opt.Contains("c")) {  //    if (opt.Contains("c")) {
926        TBranch* branch = 0;  //       TBranch* branch = 0;
927        TIter nextb(newTree->GetListOfBranches());  //       TIter nextb(newTree->GetListOfBranches());
928        while ((branch = (TBranch*) nextb())) {  //       while ((branch = (TBranch*) nextb())) {
929          printf(" 29 \n");  //      printf(" 29 \n");
930           branch->SetCompressionLevel(file->GetCompressionLevel());  //          branch->SetCompressionLevel(file->GetCompressionLevel());
931        }  //       }
932     }  //    }
933    
934     printf(" 30 \n");  //    printf(" 30 \n");
935     // Reset the basket size of the branches.  //    // Reset the basket size of the branches.
936     if (basketsize > 1000) {  //    if (basketsize > 1000) {
937        TBranch* branch = 0;  //       TBranch* branch = 0;
938        TIter nextb(newTree->GetListOfBranches());  //       TIter nextb(newTree->GetListOfBranches());
939        while ((branch = (TBranch*) nextb())) {  //       while ((branch = (TBranch*) nextb())) {
940          printf(" 31 \n");  //      printf(" 31 \n");
941           branch->SetBasketSize(basketsize);  //          branch->SetBasketSize(basketsize);
942        }  //       }
943     }  //    }
944    
945     printf(" 32 \n");  //    printf(" 32 \n");
946     Long64_t nentries = mychain->GetEntriesFast();  //    Long64_t nentries = mychain->GetEntriesFast();
947     //Long64_t nentries = mychain->GetEntries();  //    //Long64_t nentries = mychain->GetEntries();
948    
949     // Copy the entries.  //    // Copy the entries.
950     if (fastClone) {  //    if (fastClone) {
951        // For each tree in the chain.  //       // For each tree in the chain.
952        for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {  //       for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
953           if (mychain->LoadTree(i) < 0) {  //          if (mychain->LoadTree(i) < 0) {
954              break;  //             break;
955           }  //          }
956           TTreeCloner cloner(mychain->GetTree(), newTree, option);  //          TTreeCloner cloner(mychain->GetTree(), newTree, option);
957           if (cloner.IsValid()) {  //          if (cloner.IsValid()) {
958              newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());  //             newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
959              cloner.Exec();  //             cloner.Exec();
960           } else {  //          } else {
961              if (mychain->GetFile()) {  //             if (mychain->GetFile()) {
962                printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());  //            printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
963                 //            } else {  //             //            } else {
964                 //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);  //             //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
965              }  //             }
966           }  //          }
967        }  //       }
968     } else {  //    } else {
969       printf(" 33 %llu \n",nentries);  //      printf(" 33 %llu \n",nentries);
970       mychain->Print();  //      mychain->Print();
971       for (Long64_t i = 0; i < nentries; i++) {  //      for (Long64_t i = 0; i < nentries; i++) {
972         printf(" i %llu \n",i);  //        printf(" i %llu \n",i);
973         // for (Long64_t i = 0; i < 1; i++) {  //        // for (Long64_t i = 0; i < 1; i++) {
974           if (mychain->GetEntry(i) <= 0) {  //          if (mychain->GetEntry(i) <= 0) {
975              break;  //             break;
976           }  //          }
977           newTree->Fill();  //          newTree->Fill();
978        }  //       }
979        printf(" 34 \n");  //       printf(" 34 \n");
980     }  //    }
981    
982     // Write the new tree header.  //    // Write the new tree header.
983     printf(" 35 \n");  //    printf(" 35 \n");
984     newTree->Write();  //    newTree->Write();
985    
986     printf(" 36 \n");  //    printf(" 36 \n");
987     // Get our return value.  //    // Get our return value.
988     Int_t nfiles = newTree->GetFileNumber() + 1;  //    Int_t nfiles = newTree->GetFileNumber() + 1;
989    
990     // Close and delete the current file of the new tree.  //    // Close and delete the current file of the new tree.
991     if (!opt.Contains("keep")) {  //    if (!opt.Contains("keep")) {
992        // FIXME: What happens to fDirectory in newTree here?  //       // FIXME: What happens to fDirectory in newTree here?
993        delete newTree->GetCurrentFile();  //       delete newTree->GetCurrentFile();
994     }  //    }
995     return nfiles;  //    return nfiles;
996  }  // }

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

  ViewVC Help
Powered by ViewVC 1.1.23