/[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.24 by mocchiut, Fri Oct 17 15:10:20 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);
450        Target->SetCompressionLevel(3);
451      //Target->SetCompressionLevel(5);      //Target->SetCompressionLevel(5);
452      //      //
453      fOpen = true;      fOpen = true;
# Line 472  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 497  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 531  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    Target->cd();    Target->cd();
600    li->WriteCloneTrees();    nli->WriteCloneTrees();
601    printf(" file %s \n",Target->GetName());    printf("Written file %s \n",Target->GetName());
602    //  Target->Write();    //  Target->Write();
603    TTree *slist = (TTree*)Target->Get("SelectionList");    //  TTree *slist = (TTree*)Target->Get("SelectionList");
604    slist->Delete("all");    //  slist->Delete("all");
605      if ( !nli->GetCloneTree("ProcessingInfo") ){
606        TChain *P = new TChain("ProcessingInfo");
607        // loop over files and create chains
608        TIter next(sourcelist);
609        TSystemFile *questo = 0;
610        while ((questo = (TSystemFile*) next())) {
611          TString name = questo->GetName();
612          P->Add(name);
613        }
614        if ( P->GetEntries() ){
615          TTree *Pclone = P->CloneTree();
616          //
617          ProcInfo *procinfo = new ProcInfo();
618          procinfo->runID = run;
619          TTimeStamp *dt = new TTimeStamp();
620          procinfo->date = dt->AsString();
621          delete dt;
622          TString isok;
623          if ( discarded ){
624            isok = " WARNING, files were discarded while merging! ";
625          } else {
626            isok = " The level2 merging was OK!";
627          }
628          procinfo->commandLine += Form("PadmeAmidala: %s",isok.Data());
629          procinfo->outputFilename = Target->GetName();
630          procinfo->localDir = gSystem->WorkingDirectory();
631          procinfo->uname = gSystem->GetFromPipe("uname -a");
632          procinfo->DB = Form("mysql://%s/%s",dbc->GetHost(),dbc->GetDB());
633          
634          Pclone->SetBranchAddress("ProcInfo",&procinfo);
635          Pclone->Fill();
636    
637          Target->cd();
638          Pclone->Write("ProcessingInfo",TObject::kOverwrite);
639          P->Delete();
640          P=0;
641        }
642      }
643      //  
644    Target->Close();    Target->Close();
645    
646  //   //  //   //
# Line 754  void RunGlue::MergeRootfile(TList *sourc Line 844  void RunGlue::MergeRootfile(TList *sourc
844  };  };
845    
846    
847  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){
848     // We must have been passed a file, we will use it  //    // We must have been passed a file, we will use it
849     // later to reset the compression level of the branches.  //    // later to reset the compression level of the branches.
850     if (!file) {  //    if (!file) {
851        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
852       printf(" 19 \n");  //      printf(" 19 \n");
853       return 0;  //      return 0;
854     }  //    }
855     printf(" 20 \n");  //    printf(" 20 \n");
856    
857     // Options  //    // Options
858     Bool_t fastClone = kFALSE;  //    Bool_t fastClone = kFALSE;
859     TString opt = option;  //    TString opt = option;
860     opt.ToLower();  //    opt.ToLower();
861     if (opt.Contains("fast")) {  //    if (opt.Contains("fast")) {
862        fastClone = kTRUE;  //       fastClone = kTRUE;
863        printf(" 21 \n");  //       printf(" 21 \n");
864     }  //    }
865     // The chain tree must have a list of branches  //    // The chain tree must have a list of branches
866     // because we may try to change their basket  //    // because we may try to change their basket
867     // size later.  //    // size later.
868     TObjArray* lbranches = mychain->GetListOfBranches();  //    TObjArray* lbranches = mychain->GetListOfBranches();
869     if (!lbranches) {  //    if (!lbranches) {
870        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
871       printf(" 22 \n");  //      printf(" 22 \n");
872        return 0;  //       return 0;
873     }  //    }
874    
875     //   file->cd();  //    //   file->cd();
876     // The chain must have a current tree because  //    // The chain must have a current tree because
877     // that is the one we will clone.  //    // that is the one we will clone.
878     //   if (!fTree) {  //    //   if (!fTree) {
879        // -- LoadTree() has not yet been called, no current tree.  //       // -- LoadTree() has not yet been called, no current tree.
880        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
881     //      return 0;  //    //      return 0;
882     //   }  //    //   }
883    
884     // Copy the chain's current tree without  //    // Copy the chain's current tree without
885     // copying any entries, we will do that later.  //    // copying any entries, we will do that later.
886     printf(" 23 \n");  //    printf(" 23 \n");
887     TTree* newTree = mychain->CloneTree(0);  //    TTree* newTree = mychain->CloneTree(0);
888     if (!newTree) {  //    if (!newTree) {
889        // FIXME: We need an error message here.  //       // FIXME: We need an error message here.
890       printf(" 24 \n");  //      printf(" 24 \n");
891        return 0;  //       return 0;
892     }  //    }
893     printf(" 25 \n");  //    printf(" 25 \n");
894    
895    
896     // Strip out the (potential) directory name.  //    // Strip out the (potential) directory name.
897     // FIXME: The merged chain may or may not have the  //    // FIXME: The merged chain may or may not have the
898     //        same name as the original chain.  This is  //    //        same name as the original chain.  This is
899     //        bad because the chain name determines the  //    //        bad because the chain name determines the
900     //        names of the trees in the chain by default.  //    //        names of the trees in the chain by default.
901     printf(" 26 \n");  //    printf(" 26 \n");
902     newTree->SetName(gSystem->BaseName(mychain->GetName()));  //    newTree->SetName(gSystem->BaseName(mychain->GetName()));
903     printf(" 27 \n");  //    printf(" 27 \n");
904    
905     // FIXME: Why do we do this?  //    // FIXME: Why do we do this?
906     //   newTree->SetAutoSave(-1);  //    //   newTree->SetAutoSave(-1);
907     newTree->SetAutoSave(900000000000000LL);  //    newTree->SetAutoSave(900000000000000LL);
908    
909     printf(" 28 \n");  //    printf(" 28 \n");
910     // Circularity is incompatible with merging, it may  //    // Circularity is incompatible with merging, it may
911     // force us to throw away entries, which is not what  //    // force us to throw away entries, which is not what
912     // we are supposed to do.  //    // we are supposed to do.
913     newTree->SetCircular(0);  //    newTree->SetCircular(0);
914    
915     // Reset the compression level of the branches.  //    // Reset the compression level of the branches.
916     if (opt.Contains("c")) {  //    if (opt.Contains("c")) {
917        TBranch* branch = 0;  //       TBranch* branch = 0;
918        TIter nextb(newTree->GetListOfBranches());  //       TIter nextb(newTree->GetListOfBranches());
919        while ((branch = (TBranch*) nextb())) {  //       while ((branch = (TBranch*) nextb())) {
920          printf(" 29 \n");  //      printf(" 29 \n");
921           branch->SetCompressionLevel(file->GetCompressionLevel());  //          branch->SetCompressionLevel(file->GetCompressionLevel());
922        }  //       }
923     }  //    }
924    
925     printf(" 30 \n");  //    printf(" 30 \n");
926     // Reset the basket size of the branches.  //    // Reset the basket size of the branches.
927     if (basketsize > 1000) {  //    if (basketsize > 1000) {
928        TBranch* branch = 0;  //       TBranch* branch = 0;
929        TIter nextb(newTree->GetListOfBranches());  //       TIter nextb(newTree->GetListOfBranches());
930        while ((branch = (TBranch*) nextb())) {  //       while ((branch = (TBranch*) nextb())) {
931          printf(" 31 \n");  //      printf(" 31 \n");
932           branch->SetBasketSize(basketsize);  //          branch->SetBasketSize(basketsize);
933        }  //       }
934     }  //    }
935    
936     printf(" 32 \n");  //    printf(" 32 \n");
937     Long64_t nentries = mychain->GetEntriesFast();  //    Long64_t nentries = mychain->GetEntriesFast();
938     //Long64_t nentries = mychain->GetEntries();  //    //Long64_t nentries = mychain->GetEntries();
939    
940     // Copy the entries.  //    // Copy the entries.
941     if (fastClone) {  //    if (fastClone) {
942        // For each tree in the chain.  //       // For each tree in the chain.
943        for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {  //       for (Long64_t i = 0; i < nentries; i += mychain->GetTree()->GetEntries()) {
944           if (mychain->LoadTree(i) < 0) {  //          if (mychain->LoadTree(i) < 0) {
945              break;  //             break;
946           }  //          }
947           TTreeCloner cloner(mychain->GetTree(), newTree, option);  //          TTreeCloner cloner(mychain->GetTree(), newTree, option);
948           if (cloner.IsValid()) {  //          if (cloner.IsValid()) {
949              newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());  //             newTree->SetEntries(newTree->GetEntries() + mychain->GetTree()->GetEntries());
950              cloner.Exec();  //             cloner.Exec();
951           } else {  //          } else {
952              if (mychain->GetFile()) {  //             if (mychain->GetFile()) {
953                printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());  //            printf("Merge Skipped file %s\n", mychain->GetFile()->GetName());
954                 //            } else {  //             //            } else {
955                 //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);  //             //               Warning("Merge", "Skipped file number %d\n", fTreeNumber);
956              }  //             }
957           }  //          }
958        }  //       }
959     } else {  //    } else {
960       printf(" 33 %llu \n",nentries);  //      printf(" 33 %llu \n",nentries);
961       mychain->Print();  //      mychain->Print();
962       for (Long64_t i = 0; i < nentries; i++) {  //      for (Long64_t i = 0; i < nentries; i++) {
963         printf(" i %llu \n",i);  //        printf(" i %llu \n",i);
964         // for (Long64_t i = 0; i < 1; i++) {  //        // for (Long64_t i = 0; i < 1; i++) {
965           if (mychain->GetEntry(i) <= 0) {  //          if (mychain->GetEntry(i) <= 0) {
966              break;  //             break;
967           }  //          }
968           newTree->Fill();  //          newTree->Fill();
969        }  //       }
970        printf(" 34 \n");  //       printf(" 34 \n");
971     }  //    }
972    
973     // Write the new tree header.  //    // Write the new tree header.
974     printf(" 35 \n");  //    printf(" 35 \n");
975     newTree->Write();  //    newTree->Write();
976    
977     printf(" 36 \n");  //    printf(" 36 \n");
978     // Get our return value.  //    // Get our return value.
979     Int_t nfiles = newTree->GetFileNumber() + 1;  //    Int_t nfiles = newTree->GetFileNumber() + 1;
980    
981     // Close and delete the current file of the new tree.  //    // Close and delete the current file of the new tree.
982     if (!opt.Contains("keep")) {  //    if (!opt.Contains("keep")) {
983        // FIXME: What happens to fDirectory in newTree here?  //       // FIXME: What happens to fDirectory in newTree here?
984        delete newTree->GetCurrentFile();  //       delete newTree->GetCurrentFile();
985     }  //    }
986     return nfiles;  //    return nfiles;
987  }  // }

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

  ViewVC Help
Powered by ViewVC 1.1.23