//////////////////////////////////////////////////////////////////// // Program to make a validSet // (could also be used to make a valid set for production). // // usage: MakeL3Set -d -f -s // // is usually onotl_prd or onotl_dev // should contain a list of entries in the format: // tablename cid // e.g. // CMPALL 25195 // CMPCHANNEL 14371 // CMPREGION 14375 // CMPSTACK 14379 // CMUALL 25199 // CMUCHANNEL 14391 // CMUWEDGE 14387 // CMXALL 30019 // CMXCHANNEL 14403 // CMXWEDGE 14399 // CMXQUADRANT 14407 // CSXGLOBAL 47195 // CSXCHAST 47171 // CMUPOSITION 47175 // CMPPOSITION 47163 // CMXPOSITION 47179 // // is the name you want to define. // // You can see a list of the ProcessNames at: // http://cdfdbb.fnal.gov:8520/cdfr2/databases?type=cal-pd&do=r&gsrc=fp&rc=n&dcbk=FILECATALOG&calbk=PUBLIC //------------------------------------------------------------------------------------------------- // Victoria Martin. updated August 28 #include #include "CalibDB/ValidSetMaker.hh" #include "CalibDB/ValidKeyMap.hh" #include "CalibDB/ProcessDef.hh" #include #include #include using namespace std; void ParseArguments(char **filename, char **database_id, char **process_name, int argc, char **argv) { int c; for (;;){ c = getopt(argc, argv, "d:s:f:"); if (c == EOF) break; switch (c){ case 'd': *database_id = optarg; break; case 's': *process_name = optarg; break; case 'f': *filename = optarg; break; case '?': break; default: break; } } } class TableCID // stolen from MakeUsedSet by Mark Lancaster // and slightly modified { public: TableCID() { } ; TableCID(string name,int id) { _tablename = name ; _cid = id ;} TableCID(string name) { _tablename = name ; _cid = 0 ; } void SetCID(int id) {_cid = id ;} ~TableCID() { } ; string tablename() {return _tablename;} unsigned int cid() {return _cid;} friend istream & read_tablecid(istream& ist, TableCID& t) { if (!(ist >> t._tablename)) return ist ; if (!(ist >> t._cid)) return ist ; cout << "Read Values : TABLENAME = " << t._tablename << " \tCID = " << t._cid << endl; return ist; } private: string _tablename; unsigned int _cid; }; typedef vector TCIDS; int main(int argc, char* argv[]) { //check we have all the arguments if (argc<7) { cerr << "Usage: " << argv[0] << " -d -f -s " << endl; return -1; } //parse the arguments char *database_id; char *filename; char *process_name; ParseArguments(&filename, &database_id, &process_name, argc, argv); // check we can open the file ifstream inFile(filename); if (!inFile) { cerr << "Error opening i/p file = " << filename << endl; return -1; } // read in the file // the format must be tablename, cid TCIDS tcids; TableCID tcid; { while ( read_tablecid(inFile,tcid) ) tcids.push_back(tcid); } cout << tcids.size() << " tables were read "<< endl; if (tcids.size() == 0) return -1; cout << endl; // // First fetch a process definition from the database, // or in this case define one from scratch with a // name and then a list of tables. // ProcessDef myprocess(process_name); TableCID *it; for (it = tcids.begin(); it!= tcids.end(); ++it){ myprocess.tablist.insert(it->tablename()); } myprocess.print(); // // Now put some keys for the specific runs for this process // into a ValidKeyMap. The ValidKeyMap is responsible for checking // that the keys match the process definition. // ValidKeyMap vkm(myprocess); for (it = tcids.begin(); it!= tcids.end(); ++it){ RunListKey rlk(it->tablename()); rlk.setID(it->cid()); vkm.add(rlk); } cout << "ValidMapKey size is " << vkm.size() << "\n"; // // Now create a ValidSetMaker to write the info for the // keys defined in vkm to a specific db. It has to check // whether the keys can be resolved before writing. // ValidSetMaker vsm(database_id); // vsm.print(vkm); ValidSet vs; if (vsm.write(vkm,vs)==Result::success) { cout << "Wrote ValidSet " << vs.jobset() << " to database " << database_id << " for " << vs.process() << endl; } else { cout << " --> Did not write ValidSet" << endl << endl; return -1; } return 0; }