Changeset 6691 for trunk/MagicSoft
- Timestamp:
- 03/01/05 19:08:59 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mtemp/mucm/classes
- Files:
-
- 2 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 } -
trunk/MagicSoft/Mars/mtemp/mucm/classes/MDataSetIter.h
r4683 r6691 8 8 #ifndef MARS_MRunIter 9 9 #include "MRunIter.h" 10 #endif 11 12 #ifndef MARS_MSequence 13 #include "MSequence.h" 10 14 #endif 11 15 … … 25 29 TObjArray fSrcList; // List with the valid source names 26 30 27 Int_t fLastProcessedRun; // Runnumber of the last processed run 31 32 Int_t fInitialRun; // Runnumber of the first run to proccess 33 Int_t fEndRun; // Runnumber of the last run to proccess 34 Int_t fLastProcessedDataRun; // Runnumber of the last processed run 35 Int_t fLastDataRun; // Lst Data runnumber in fFileList 28 36 29 37 MRunIter* fPedRuns; 30 38 MRunIter* fCalRuns; 31 39 MRunIter* fDataRuns; 40 MSequence* fSequence; 32 41 33 42 TString fSrcName; 34 43 TString fDate; 35 44 45 Int_t fDefCalRun; 46 TString fDefCalRunPath; 47 36 48 MLog *fLog; 37 49 38 Int_t fDefCalRun;39 TString fDefCalRunPath;40 50 41 51 Int_t CheckSourceName(TString& src); 52 Int_t CompareSourceNames(TString& src1, TString& src2); 42 53 void AddToFileList(MDirIter& dir); 43 void ScanFileName(const TString& file, TString& name, TString& path, TString& date, TString& src, Int_t* run, char* type); 44 54 void ScanFileName(const TString& file, TString& name, TString& path, TString& date, TString& src, Int_t* run, char* type); 55 Int_t IsPreviousRunUsable(MRunIter& oldRun); 56 Int_t Loop(TString option, TString LockSrcName=""); 57 void FindLastDataRun(); 58 45 59 public: 46 60 … … 52 66 Int_t NextDataSet(); 53 67 54 void SetInitialRun(Int_t run) { fLastProcessedRun = run; } 68 void SetInitialRun(Int_t run) { fInitialRun = run; } 69 void SetEndRun(Int_t run) 70 { 71 fEndRun = run; 72 FindLastDataRun(); 73 } 74 void SetDefCalRun(Int_t run, const char* path) {fDefCalRun = run; fDefCalRunPath = path; } 75 76 Int_t GetLastProcessedRun() const { return fLastProcessedDataRun; } 55 77 56 78 TString* GetSrcName() { return &fSrcName; } … … 74 96 void Reset() 75 97 { 76 MDirIter::Reset(); 77 fLastProcessedRun = 0; 98 fLastProcessedDataRun = 0; 78 99 } 79 100 80 101 void Print(const Option_t *option="") const; 102 103 Bool_t HasFinishedSuccesfully(); 81 104 82 Int_t Loop(TString option, TString LockSrcName=""); 83 84 Int_t IsPreviousRunUsable(MRunIter& oldRun); 85 86 87 Int_t GetLastProcessedRun() const { return fLastProcessedRun; } 88 89 void SetDefCalRun(Int_t run, const char* path) {fDefCalRun = run; fDefCalRunPath = path; } 105 Int_t WriteSequence(); 90 106 91 107 92 ClassDef(MDataSetIter, 1) // Iterator for runs108 ClassDef(MDataSetIter, 1) // Iterator for data set made of Pec, Cal and Data runs 93 109 }; 94 110
Note:
See TracChangeset
for help on using the changeset viewer.