#include #include #include #include #include #include #include #include #include "ICOMETLog.hxx" #include "ICOMETInput.hxx" #include "ICOMETOutputMerged.hxx" #include "IInputFileList.hxx" void usage(void) { std::cout <<"Usage: oaEvent_concatenate-files.exe [options] files\n" " where file specifier is the path to a list of oaEvent files\n" " /\n\n" "The specified files are concatenated into one large file by merging the event \n" "trees. Records of original file content are saved using IEntryLists, which \n" "are stored in the new merged output file.\n\n" "Options: \n" " -I Text file containing a list of input oaEvent files. Each line must\n" " match one of the following forms. \n" " filename \n" " filename root \n" " Note, this has only been tested on ROOT files.\n\n" " -o Name of the output file\n\n" " -b Flag to allow bad files to be skipped\n\n" " -L Flag disabling file list log being printed" << std::endl; } int main(int argc, char **argv) { // Get the default options COMET::IInputFileList inputFiles; inputFiles.SetSkipBadFiles(false); std::string fOutFileName = "mergedFiles.root"; bool printFilelistLog = true; // Lets count how many events we merge int nEventsMerged = 0; // Set the options int c; while ((c = getopt(argc, argv, "I:o:bLh")) != -1) switch (c){ // List of files from an input file list case 'I': if(!inputFiles.ReadListFromFile(optarg)){ COMETError("Problem obtaining input list from file."); return 1; } break; // Choose the output name case 'o': fOutFileName= optarg; break; // Suppress printing the file list log case 'L': printFilelistLog = false; break; // Allow bad files to be skipped case 'b': inputFiles.SetSkipBadFiles(false); break; // Print the help menu case 'h': usage(); return 0; // Let getopt deal with the rest case '?': return 1; default: abort(); } // Prepare the input files for(int i = optind;iExpandPathName(configPath); COMET::ICOMETLog::Configure(configPath.Data()); // Open the output COMET::ICOMETOutputMerged* mergedFile = new COMET::ICOMETOutputMerged(fOutFileName.c_str(), "CREATE"); // Declare the output list file and open it if we need it std::ofstream fileListLog; if (printFilelistLog) { // Delare the name of the output file list log std::string fileListLogName; // Get the basename of the file minus the extension std::string outBaseName = gSystem->BaseName(fOutFileName.c_str()); std::string outDirName = gSystem->DirName(fOutFileName.c_str()); outDirName.append("/"); size_t lastdot = outBaseName.find_last_of("."); // If it has no extention, just add the correct suffix if (lastdot == std::string::npos) fileListLogName = fOutFileName + "_listlog.txt"; // Otherwise, strip the extension, and add the correct suffix else fileListLogName = outDirName + outBaseName.substr(0, lastdot) + "_listlog.txt"; fileListLog.open(fileListLogName.c_str()); } // Open up the input files while (inputFiles.OpenNextFile()){ // Get the next input file COMET::ICOMETInput* fInputFile = dynamic_cast(inputFiles.GetCurrentFile()); // Add this input file mergedFile->AddFile(fInputFile); if (printFilelistLog) fileListLog << fInputFile->GetFilename() << "\n"; // Add the number of entries added nEventsMerged += fInputFile->GetEventsInFile(); inputFiles.CloseFile(); } // Close the merged file mergedFile->Close(); if (printFilelistLog) fileListLog.close(); // Recored the number of events merged COMETLog("Number of Events Merged : " << nEventsMerged); return 0; }