/[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.6 by mocchiut, Wed Jan 24 16:24:51 2007 UTC revision 1.10 by mocchiut, Fri Sep 7 13:26:11 2007 UTC
# Line 5  Line 5 
5   * The file contains implementation of the methods to query the DB.   * The file contains implementation of the methods to query the DB.
6   */   */
7  //  //
 #include <sstream>  
 #include <iostream>  
 //  
 #include <TFile.h>  
 #include <TTree.h>  
 #include <TTimeStamp.h>  
 #include <TTreeCloner.h>  
8  #include <RunGlue.h>  #include <RunGlue.h>
9  //  //
10  ClassImp(RunGlue);  ClassImp(RunGlue);
# Line 22  RunGlue::RunGlue() { Line 15  RunGlue::RunGlue() {
15    this->Clear();    this->Clear();
16  }  }
17    
18  RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi) {  RunGlue::RunGlue(TSQLServer *da, UInt_t ru, TString di, TString wrkdi, Bool_t fcas) {
19    fDBG = false;    fDBG = false;
20      castor = fcas;
21    li = new PamLevel2();    li = new PamLevel2();
22    this->Clear();    this->Clear();
23    dbc = da;    dbc = da;
# Line 86  TList *RunGlue::GetRunList(){ Line 80  TList *RunGlue::GetRunList(){
80    lList = new TList();    lList = new TList();
81    lList->Clear();    lList->Clear();
82    TString thisrun;    TString thisrun;
83      //  TFile *su;
84    TFile *su;    TFile *su;
85    //    //
86    TSQLResult *pResult;    TSQLResult *pResult;
# Line 169  TList *RunGlue::GetRunList(){ Line 164  TList *RunGlue::GetRunList(){
164        //        //
165        if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());        if ( DebugMode() ) printf(" Filename is %s \n",thisrun.Data());
166        //        //
167          //su = TFile::Open(thisrun);
168        su = TFile::Open(thisrun);        su = TFile::Open(thisrun);
169        if ( li->CheckLevel2File(thisrun) ){        if ( li->CheckLevel2File(thisrun) ){
170          lList->Add(su);          lList->Add(su);
# Line 212  TList *RunGlue::GetRunList(){ Line 208  TList *RunGlue::GetRunList(){
208            if ( DebugMode() ) printf(" fullpath = %s     name %s \n",fullpath.Data(),name.Data());            if ( DebugMode() ) printf(" fullpath = %s     name %s \n",fullpath.Data(),name.Data());
209            //            //
210            //            //
211              //su = TFile::Open(fullpath);
212            su = TFile::Open(fullpath);            su = TFile::Open(fullpath);
213            if ( li->CheckLevel2File((TString)fullpath) ){            if ( li->CheckLevel2File((TString)fullpath) ){
214              fList->Add(su);              fList->Add(su);
# Line 335  TList *RunGlue::GetRunList(){ Line 332  TList *RunGlue::GetRunList(){
332        //        //
333        su = TFile::Open(thisrun);        su = TFile::Open(thisrun);
334        if ( su ){        if ( su ){
335            //      TFile *su0 = TFile::Open(thisrun);
336          TFile *su0 = TFile::Open(thisrun);          TFile *su0 = TFile::Open(thisrun);
337          fDoneList->Add(su0);          fDoneList->Add(su0);
338          fNlistdone++;          fNlistdone++;
# Line 380  TList *RunGlue::GetRunList(){ Line 378  TList *RunGlue::GetRunList(){
378    
379  Bool_t RunGlue::OpenFile(){  Bool_t RunGlue::OpenFile(){
380    //    //
381    fOpen = false;    ifstream myfile;
382    printf(" Check if output file already exists \n");    TString thename;
   Target = TFile::Open((this->GetFilename()).Data(), "READ" );  
383    //    //
384    if ( Target ){    Bool_t exi = false;
385      Target->Close();    fOpen = false;
386      printf("Error opening target file, %s  already exist!\n",(this->GetFilename()).Data());    thename = Form("rfio://%s",(this->GetFilename()).Data());
387      Target = 0;
388      if ( castor ){
389        Target = new TRFIOFile(thename.Data(),"READ","",1);
390        if ( !Target->IsZombie()) exi = true;
391      } else {
392        //    thename = Form("rfio://%s",(this->GetFilename()).Data());
393        printf(" Check if output file already exists \n");
394        myfile.open((this->GetFilename()).Data());
395        if ( myfile ) exi = true;
396      };
397      if ( exi ){
398        //  Target = TFile::Open((this->GetFilename()).Data(), "READ" );
399        //
400        //  if ( Target ){
401        //    Target->Close();
402        if ( myfile ) myfile.close();
403        //
404        if ( Target ) Target->Close();
405        //
406        printf("Error opening target file, %s  already exist!\n",thename.Data());
407      return(false);      return(false);
408        //
409    } else {    } else {
410      //      //
411      printf(" Output file does not exist, creating it\n");      printf(" Output file does not exist, creating it\n");
412      //      //
413      Long64_t maxsize = 99900000000LL;        Long64_t maxsize = 99900000000LL;  
414      //      //
415      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );      Target = new TRFIOFile(thename.Data(), "RECREATE", "", 2 );
416        //      Target = TFile::Open((this->GetFilename()).Data(), "RECREATE" );
417        //
418      //fastMethod = kTRUE;      //fastMethod = kTRUE;
419      fastMethod = kFALSE;      fastMethod = kFALSE;
420      //          //    
421      //          //    
422      if ( !Target || Target->IsZombie()) {      if ( !Target || Target->IsZombie()) {
423        printf("Error opening target file (does %s exist?)\n",(this->GetFilename()).Data());        printf("Error opening target file (does %s exist?)\n",thename.Data());
424        exit(1);        exit(1);
425      }      }
426      //      //
# Line 467  void RunGlue::UpdateDB(TList *dlist){ Line 487  void RunGlue::UpdateDB(TList *dlist){
487    };    };
488    //    //
489    myquery.str("");    myquery.str("");
490    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 << ",'" << outdir.Data() << "','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
491      myquery << "insert into GL_ROOT (ID_RAW,PATH,NAME) values (" << idr << ",'$PAM_L2','" << ((TString)gSystem->BaseName(this->GetFilename())).Data() << "');";
492    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());    if ( DebugMode() ) printf(" query is %s \n",myquery.str().c_str());
493    //    //
494    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
# Line 529  void RunGlue::MergeRootfile(TList *sourc Line 550  void RunGlue::MergeRootfile(TList *sourc
550    //    //
551    if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());    if ( DebugMode() ) printf("\nTarget path is: %s \n",target->GetPath());
552    //    //
553    TString path( (char*)strstr( target->GetPath(), ":" ) );    TString path;
554      //if ( castor ){
555        path = TString(":/");
556        //  } else {
557        //    path = TString( (char*)strstr( target->GetPath(), ":" ) );
558        //  };
559    path.Remove(0,2);    path.Remove(0,2);
560      if ( DebugMode() ) printf("path is %s \n",path.Data());
561    //    //
562    TDirectory *first_source = (TDirectory*)sourcelist->First();    TDirectory *first_source = (TDirectory*)sourcelist->First();
563    THashList allNames;    THashList allNames;
# Line 567  void RunGlue::MergeRootfile(TList *sourc Line 594  void RunGlue::MergeRootfile(TList *sourc
594        //        //
595        //        //
596        //        //
597        if ( !strcmp(key->GetName(),"Tracker") && !li->TRK2 && !li->TRK1 && !li->TRKh ) continue;        if ( !strcmp(key->GetName(),"Tracker") && !li->IsTRK2() && !li->IsTRK1() && !li->IsTRKh() ) continue;
598        //        //
599        if ( !strcmp(key->GetName(),"Calorimeter") && !li->CAL2 && !li->CAL1 ) continue;        if ( !strcmp(key->GetName(),"Calorimeter") && !li->IsCAL2() && !li->IsCAL1() ) continue;
600        //        //
601        if ( !strcmp(key->GetName(),"ToF") && !li->TOF ) continue;        if ( !strcmp(key->GetName(),"ToF") && !li->IsTOF() ) continue;
602        //        //
603        if ( !strcmp(key->GetName(),"Trigger") && !li->TRG ) continue;        if ( !strcmp(key->GetName(),"Trigger") && !li->IsTRG() ) continue;
604        //        //
605        if ( !strcmp(key->GetName(),"Anticounter") && !li->AC ) continue;        if ( !strcmp(key->GetName(),"Anticounter") && !li->IsAC() ) continue;
606        //        //
607        if ( !strcmp(key->GetName(),"S4") && !li->S4 ) continue;        if ( !strcmp(key->GetName(),"S4") && !li->IsS4() ) continue;
608        //        //
609        if ( !strcmp(key->GetName(),"NeutronD") && !li->ND ) continue;        if ( !strcmp(key->GetName(),"NeutronD") && !li->IsND() ) continue;
610        //        //
611        if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->ORB ) continue;        if ( !strcmp(key->GetName(),"OrbitalInfo") && !li->IsORB() ) continue;
612        //        //
613        if ( !strcmp(key->GetName(),"Run") && !RUN ) continue;        if ( !strcmp(key->GetName(),"Run") && !li->IsRUN() ) continue;
614        //        //
615        if ( strcmp(key->GetName(),"Calorimeter") && strcmp(key->GetName(),"Tracker") && strcmp(key->GetName(),"ToF") && strcmp(key->GetName(),"Trigger") && strcmp(key->GetName(),"Anticounter") && strcmp(key->GetName(),"S4") && strcmp(key->GetName(),"NeutronD") && strcmp(key->GetName(),"OrbitalInfo") && strcmp(key->GetName(),"Run") && strcmp(key->GetName(),"ProcessID0") ){        if ( strcmp(key->GetName(),"Calorimeter") && strcmp(key->GetName(),"Tracker") && strcmp(key->GetName(),"ToF") && strcmp(key->GetName(),"Trigger") && strcmp(key->GetName(),"Anticounter") && strcmp(key->GetName(),"S4") && strcmp(key->GetName(),"NeutronD") && strcmp(key->GetName(),"OrbitalInfo") && strcmp(key->GetName(),"Run") && strcmp(key->GetName(),"ProcessID0") ){
616          if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());          if ( DebugMode() ) printf(" ERROR UNKNOWN KEY %s !\n",key->GetName());
# Line 615  void RunGlue::MergeRootfile(TList *sourc Line 642  void RunGlue::MergeRootfile(TList *sourc
642          //          //
643          globChain->Add(first_source->GetName());          globChain->Add(first_source->GetName());
644          //          //
645            //      TFile *nextsource = (TFile*)sourcelist->After( first_source );
646          TFile *nextsource = (TFile*)sourcelist->After( first_source );          TFile *nextsource = (TFile*)sourcelist->After( first_source );
647          //          //
648          while ( nextsource ) {                      while ( nextsource ) {            
# Line 622  void RunGlue::MergeRootfile(TList *sourc Line 650  void RunGlue::MergeRootfile(TList *sourc
650            //do not add to the list a file that does not contain this Tree            //do not add to the list a file that does not contain this Tree
651            //            //
652            TFile *curf = TFile::Open(nextsource->GetName());            TFile *curf = TFile::Open(nextsource->GetName());
653              //      TFile *curf = TFile::Open(nextsource->GetName());
654            //            //
655            if ( curf ) {            if ( curf ) {
656              //              //
# Line 711  void RunGlue::MergeRootfile(TList *sourc Line 740  void RunGlue::MergeRootfile(TList *sourc
740  };  };
741    
742    
743    //Long64_t RunGlue::Mergy(TChain *mychain, TFile* file, Int_t basketsize, Option_t* option){
744  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){
745     // We must have been passed a file, we will use it     // We must have been passed a file, we will use it
746     // later to reset the compression level of the branches.     // later to reset the compression level of the branches.

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.23