// -*- mode: c++ -*- // // $Id$ // $Author$ // $Date$ // $Copyright: (C) 2001 BRAHMS Collaboration // #include #include #include #include #include #include #include using namespace std; int NDaySeconds(Float_t n) { return Int_t(60*60*24*n); } int main(int argc, char** argv) { // ---- command line stuff BrAppOptionManager* optionManager = BrAppOptionManager::Instance(); optionManager->SetVersion(1,0, "DumpRunNumbers"); BrAppIntOption* brunOption = new BrAppIntOption('b', "begin-run", "Start run number", 0); BrAppIntOption* erunOption = new BrAppIntOption('e', "end-run", "End run number", 0); BrAppStringOption *fileOption = new BrAppStringOption('f', "file", "Dump runnumber to file", ""); BrAppIntOption* minseqOption = new BrAppIntOption('s', "minimum-sequence", "Minimum number of sequence", 2); BrAppIntOption* ndayOption = new BrAppIntOption('n', "ndays", "Maximum number of days between calibration", 3); BrAppIntOption* intervalOption = new BrAppIntOption('i', "interval", "Max number of runs between calibration", 5); BrAppBoolOption* calibOption = new BrAppBoolOption('c', "calib", "Print only runs for calibration", kFALSE); BrAppStringOption* datatypeOption = new BrAppStringOption('t', "data-type", "Data type (pedestal, data)", "data"); BrAppStringOption* maindbhostOption = new BrAppStringOption('m', "maindb-host", "Main DB host name", "brahms-db0.rcf.bnl.gov"); BrAppStringOption* maindbnameOption = new BrAppStringOption('D', "maindb-name", "Main DB name", "BrahmsMain"); BrAppStringOption* maindbuserOption = new BrAppStringOption('U', "maindb-user", "Main DB user name", "query"); BrAppFloatOption* mrsangleOption = new BrAppFloatOption('M', "mrs-angle", "Filter MRS runs with angle (0 means no filter)", 0); BrAppFloatOption* ffsangleOption = new BrAppFloatOption('F', "ffs-angle", "Filter FFS runs with angle (0 means no filter)", 0); // command line optionManager->SetCommandLine(argc, argv); if (!optionManager->ProcessCommandLine()) throw new BrFatal("", "Bad command line, try --help option"); // help if (optionManager->ShowHelp()) return 0; try { // ---- check input consistency Int_t brun = brunOption->GetValue(); Int_t erun = erunOption->GetValue(); if (brun == 0) throw new BrError("Main", "Provide a valid start run please!"); if (brun > erun) { if (erun == 0) erun = brun; else { brun = erunOption->GetValue(); erun = brunOption->GetValue(); } } // check dump to file Bool_t dumpToFile = false; if (fileOption->GetValue()[0] != '\0') dumpToFile = true; // Get connections to Actual databases BrMainDb* mainDb = BrMainDb::Instance(); mainDb->SetUserName(maindbuserOption->GetValue()); mainDb->SetHostName(maindbhostOption->GetValue()); mainDb->SetDbName(maindbnameOption->GetValue()); if (!mainDb->Connect()) return 1; if (!mainDb->ConnectToRun()) return 1; BrRunInfoManager* runMan = BrRunInfoManager::Instance(); for (Int_t run = brun; run <= erun; run++) runMan->Register(run); runMan->Init(); // check if we shall dump in ascii file ofstream asciidump; if (dumpToFile) { asciidump.open(fileOption->GetValue(), ios::out); asciidump << " *-------------------------------------------*" << endl << " * Dumping Run Numbers for: " << datatypeOption->GetValue(); if (ffsangleOption->GetValue()) asciidump << " FS@" << ffsangleOption->GetValue(); if (mrsangleOption->GetValue()) asciidump << " MRS@" << mrsangleOption->GetValue(); asciidump << "\n*-------------------------------------------*" << endl; } else { cout << " *-------------------------------------------*" << endl << " * DumpRunNumbers for: " << datatypeOption->GetValue(); if (ffsangleOption->GetValue()) cout << " FS@" << ffsangleOption->GetValue(); if (mrsangleOption->GetValue()) cout << " MRS@" << mrsangleOption->GetValue(); cout << "\n*-------------------------------------------*" << endl; } Float_t prevmrsang = 0; Float_t prevfsang = 0; Int_t prevD1field = 0; Int_t prevD5field = 0; Int_t interval = -1; Int_t prevtime = 0; Int_t ncalibs = 0; // ---- run loop for (Int_t run = brun; run <= erun; run++) { // update runMan runMan->Update(); const BrRunInfo* runInfo = runMan->GetCurrentRun(); // check if run exists and is written to HPSS if (runInfo->GetRunNo() == -1 || !runInfo->GetHPSS()) continue; // check data type TString datatype(runInfo->GetRunType()); TString inptype(datatypeOption->GetValue()); datatype.ToLower(); inptype.ToLower(); // check datatype, number of sequences and angles if (datatype == inptype) { // check angle if (mrsangleOption->GetValue()) if (runInfo->GetMRSAngle() != mrsangleOption->GetValue()) continue; if (ffsangleOption->GetValue()) if (runInfo->GetFFSAngle() != ffsangleOption->GetValue()) continue; // check if this is a run to calibrate interval++; Bool_t doprint = kTRUE; TString info(""); if (runInfo->GetFFSAngle() != prevfsang || runInfo->GetMRSAngle() != prevmrsang || runInfo->GetD1Set() != prevD1field || runInfo->GetD5Set() != prevD5field || prevtime+(NDaySeconds(ndayOption->GetValue())) < runInfo->GetUnixStartTime() || interval >= intervalOption->GetValue()) { // possible calibration job, check nseq if (runInfo->GetSequences()->GetEntries() >= minseqOption->GetValue()) { if (!calibOption->GetValue()) info += "--->"; interval = -1; ncalibs++; } else { if (calibOption->GetValue()) doprint = kFALSE; info += " "; } } else { // not a calibration job if (calibOption->GetValue()) doprint = kFALSE; info += " "; } // print run info if (doprint) { info += Form("Run %6d ", runInfo->GetRunNo()); info += Form("with %2d seqs. ", runInfo->GetSequences()->GetEntries()); info += Form("MRS@%2.0fdeg ", runInfo->GetMRSAngle()); info += Form("(%4d%s) ", runInfo->GetD5Set(), runInfo->GetD5Pol()); info += Form("FFS@%2.1fdeg ", runInfo->GetFFSAngle()); info += Form("(%4d%s) ", runInfo->GetD1Set(), runInfo->GetD1Pol()); info += Form("(BFS@%2.1f) ", runInfo->GetBFSAngle()); info += Form("MRS Quality: %s ", runInfo->GetMrsQuality()); info += Form("FS Quality: %s ", runInfo->GetFsQuality()); if (dumpToFile) asciidump << info.Data() << endl; else cout << info.Data() << endl; // update check values } if (interval == -1) { prevfsang = runInfo->GetFFSAngle(); prevmrsang = runInfo->GetMRSAngle(); prevD1field = runInfo->GetD1Set(); prevD5field = runInfo->GetD5Set(); prevtime = runInfo->GetUnixStartTime(); } } } if (dumpToFile) asciidump << "Suggest " << ncalibs << " runs for calibrations" << (!calibOption->GetValue() ? " all marked with: -->" : ".") << endl; cout << "Suggest " << ncalibs << " runs for calibrations" << (!calibOption->GetValue() ? " all marked with: -->" : ".") << endl; } // catch any errors catch(BrException* e) { cerr << "RunInfo" << *e << endl; e->Execute(); return 1; } return 0; }