Changeset 6691 for trunk/MagicSoft/Mars/mtemp/mucm/classes/MDataSetIter.cc
- Timestamp:
- 03/01/05 19:08:59 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mtemp/mucm/classes/MDataSetIter.cc
r4693 r6691 62 62 63 63 #include "MRunIter.h" 64 #include "MSequence.h" 64 65 65 66 #include "TObjArray.h" 66 67 67 68 #include <TSystem.h> 68 69 #include <fstream> 69 70 70 71 ClassImp(MDataSetIter); … … 79 80 // 80 81 MDataSetIter::MDataSetIter() 81 : fLastProcessedRun(0), fLog(&gLog), fDefCalRun(0)82 : fInitialRun(-1), fEndRun(-1), fLastProcessedDataRun(0), fLastDataRun(0), fDefCalRun(0), fDefCalRunPath(""), fLog(&gLog) 82 83 { 83 84 fPedRuns = new MRunIter; 84 85 fCalRuns = new MRunIter; 85 86 fDataRuns = new MRunIter; 86 } 87 87 fSequence = new MSequence; 88 } 89 90 91 // --------------------------------------------------------------------------- 92 // 93 // Add all the files inside a given directory to the fFileList. 94 // 95 void MDataSetIter::AddToFileList(MDirIter& dir) 96 { 97 TString name; 98 99 while (!(name=dir.Next()).IsNull()) 100 fFileList.Add((TObject*)(new TNamed((const char*)name, ""))); 101 102 103 // 104 // Sort File List by name 105 // 106 fFileList.Sort(); 107 108 // 109 // Find last Data runnumber of the filelist to be processed 110 // 111 FindLastDataRun(); 112 } 113 114 115 // ------------------------------------------------------------------------- 116 // 117 // Find last Data runnumber of the filelist to be processed 118 // 119 void MDataSetIter::FindLastDataRun() 120 { 121 122 if(fFileList.GetLast()==-1) 123 return; 124 125 126 TIter next(&fFileList,kIterBackward); 127 TNamed* n; 128 129 while ( (n=(TNamed*)next()) ) 130 { 131 TString name, path, date, src; 132 Int_t run; 133 char type; 134 135 ScanFileName(n->GetName(), name, path, date, src, &run, &type); 136 137 if(type!='D') 138 continue; 139 140 141 if(fEndRun==-1) 142 { 143 if(run>fLastDataRun) 144 fLastDataRun = run; 145 146 break; 147 } 148 else 149 { 150 if(run<=fEndRun) 151 { 152 if(run>fLastDataRun) 153 fLastDataRun = run; 154 155 break; 156 } 157 158 } 159 } 160 161 } 162 163 164 // ---------------------------------------------------------------------------- 165 // 166 // Overload MDirIter::AddDirectory 167 // 168 // Each time a new directory is added, all the files inside that directory 169 // are added to the fFileList. 170 // 171 // Returns the number of directories added 172 // 173 Int_t MDataSetIter::AddDirectory(const char *dir, const char *filter, Int_t recursive) 174 { 175 const Int_t rc = MDirIter::AddDirectory(dir, filter, recursive); 176 if (rc==0) 177 return 0; 178 179 // 180 // Add the files inside that directory to the fFileList. In order to 181 // add only the files inside the new directory added, we create 182 // and MDirIter with only that directory. Otherwise, it we call 183 // directly this.Next() inside FillFileList the new files and the 184 // previously existing one will be again adde to the fFileList. 185 // 186 MDirIter next(dir,filter,recursive); 187 AddToFileList(next); 188 189 next.Print() ; 190 191 return kTRUE; 192 } 193 194 195 // ---------------------------------------------------------------------------- 196 // 197 // Add a source name to the list of selected source names. 198 // 199 void MDataSetIter::SelectSourceName(const char *src) 200 { 201 fSrcList.Add((TObject*)(new TNamed(src, src))); 202 } 203 88 204 89 205 // ---------------------------------------------------------------------------- … … 112 228 return kFALSE; 113 229 } 230 231 // 232 // Skip Green and Blue calib 233 // 234 if(src.Contains("Blue",TString::kIgnoreCase) || src.Contains("Green",TString::kIgnoreCase)) 235 { 236 *fLog << warn << "Skipping Blue/Green run [" << src << "]" << endl; 237 return kFALSE; 238 } 239 240 114 241 115 242 // … … 124 251 if(src.Contains("-")) 125 252 { 126 *fLog << warn << "For source [" << src << "] ignoring suffix ["127 253 //*fLog << warn << "For source [" << src << "] ignoring suffix [" 254 // << src( src.First("-")+1, src.Length() ) << "]" << endl; 128 255 src.Remove(src.First("-")); 129 256 } … … 141 268 ValidSrc = n->GetName(); 142 269 143 //if (src==ValidSrc) // For dealing with new calib files as Mrk421blue5144 if (src.Contains(ValidSrc))270 if (src==ValidSrc) // For dealing with new calib files as Mrk421blue5 271 //if (src.Contains(ValidSrc)) 145 272 return kTRUE; 146 273 } … … 151 278 } 152 279 280 // ------------------------------------------------------------------- 281 // 282 // Compare two source names 283 // 284 Int_t MDataSetIter::CompareSourceNames(TString& src1, TString& src2) 285 { 286 if(src1.Contains("-")) 287 { 288 //*fLog << warn << "For source [" << src << "] ignoring suffix [" 289 // << src( src.First("-")+1, src.Length() ) << "]" << endl; 290 src1.Remove(src1.First("-")); 291 } 292 293 294 if(src2.Contains("-")) 295 { 296 //*fLog << warn << "For source [" << src << "] ignoring suffix [" 297 // << src( src.First("-")+1, src.Length() ) << "]" << endl; 298 src2.Remove(src2.First("-")); 299 } 300 301 return (src1.CompareTo(src2)==0) ? kTRUE : kFALSE; 302 } 153 303 154 304 // --------------------------------------------------------------------------- … … 163 313 path = file(0,slash+1); 164 314 name = file(slash+1,file.Length()); 165 315 316 TString tmp = name; 317 318 166 319 // Get date 167 date = name(0,8); 168 320 date = tmp(0,tmp.First('_')); 321 tmp = tmp.Remove(0,tmp.First('_')+1); 322 323 169 324 // Get run number 170 const TString runstr = name(9,5);325 const TString runstr = tmp(0,tmp.First('_')); 171 326 *run = atoi(runstr.Data()); 172 327 tmp = tmp.Remove(0,tmp.First('_')+1); 328 329 173 330 // Get run type 174 *type = name[15]; 331 *type = tmp[0]; 332 tmp = tmp.Remove(0,tmp.First('_')+1); 333 175 334 176 335 // Get source name 177 src = name(17,name.Last('_')-17); 178 } 179 180 181 // --------------------------------------------------------------------------- 182 // 183 // Add all the files inside a given directory to the fFileList. 184 // 185 void MDataSetIter::AddToFileList(MDirIter& dir) 186 { 187 188 TString name; 189 while (!(name=dir.Next()).IsNull()) 190 { 191 fFileList.Add((TObject*)(new TNamed((const char*)name, ""))); 192 } 193 194 // 195 // Sort File List by name 196 // 197 fFileList.Sort(); 198 } 199 200 201 // ---------------------------------------------------------------------------- 202 // 203 // Overload MDirIter::AddDirectory 204 // 205 // Each time a new directory is added, all the files inside that directory 206 // are added to the fFileList. 207 // 208 // Returns the number of directories added 209 // 210 Int_t MDataSetIter::AddDirectory(const char *dir, const char *filter, Int_t recursive) 211 { 212 const Int_t rc = MDirIter::AddDirectory(dir, filter, recursive); 213 if (rc==0) 214 return 0; 215 216 // 217 // Add the files inside that directory to the fFileList. In order to 218 // add only the files inside the new directory added, we create 219 // and MDirIter with only that directory. Otherwise, it we call 220 // directly this.Next() inside FillFileList the new files and the 221 // previously existing one will be again adde to the fFileList. 222 // 223 MDirIter next(dir,filter,recursive); 224 AddToFileList(next); 225 226 return kTRUE; 227 } 228 229 230 // ---------------------------------------------------------------------------- 231 // 232 // Add a source name to the list of selected source names. 233 // 234 void MDataSetIter::SelectSourceName(const char *src) 235 { 236 fSrcList.Add((TObject*)(new TNamed(src, src))); 237 } 238 336 //src = tmp(0,tmp.First('_')); 337 // 338 // To deal with 4C15 with filemames doesn't include '_E' (18-11-2004) 339 // 340 if (tmp.Contains('_')) 341 src = tmp(0,tmp.First('_')); 342 else 343 src = tmp(0,tmp.First('.')); 344 } 345 239 346 240 347 // ---------------------------------------------------------------------------- … … 248 355 { 249 356 *fLog << warn << "Doesn't exist previous set." << endl; 250 357 return kFALSE; 251 358 } 252 359 … … 264 371 265 372 ScanFileName(oldRuns.Next(), name, path, date, src, &run, &type); 266 267 // if( src != fSrcName) 268 // { 269 // *fLog << err << "Previous runs were for a diffrent source...exit." << endl; 270 // return kFALSE; 271 // } 272 273 // 274 // For dealing with calibration color we just ask than the srcname 275 // contains the FirstSrcName 276 // 277 if( !src.Contains(fSrcName) ) 278 { 279 *fLog << warn << "Previous runs were for a diffrent source [" << src << "] vs [" << fSrcName << "] ...exit." << endl; 280 return kFALSE; 281 } 282 373 374 375 if ( !CompareSourceNames(src,fSrcName) ) 376 // 377 // For dealing with calibration color we just ask than the srcname 378 // contains the FirstSrcName 379 // 380 //if( !src.Contains(fSrcName) ) 381 { 382 *fLog << warn << "Previous runs were for a diffrent source [" << src << "] vs [" << fSrcName << "] ...exit." << endl; 383 return kFALSE; 384 } 385 283 386 284 387 return kTRUE; … … 300 403 // 301 404 // Process all the runs which runnumber is later to the last processed run 302 // (the first time this function is call fLastProcessed Run is 0, so it start405 // (the first time this function is call fLastProcessedDataRun is 0, so it start 303 406 // processing from the beginning) 304 407 // … … 310 413 311 414 if(fFileList.GetLast()==-1) 415 { 416 *fLog << warn << "File list empty." << endl; 312 417 return kFALSE; 418 } 313 419 314 420 … … 320 426 MRunIter* oldCalRuns = 0; 321 427 322 323 428 if(fDataRuns) 324 429 oldDataRuns = (MRunIter*)fDataRuns->Clone(); … … 340 445 // the directory. Then Return kFALSE 341 446 // 342 if ( fDataRuns->GetNumRuns()==0 ) 447 if ( fDataRuns->GetNumRuns()==0 ) 343 448 { 344 449 *fLog << warn << "No more Data runs left." << endl; … … 470 575 // Print the runs of this data set 471 576 // 472 Print();577 //Print(); 473 578 474 579 … … 478 583 479 584 585 return kTRUE; 586 } 587 588 589 // ----------------------------------------------------------------------- 590 // 591 // Write an ASCII file with the sequence info. 592 // The name of the file is 'sequenceRunNum.txt' where 593 // RunNum is the run number of the first data file to analyse. We use 594 // the data runnumber instead of calib run because several sequences can 595 // have the same calib run (just the P can change) 596 // 597 Int_t MDataSetIter::WriteSequence() 598 { 599 // 600 // Sequence 601 // 602 //fSequence->SetupDatRuns(fDataRuns, fPathData, "D"); 603 //fSequence->SetupPedRuns(fPedRuns, fPathData, "P"); 604 //fSequence->SetupCalRuns(fCalRuns, fPathData, "C"); 605 606 //fSequence->Print(); 607 608 TString sped = fPedRuns->GetRunsAsFileName(); 609 TString scal = fCalRuns->GetRunsAsFileName(); 610 TString sdata = fDataRuns->GetRunsAsFileName(); 611 612 sped.ReplaceAll("_"," "); 613 scal.ReplaceAll("_"," "); 614 sdata.ReplaceAll("_"," "); 615 616 617 Int_t seqnum; 618 //sscanf(scal.Data(),"%d",&seqnum); 619 sscanf(sdata.Data(),"%d",&seqnum); 620 621 TString fname = Form("sequence_%s_%d.txt",fDate.Data(), seqnum); 622 ofstream out(fname); 623 624 625 TString date = fDate; 626 date.Insert(4,"-"); 627 date.Insert(7,"-"); 628 629 630 //out << "# Sequence number (identifier)" <<endl; 631 out << "Sequence: " << seqnum << endl; 632 //out << endl; 633 //out << "# date of sunrise of the observation night" << endl; 634 //out << "Night: 2004-09-21" << endl; 635 out << "Night: " << date << endl; 636 out << endl; 637 //out << "# Source name of all runs of sequence" << endl; 638 //out << "Source: " << fSrcName << endl; 639 //out << endl; 640 //out << "# List of all runs of this sequence" << endl; 641 //out << "Runs: " << scal << " " << sped << " "<< sdata << endl; 642 //out << endl; 643 //out << "# List of all calibration runs of this sequence" << endl; 644 out << "CalRuns: " << scal << endl; 645 //out << "# List of all pedestal runs of this sequence" << endl; 646 out << "PedRuns: " << sped << endl; 647 //out << "# List of all data runs of this sequence" << endl; 648 out << "DatRuns: "<< sdata << endl; 649 out.close(); 650 651 480 652 return kTRUE; 481 653 } … … 520 692 fCalRuns = new MRunIter(); 521 693 522 523 // 524 TString FirstSrcName = ""; // SrcName of the first run found 694 // 695 // Init 696 // 697 TString FirstSrcName = ""; // SrcName of the first run found 525 698 Bool_t RunFound = kFALSE; 526 699 Bool_t DataRunFound = kFALSE; 527 700 Bool_t CalRunFound = kFALSE; 528 701 Bool_t PedRunFound = kFALSE; 702 703 529 704 530 705 … … 559 734 ScanFileName(n->GetName(), name, path, date, src, &run, &type); 560 735 561 736 737 // 738 // Check that runnumber is inside the desire range of range to analyse [fInitialRun,fEndRun] 739 // 740 if(fEndRun !=-1 && run > fEndRun) 741 break; 742 if(run < fInitialRun) 743 continue; 744 745 562 746 // 563 // Skip until finding the following run after the fLastDataRun564 // 565 if( run <= fLastProcessed Run )747 // Skip until finding the following run after the last processed one, fLastDataRun 748 // 749 if( run <= fLastProcessedDataRun ) 566 750 continue; 567 751 568 752 // 569 753 // Check that the source name is among one of the selected source names … … 571 755 if( LockSrcName != "") 572 756 { 573 if( src != LockSrcName ) 574 continue; 757 FirstSrcName = LockSrcName; 575 758 } 576 else 577 { 578 if( !CheckSourceName(src) ) 579 continue; 580 } 759 760 if( !CheckSourceName(src) ) 761 continue; 762 581 763 582 764 // … … 608 790 } 609 791 610 if( src != FirstSrcName) 792 793 if( !CompareSourceNames(src,FirstSrcName) ) 611 794 { 612 if(type!='C') 613 { 614 *fLog << err << "ERROR: Source Name differs inside data set (" 795 *fLog << err << "ERROR: Source Name differs inside data set (" 615 796 << src << " vs. " << FirstSrcName << ") ...exit." << endl; 616 return kFALSE; 617 } 618 else 619 { 620 *fLog << warn << "Warning: Cal Source Name differs inside data set (" << src << " vs. " << FirstSrcName << ")." << endl; 621 } 797 return kFALSE; 622 798 } 799 623 800 624 801 … … 641 818 DataRunFound = kTRUE; 642 819 643 fLastProcessedRun = run; 644 820 fLastProcessedDataRun = run; 645 821 } 646 822 break; … … 752 928 753 929 930 // ------------------------------------------------------------------------------------ 931 // 932 // Deterimines wheather of data runs has been processed or not 933 // 934 Bool_t MDataSetIter::HasFinishedSuccesfully() 935 { 936 937 if(fEndRun==-1) 938 *fLog << "LastDataRun = " << fLastDataRun << endl; 939 else 940 *fLog << "EndRun = " << fEndRun << endl; 941 942 *fLog << "LastProcessedDataRun = " << fLastProcessedDataRun << endl; 943 944 945 if(fEndRun==-1) 946 return fLastProcessedDataRun==fLastDataRun ? kTRUE : kFALSE; 947 else 948 return fLastProcessedDataRun==fEndRun ? kTRUE : kFALSE; 949 950 }
Note:
See TracChangeset
for help on using the changeset viewer.