/[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.15 by mocchiut, Fri Jan 30 09:37:18 2009 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" );      //    Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );
430      Target = TFile::Open((this->GetFilename()).Data(), "NEW" );          Target = TFile::Open((this->GetFilename()).Data(), "NEW" );    
431      //          //    
# Line 478  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 503  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 537  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    li->SetSELLI(2);    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("Written 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  //   //  //   //

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

  ViewVC Help
Powered by ViewVC 1.1.23