// // // UsedSetVersion - returns the version of the latest used set for a beam line entry for a given // history code. // // to test do: UsedSetVersion ofotl_prd_read 145052 PAD_PHYSICS_COTBEAM 999 345 // // 08/07/02 Hartmut Stadie //*************************************************************************************** #include #include #include "CalibDB/UsedSetKey.hh" #include "CalibDB/UsedSetDefs.hh" #include "CalibDB/ValidSetKey.hh" #include "CalibDB/ValidSetDefs.hh" #include "Alignment/CotBeam.hh" #include "Alignment/SvxBeam.hh" int main(int argc, char* argv[]) { if(argc != 7) { std::cout << "USAGE: UsedSetVersion " << std::endl; std::cout << " history = 999 lists all used set." << std::endl; return 1; } std::string dbid = argv[1]; int run = atoi(argv[2]); std::string usedsetname = argv[3]; int history = atoi(argv[4]); int algorithm = atoi(argv[5]); int passindex = atoi(argv[6]); int verbose = 0; //create the managers if(verbose) std::cout << "Debug: creating UsedSet_mgr" << std::endl; UsedSet_mgr used_mgr(dbid,"UsedSet"); if(verbose) std::cout << "Debug: creating ValidSet_mgr" << std::endl; ValidSet_mgr valid_mgr(dbid,"ValidSet"); //load the used sets UsedSet_var used_set; // Handle template of vector of UsedSet UsedSetKey used_set_key; used_set_key.process_ = ProcessTag(usedsetname); // used_set_key.run_ = RunVersion(run,Version::undefined); used_set_key.run_ = RunVersion(run,Version::latest); if(verbose) std::cout << "Debug: calling isvalid" << std::endl; bool qq1 = used_mgr.isValid(); if(verbose) std::cout << "Debug: printing used_set_key " << std::endl; if(verbose) std::cout << used_set_key << std::endl; if(verbose) std::cout << "Debug: calling get " << std::endl; bool qq2 = used_mgr.get(used_set_key,used_set) == Result::success; if(verbose) std::cout << "Debug: result: "<< qq1 << " " << qq2 << std::endl; if(qq1 && qq2) { if(verbose) { std::cout << "Debug: used set: list of UsedSet's " << std::endl; for(int i = 0 , n = used_set->size() ; i < n ; ++i) std::cout << used_set->at(i) << std::endl; } //try to load tables and find the right version CotBeam cotbeam(dbid); SvxBeam svxbeam(dbid); int version = 0; bool svx = true, cot = true; for(int i = 0 , n = used_set->size() ; i < n ; ++i) { ValidSetKey valid_set_key(used_set->at(i).jobset()); // typedef db::Handle ValidSet_var; // ValidSetContainer is a vector of ValidSet ValidSet_var valid_set; if(verbose) std::cout << "Debug: calling valid_mgr.isValid " << std::endl; bool q1 = valid_mgr.isValid(); if(verbose) std::cout << "Debug: valid set key:" << std::endl; if(verbose) std::cout << valid_set_key << std::endl; if(verbose) std::cout << "Debug: calling get for valid set " << std::endl; bool q2 = valid_mgr.get(valid_set_key,valid_set) == Result::success; if(verbose) std::cout << "Debug: results: " << q1 << " " << q2 << std::endl; if(q1 && q2) { int loadStat = svxbeam.loadCid(valid_set->at(0).cids_[0]); if(verbose) { std::cout << "Debug: Svx CID " << valid_set->at(0).cids_[0] << std::endl; std::cout << "Debug: stat " << loadStat << std::endl; std::cout << "Debug: Process tag, size " << valid_set->at(0).process_ << " " << valid_set->size() << std::endl; } if(svx && loadStat==0) { SvxBeamPosition sBeamPos(svxbeam.getRecord()); cot = false; if(history == 999) { std::cout << "jobset:" << used_set->at(i).jobset() << " version:" << used_set->at(i).run_.version_ << " history:" << (sBeamPos.Flag0() & 0xFFFF) << " algorithm:" << ((sBeamPos.Flag0() >> 16) & 0xFFFF) << std::endl; } if(verbose) { std::cout << "Debug: history compare: " << (sBeamPos.Flag0() & 0xFFFF) << " " << history << std::endl; std::cout << "Debug: algorit compare: " << ((sBeamPos.Flag0()>>16) & 0xFFFF) << " " << algorithm << std::endl; std::cout << "Debug: version compare: " << used_set->at(i).run_.version_ << " " << version << std::endl; } if(((sBeamPos.Flag0() & 0xFFFF) == history) && (((sBeamPos.Flag0() >> 16) & 0xFFFF) == algorithm) && (version < used_set->at(i).run_.version_)) version = used_set->at(i).run_.version_; if(verbose) std::cout << "Debug: Cot CID " << valid_set->at(0).cids_[0] << std::endl; } else if(cot && (cotbeam.loadCid(valid_set->at(0).cids_[0]) == 0)) { CotBeamPosition cBeamPos(cotbeam.getRecord()); svx = false; if(history == 999) { std::cout << "jobset:" << used_set->at(i).jobset() << " version:" << used_set->at(i).run_.version_ << " history:" << (cBeamPos.Flag0() & 0xFFFF) << " algorithm:" << ((cBeamPos.Flag0() >> 16) & 0xFFFF) << std::endl; } if(((cBeamPos.Flag0() & 0xFFFF) == history) && (((cBeamPos.Flag0() >> 16) & 0xFFFF) == algorithm) && (version < used_set->at(i).run_.version_)) version = used_set->at(i).run_.version_; } } } if(version != 0) { std::cout << passindex << "\t" << run << "\t" << run << "\t" << version << std::endl; return 0; } } return 1; }