// process_cbnt.cxx // // David Adams // April 2003 // // Function that applies a PAW kumac to an ATLAS combined ntuple dataset. // #include "dataset_CBNT/process_cbnt.h" #include #include #include #include #include #include #include #include "dataset_util/FileStatus.h" #include "dataset_util/Path.h" #include "dataset_util/CommandLine.h" #include "dataset_util/WorkingDirectory.h" #include "dataset_util/Text.h" #include "dataset_CBNT/HbookFile.h" #include "dataset_CBNT/CbntDataset.h" using std::string; using std::cout; using std::endl; using std::ofstream; using dset::CbntDataset; typedef Text::Line Line; //********************************************************************** // Local definitions. //********************************************************************** namespace { // Function which handles either initialization case. // For initialization from file, init has only one line // which is the file name. int process_cbnt(const CbntDataset& dst, bool init_from_script, const Text& inittxt, const Text& usercode, string resfile, int verbose) { WorkingDirectory wd; // Find paw. Path exepath; exepath.getenv("PATH"); if ( exepath.size() == 0 ) return 1; Path pawpath = exepath.find("paw"); if ( pawpath.size() == 0 ) return 2; string pawexe = pawpath.front() + "/paw"; if ( ! FileStatus(pawexe).is_executable() ) return 3; // Create the include file from the dataset. // Extract the HBNAME calls as we parse the file. // We do not expect to find any HBNAME calls. Text hbcalls; string incfile = "cbnt.inc"; int id = 3333; HbookFile& hfile = dst.hbook_file(); if ( ! hfile.is_valid() ) return 5; if ( hfile.open() != 0 ) return 6; if ( hfile.cd("cbnt") != 0 ) return 7; if ( hfile.evcode(id) != 0 ) return 8; if ( hfile.close() != 0 ) return 9; Text oldcode("evcode.f"); Text newcode; newcode.append("* Created in process_cbnt"); newcode.append(""); bool found_end = false; for ( Text::size_type ilin=0; ilin 4 ) cout << kum << endl; // Write kumac. string kumfile = "process_cbnt.kumac"; { string com = "rm -rf "; com += kumfile; system(com.c_str()); } if ( FileStatus(kumfile).exists() ) return 17; kum.write(kumfile); // Create command line. CommandLine::Name comname = pawexe; CommandLine::ArgumentList comargs; comargs.push_back("-b"); comargs.push_back(kumfile); CommandLine comline(comname, comargs); // Execute paw subprocess. int fstat = fork(); // Fork error. if ( fstat == -1 ) { return 18; // Child process. } else if ( fstat == 0 ) { if ( verbose > 3 ) cout << comline << endl; execv( comline.cname(), comline.unsafe_argv() ); // Parent process -- wait for child to finish. } else { int rstat; pid_t pid = wait(&rstat); assert( pid = fstat ); // Normal exit. if ( WIFEXITED(rstat) ) { int stat = WEXITSTATUS(rstat); if ( stat != 0 ) return stat + 100; // Other exit. } else { return 20; } } return 0; } } // end unnamed namespace //********************************************************************** // Functions. //********************************************************************** // Initialization from script. int process_cbnt(const CbntDataset& dst, const Text& inittxt, const Text& usercode, string resfile, int verbose) { return process_cbnt(dst, true, inittxt, usercode, resfile, verbose); } //********************************************************************** // Initialization from HBOOK file. int process_cbnt(const CbntDataset& dst, string hbkfile, const Text& usercode, string resfile, int verbose) { Text inittxt; inittxt.append(hbkfile); return process_cbnt(dst, false, inittxt, usercode, resfile, verbose); } //**********************************************************************