some more work on any2may. Still not meant for production

This commit is contained in:
nemu 2011-01-11 06:24:02 +00:00
parent 452018bedf
commit a406219826
4 changed files with 387 additions and 68 deletions

View File

@ -52,47 +52,69 @@ void any2many_syntax()
{
cout << endl << "usage: any2many [--help] : will show this help.";
cout << endl << " any2many --version : will show the svn version.";
cout << endl << " any2many -I <filename> | -i <runList-input> -c <convert-options> [-p <output-path>] [-o <output>] [-y <year>]";
cout << endl << " [-t <in-template> <out-template>] [-s] [-rebin <n>]";
cout << endl << " <filename> : a single file name, e.g. 2010/lem10_his_0111.root, but not starting with a '-'";
cout << endl << " <runList-input> : a list of run numbers separated by ' ' of the form: <run1> <run2> <run3> etc.";
cout << endl << " or a sequence of runs <runStart>-<runEnd>, e.g. 111-222";
cout << endl << " <convert-options> : <inFormat> <outFormat>";
cout << endl << " <inFormat> : input data file format. Supported formats are:";
cout << endl << " PSI-BIN, ROOT (LEM), MUD, NeXuS, PSI-MDU, WKM";
cout << endl << " <outFormat>: ouput data file format. Supported formats are:";
cout << endl << " PSI-BIN, ROOT (LEM), MUD, NeXuS, MDU, WKM, ASCII";
cout << endl << " <output-path> : output path for the converted files. If nothing is given, the current directory will be used,";
cout << endl << " unless the option '-s' is used.";
cout << endl << " <output> : single output file name. If <input> is a list of runs, this option";
cout << endl << " should be omitted since the file names are generated according to the";
cout << endl << " run number and the file format, e.g. 111 -> lemyy_his_0111.root, where yy is";
cout << endl << " the current year.";
cout << endl << " <year> : if the option -y is used, here a year in the form 'yy' can be given, if this";
cout << endl << " is the case, any automatic file name generation needs a year, this number will";
cout << endl << " be used.";
cout << endl << " <in-template>";
cout << endl << " <out-template> : template file name. Needed for run-lists in order to generate the proper file names.";
cout << endl << " The following template tags can be used: [yy] for year, and [rrrr] for the run number.";
cout << endl << " If the run number tag is used, the number of 'r' will give the number of digits used";
cout << endl << " with leading zeros, e.g. [rrrrrr] and run numbe 123 will result in 000123.";
cout << endl << " The same is true for the year, i.e. [yyyy] will result in something like 1999.";
cout << endl << " -s : with this option the output data file will be sent to the standard output.";
cout << endl << " <n> : number of bins to be packed";
cout << endl << " any2many -I <filename> | -i <runList-input> -c <convert-options> ";
cout << endl << " [-p <output-path>] [-o <output>] [-y <year>]";
cout << endl << " [-t <in-template> <out-template>] [-s] [-rebin <n>]";
cout << endl << " [-z <compressed>]";
cout << endl << " -I <filename> : where <filename> is a single file name,";
cout << endl << " e.g. 2010/lem10_his_0111.root, but not starting with a '-'";
cout << endl << " -i <runList-input> : where <runList-input> is a list of run numbers";
cout << endl << " separated by spaces ' ' of the form: <run1> <run2> <run3>";
cout << endl << " etc., or a sequence of runs <runStart>-<runEnd>, e.g. 111-222";
cout << endl << " -c <convert-options> : <inFormat> <outFormat>";
cout << endl << " <inFormat> : input data file format. Supported formats are:";
cout << endl << " PSI-BIN, ROOT (LEM), MUD, NeXuS, PSI-MDU, WKM";
cout << endl << " <outFormat> : ouput data file format. Supported formats are:";
cout << endl << " PSI-BIN, ROOT (LEM), MUD, NeXuS, MDU, WKM, ASCII";
cout << endl << " -p <output-path> : where <output-path> is the output path for the";
cout << endl << " converted files. If nothing is given, the current directory";
cout << endl << " will be used, unless the option '-s' is used.";
cout << endl << " -o <output> : where <output> is a single output file name. If <input>";
cout << endl << " is a list of runs, this option should be omitted since the file";
cout << endl << " names are generated according to the run number and the file";
cout << endl << " format, e.g. 111 -> lemyy_his_0111.root, where yy is the";
cout << endl << " current year.";
cout << endl << " -y <year> : if the option -y is used, here a year in the form 'yy' can";
cout << endl << " be given, if this is the case, any automatic file name";
cout << endl << " generation needs a year, this number will be used.";
cout << endl << " -t <in-template> <out-template> : ";
cout << endl << " <in-/out-template> : template file name. Needed for run-lists in";
cout << endl << " order to generate the proper file names. The following template";
cout << endl << " tags can be used: [yy] for year, and [rrrr] for the run number.";
cout << endl << " If the run number tag is used, the number of 'r' will give the";
cout << endl << " number of digits used with leading zeros, e.g. [rrrrrr] and run";
cout << endl << " number 123 will result in 000123. The same is true for the";
cout << endl << " year, i.e. [yyyy] will result in something like 1999.";
cout << endl << " -s : with this option the output data file will be sent to the stdout.";
cout << endl << " -rebin <n> : where <n> is the number of bins to be packed";
cout << endl << " -z [g|b] <compressed> : where <compressed> is the output file name";
cout << endl << " (without extension) of the compressed data collection, and";
cout << endl << " 'g' will result in .tar.gz, and 'b' in .tar.bz2 files.";
cout << endl;
cout << endl << " If the output option '-o' is missing, the output file name will be generated according to the";
cout << endl << " input data file name, and the output data format.";
cout << endl << " If the output option '-o' is missing, the output file name will be";
cout << endl << " generated according to the input data file name, and the output data";
cout << endl << " format.";
cout << endl;
cout << endl << "examples:" << endl;
cout << endl << " any2many -I 2010/lem10_his_0123.root -c ROOT ASCII -rebin 25";
cout << endl << " Will take the LEM ROOT file '2010/lem10_his_0123.root' rebin it with 25 and convert it to ASCII.";
cout << endl << " The output file name will be lem10_his_0123.ascii, and the file will be saved in the current directory.";
cout << endl << " any2many -i 123 137 -c PSI-BIN MUD -t d[yyyy]/deltat_tdc_gps_[rrrr].bin [rrrrrr].msr -y 2001";
cout << endl << " Will take the run 123 and 137, will generate the input file names d2001/deltat_tdc_gps_0123.bin and";
cout << endl << " d2001/deltat_tdc_gps_0137.bin, and output file names 000123.msr and 000137.msr";
cout << endl << " any2many -i 100-117 -c PSI-MDU ASCII -t d[yyyy]/deltat_tdc_alc_[rrrr].mdu [rrr].ascii -y 2011 -s";
cout << endl << " Will take the runs 100 through 117 and convert the PSI-MDU input files to ASCII output and instead of";
cout << endl << " saving them into a file, they will be spit to the standard output.";
cout << endl << " Will take the LEM ROOT file '2010/lem10_his_0123.root' rebin it with 25";
cout << endl << " and convert it to ASCII. The output file name will be";
cout << endl << " lem10_his_0123.ascii, and the file will be saved in the current directory." << endl;
cout << endl << " any2many -i 123 137 -c PSI-BIN MUD -t d[yyyy]/deltat_tdc_gps_[rrrr].bin \\";
cout << endl << " [rrrrrr].msr -y 2001";
cout << endl << " Will take the run 123 and 137, will generate the input file names:";
cout << endl << " d2001/deltat_tdc_gps_0123.bin and d2001/deltat_tdc_gps_0137.bin, and";
cout << endl << " output file names 000123.msr and 000137.msr" << endl;
cout << endl << " any2many -i 100-117 -c PSI-MDU ASCII -t d[yyyy]/deltat_tdc_alc_[rrrr].mdu \\";
cout << endl << " [rrr].ascii -y 2011 -s";
cout << endl << " Will take the runs 100 through 117 and convert the PSI-MDU input files to";
cout << endl << " ASCII output and instead of saving them into a file, they will be spit to";
cout << endl << " the standard output." << endl;
cout << endl << " any2many -i 100-117 -c NEXUS ROOT -t d[yyyy]/psi_gps_[rrrr].nexus \\";
cout << endl << " psi_[yyyy]_gps_[rrrr].root -z b psi_gps_run_100to117";
cout << endl << " Will take the runs 100 through 117 and convert the PSI-NEXUS input files";
cout << endl << " to ROOT output. Afterwards these new files will be collected in a";
cout << endl << " compressed archive psi_gps_run_100to117.tar.bz2." << endl;
cout << endl << endl;
}
@ -135,6 +157,7 @@ int main(int argc, char *argv[])
// init info structure
info.useStandardOutput = false;
info.rebin = 1;
info.compressionTag = 0; // no compression as default
// call any2many without arguments
if (argc == 1) {
@ -339,6 +362,32 @@ int main(int argc, char *argv[])
break;
}
}
// filter out if compression is whished
if (strstr(argv[i], "-z")) {
if (i+2 < argc) {
if ((argv[i+1][0] == '-') || (argv[i+2][0] == '-')) {
cerr << endl << ">> any2many **ERROR** found invalid template in option '-t'" << endl;
show_syntax = true;
break;
}
if (argv[i+1][0] == 'g') {
info.compressionTag = 1;
} else if (argv[i+1][0] == 'b') {
info.compressionTag = 2;
} else {
cerr << endl << ">> any2many **ERROR** found in option '-z' compression tag '" << argv[i+1] << "' which is not supported." << endl;
show_syntax = true;
break;
}
info.compressFileName = argv[i+2];
i += 2; // shift argument position
} else {
cerr << endl << ">> any2many **ERROR** found option '-z' with missing arguments" << endl;
show_syntax = true;
break;
}
}
}
/*
@ -355,6 +404,11 @@ cout << endl << "debug> info.outPath=" << info.outPath;
cout << endl << "debug> info.rebin=" << info.rebin;
cout << endl << "debug> info.inTemplate=" << info.inTemplate;
cout << endl << "debug> info.outTemplate=" << info.outTemplate;
cout << endl << "debug> info.compressionTag=" << info.compressionTag;
cout << endl << "debug> info.compressFileName=" << info.compressFileName;
cout << endl << "debug> info.outFileList=";
for (unsigned int i=0; i<info.outFileList.size(); i++)
cout << info.outFileList[i] << ", ";
cout << endl;
*/

View File

@ -270,6 +270,8 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
outTag = A2M_PSIBIN;
else if (!fAny2ManyInfo->outFormat.CompareTo("psi-mdu", TString::kIgnoreCase))
outTag = A2M_PSIMDU;
else if (!fAny2ManyInfo->outFormat.CompareTo("mud",TString::kIgnoreCase))
outTag = A2M_MUD;
else if (!fAny2ManyInfo->outFormat.CompareTo("nexus", TString::kIgnoreCase))
outTag = A2M_NEXUS;
else if (!fAny2ManyInfo->outFormat.CompareTo("wkm", TString::kIgnoreCase))
@ -440,6 +442,86 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
}
// check if compression is wished
if (fAny2ManyInfo->compressionTag > 0) {
TString fln = fAny2ManyInfo->compressFileName;
// currently system call is used, which means this is only running under Linux and Mac OS X but not under Windows
char cmd[256];
if (fAny2ManyInfo->outFileList.size() == 1) {
if (fAny2ManyInfo->compressionTag == 1) // gzip
fln += TString(".tar.gz");
else // bzip2
fln += TString(".tar.bz2");
if (fAny2ManyInfo->compressionTag == 1) // gzip
sprintf(cmd, "tar -zcf %s %s", fln.Data(), fAny2ManyInfo->outFileList[0].Data());
else // bzip2
sprintf(cmd, "tar -jcf %s %s", fln.Data(), fAny2ManyInfo->outFileList[0].Data());
system(cmd);
} else {
fln += TString(".tar");
for (UInt_t i=0; i<fAny2ManyInfo->outFileList.size(); i++) {
if (i==0) {
sprintf(cmd, "tar -cf %s %s", fln.Data(), fAny2ManyInfo->outFileList[i].Data());
} else {
sprintf(cmd, "tar -rf %s %s", fln.Data(), fAny2ManyInfo->outFileList[i].Data());
}
system(cmd);
}
if (fAny2ManyInfo->compressionTag == 1) // gzip
sprintf(cmd, "gzip %s", fln.Data());
else
sprintf(cmd, "bzip2 -z %s", fln.Data());
system(cmd);
}
// check if the compressed file shall be streamed to the stdout
if (fAny2ManyInfo->useStandardOutput) {
// stream file to stdout
ifstream is;
int length=1024;
char *buffer;
is.open(fln.Data(), ios::binary);
if (!is.is_open()) {
cerr << endl << "PRunDataHandler::ReadWriteFilesList(): **ERROR** Couldn't open the file for streaming." << endl;
remove(fln.Data());
return false;
}
// get length of file
is.seekg(0, ios::end);
length = is.tellg();
is.seekg(0, ios::beg);
if (length == -1) {
cerr << endl << "PRunDataHandler::ReadWriteFilesList(): **ERROR** Couldn't determine the file size." << endl;
remove(fln.Data());
return false;
}
// allocate memory
buffer = new char [length];
// read data as a block
while (!is.eof()) {
is.read(buffer, length);
cout.write(buffer, length);
}
is.close();
delete [] buffer;
// delete temporary root file
remove(fln.Data());
}
// remove all the converted files
for (UInt_t i=0; i<fAny2ManyInfo->outFileList.size(); i++)
remove(fAny2ManyInfo->outFileList[i].Data());
}
return true;
}
@ -690,6 +772,7 @@ Bool_t PRunDataHandler::FileExistsCheck(const Int_t idx)
if (idx == -1) { // single input file name
fln = fAny2ManyInfo->inFileName;
cout << endl << "debug> fln=" << fln << endl;
} else { // run file list entry shall be handled
// check for input/output templates
if ((fAny2ManyInfo->inTemplate.Length() == 0) || (fAny2ManyInfo->outTemplate.Length() == 0)) {
@ -710,7 +793,8 @@ Bool_t PRunDataHandler::FileExistsCheck(const Int_t idx)
// check if the file is in the local directory
if (gSystem->AccessPathName(fln) != true) { // found in the local dir
pathName = TString("./")+fln;
// pathName = TString("./")+fln;
pathName = fln;
}
// check if the file is found in the directory given in the startup file
if (pathName.CompareTo("???") == 0) { // not found in local directory search
@ -2717,12 +2801,12 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
cout << endl << ">> PRunDataHandler::WriteRootFile(): writing a root data file ... " << endl;
// generate output file name if needed
if (!fAny2ManyInfo->useStandardOutput) {
if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) {
if (fln.Length() == 0) {
Int_t start = fRunPathName.Last('/');
Int_t end = fRunPathName.Last('.');
if ((start == -1) || (end == -1)) {
cout << endl << ">> PRunDataHandler::WriteAsciiFile(): **ERROR** couldn't generate the output file name ..." << endl;
if (end == -1) {
cerr << endl << ">> PRunDataHandler::WriteRootFile(): **ERROR** couldn't generate the output file name ..." << endl;
return false;
}
// cut out the filename (get rid of the extension, and the path)
@ -2737,6 +2821,8 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
} else {
fln.Prepend(fAny2ManyInfo->outPath);
}
// keep the file name if compression is whished
fAny2ManyInfo->outFileList.push_back(fln);
} else {
fln = TString("__tmp.root");
}
@ -2829,7 +2915,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
// write file
TFile *fout = new TFile(fln, "RECREATE", fln);
if (fout == 0) {
cout << endl << "PRunDataHandler::WriteRootFile(): **ERROR** Couldn't create ROOT file '" << fln << "'" << endl;
cerr << endl << "PRunDataHandler::WriteRootFile(): **ERROR** Couldn't create ROOT file '" << fln << "'" << endl;
return false;
}
@ -2848,7 +2934,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
delete header;
// check if root file shall be streamed to stdout
if (fAny2ManyInfo->useStandardOutput) {
if (fAny2ManyInfo->useStandardOutput && (fAny2ManyInfo->compressionTag == 0)) {
// stream file to stdout
ifstream is;
int length=1024;
@ -2856,7 +2942,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
is.open(fln.Data(), ios::binary);
if (!is.is_open()) {
cout << endl << "PRunDataHandler::WriteRootFile(): **ERROR** Couldn't open the root-file for streaming." << endl;
cerr << endl << "PRunDataHandler::WriteRootFile(): **ERROR** Couldn't open the root-file for streaming." << endl;
remove(fln.Data());
return false;
}
@ -2867,7 +2953,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
is.seekg(0, ios::beg);
if (length == -1) {
cout << endl << "PRunDataHandler::WriteRootFile(): **ERROR** Couldn't determine the root-file size." << endl;
cerr << endl << "PRunDataHandler::WriteRootFile(): **ERROR** Couldn't determine the root-file size." << endl;
remove(fln.Data());
return false;
}
@ -2930,8 +3016,8 @@ Bool_t PRunDataHandler::WriteWkmFile(TString fln)
if (fln.Length() == 0) {
Int_t start = fRunPathName.Last('/');
Int_t end = fRunPathName.Last('.');
if ((start == -1) || (end == -1)) {
cout << endl << ">> PRunDataHandler::WriteWkmFile(): **ERROR** couldn't generate the output file name ..." << endl;
if (end == -1) {
cerr << endl << ">> PRunDataHandler::WriteWkmFile(): **ERROR** couldn't generate the output file name ..." << endl;
return false;
}
// cut out the filename (get rid of the extension, and the path)
@ -2946,12 +3032,14 @@ Bool_t PRunDataHandler::WriteWkmFile(TString fln)
} else {
fln.Prepend(fAny2ManyInfo->outPath);
}
// keep the file name if compression is whished
fAny2ManyInfo->outFileList.push_back(fln);
// write ascii file
ofstream fout;
streambuf* strm_buffer = 0;
if (!fAny2ManyInfo->useStandardOutput) {
if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) {
// open data-file
fout.open(fln.Data(), ofstream::out);
if (!fout.is_open()) {
@ -3022,7 +3110,7 @@ Bool_t PRunDataHandler::WriteWkmFile(TString fln)
}
}
if (!fAny2ManyInfo->useStandardOutput) {
if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) {
// restore old output buffer
cout.rdbuf(strm_buffer);
@ -3082,7 +3170,168 @@ Bool_t PRunDataHandler::WritePsiMduFile(TString fln)
*/
Bool_t PRunDataHandler::WriteMudFile(TString fln)
{
cout << endl << ">> PRunDataHandler::WriteMudFile(): will write a mud data file. Not yet implemented ... " << endl;
if (!fAny2ManyInfo->useStandardOutput)
cout << endl << ">> PRunDataHandler::WriteMudFile(): writing a mud data file ... " << endl;
// generate output file name if needed
if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) {
if (fln.Length() == 0) {
Int_t start = fRunPathName.Last('/');
Int_t end = fRunPathName.Last('.');
if (end == -1) {
cerr << endl << ">> PRunDataHandler::WriteMudFile(): **ERROR** couldn't generate the output file name ..." << endl;
return false;
}
// cut out the filename (get rid of the extension, and the path)
Char_t str1[1024], str2[1024];
strncpy(str1, fRunPathName.Data(), sizeof(str1));
for (Int_t i=0; i<end-start-1; i++) {
str2[i] = str1[i+start+1];
}
str2[end-start-1] = 0;
fln = fAny2ManyInfo->outPath + str2 + ".msr";
} else {
fln.Prepend(fAny2ManyInfo->outPath);
}
// keep the file name if compression is whished
fAny2ManyInfo->outFileList.push_back(fln);
} else {
fln = TString("__tmp.msr");
}
// generate the mud data file
int fd = MUD_openWrite((char*)fln.Data(), MUD_FMT_TRI_TD_ID);
if (fd == -1) {
cerr << endl << ">> PRunDataHandler::WriteMudFile(): **ERROR** couldn't open mud data file for write ..." << endl;
return false;
}
// generate header information
char dummy[32], info[128];
strcpy(dummy, "???");
MUD_setRunDesc(fd, MUD_SEC_GEN_RUN_DESC_ID);
MUD_setExptNumber(fd, 0);
MUD_setRunNumber(fd, fData[0].GetRunNumber());
MUD_setElapsedSec(fd, 0);
MUD_setTimeBegin(fd, 0);
MUD_setTimeEnd(fd, 0);
MUD_setTitle(fd, (char *)fData[0].GetRunTitle()->Data());
MUD_setLab(fd, dummy);
MUD_setArea(fd, dummy);
MUD_setMethod(fd, (char *)fData[0].GetSetup()->Data());
MUD_setApparatus(fd, dummy);
MUD_setInsert(fd, dummy);
MUD_setSample(fd, dummy);
MUD_setOrient(fd, dummy);
MUD_setDas(fd, dummy);
MUD_setExperimenter(fd, dummy);
sprintf(info, "%lf+-%lf (K)", fData[0].GetTemperature(0), fData[0].GetTempError(0));
MUD_setTemperature(fd, info);
sprintf(info, "%lf", fData[0].GetField());
MUD_setField(fd, info);
// generate the histograms
MUD_setHists(fd, MUD_GRP_TRI_TD_HIST_ID, fData[0].GetNoOfHistos());
UInt_t *data, dataSize = fData[0].GetDataBin(0)->size()/fAny2ManyInfo->rebin + 1;
data = new UInt_t[dataSize];
if (data == 0) {
cerr << endl << ">> PRunDataHandler::WriteMudFile(): **ERROR** couldn't allocate memory for the data ..." << endl;
MUD_closeWrite(fd);
return false;
}
UInt_t noOfEvents = 0, ival = 0, k = 0;
for (UInt_t i=0; i<fData[0].GetNoOfHistos(); i++) {
// fill data
for (UInt_t j=0; j<dataSize; j++)
data[j] = 0;
noOfEvents = 0;
k = 0;
for (UInt_t j=0; j<fData[0].GetDataBin(0)->size(); j++) {
if ((j != 0) && (j % fAny2ManyInfo->rebin == 0)) {
data[k] = ival;
noOfEvents += ival;
k++;
ival = 0;
}
ival += static_cast<UInt_t>(fData[0].GetDataBin(i)->at(j));
}
// feed data relevant information
// the numbering of the histograms start from '1', hence i+1 needed!!
MUD_setHistType(fd, i+1, MUD_GRP_TRI_TD_HIST_ID);
MUD_setHistNumBytes(fd, i+1, sizeof(data));
MUD_setHistNumBins(fd, i+1, dataSize);
MUD_setHistBytesPerBin(fd, i+1, 0);
MUD_setHistFsPerBin(fd, i+1, static_cast<UINT32>(1.0e6*fAny2ManyInfo->rebin*fData[0].GetTimeResolution())); // time resolution is given in (ns)
if (fData[0].GetT0Size() > i) {
MUD_setHistT0_Ps(fd, i+1, static_cast<UINT32>(1.0e3*fData[0].GetTimeResolution()*((fData[0].GetT0(i)+fAny2ManyInfo->rebin/2)/fAny2ManyInfo->rebin)));
MUD_setHistT0_Bin(fd, i+1, static_cast<UINT32>(fData[0].GetT0(i)/fAny2ManyInfo->rebin));
} else {
MUD_setHistT0_Ps(fd, i+1, 0);
MUD_setHistT0_Bin(fd, i+1, 0);
}
MUD_setHistGoodBin1(fd, i+1, 0);
MUD_setHistGoodBin2(fd, i+1, 0);
MUD_setHistBkgd1(fd, i+1, 0);
MUD_setHistBkgd2(fd, i+1, 0);
MUD_setHistNumEvents(fd, i+1, (UINT32)noOfEvents);
MUD_setHistTitle(fd, i+1, dummy);
REAL64 timeResolution = (fAny2ManyInfo->rebin*fData[0].GetTimeResolution())/1.0e9; // ns -> s
MUD_setHistSecondsPerBin(fd, i+1, timeResolution);
MUD_setHistData(fd, i+1, data);
}
MUD_closeWrite(fd);
delete [] data;
// check if mud file shall be streamed to stdout
if (fAny2ManyInfo->useStandardOutput && (fAny2ManyInfo->compressionTag == 0)) {
// stream file to stdout
ifstream is;
int length=1024;
char *buffer;
is.open(fln.Data(), ios::binary);
if (!is.is_open()) {
cerr << endl << "PRunDataHandler::WriteMudFile(): **ERROR** Couldn't open the mud-file for streaming." << endl;
remove(fln.Data());
return false;
}
// get length of file
is.seekg(0, ios::end);
length = is.tellg();
is.seekg(0, ios::beg);
if (length == -1) {
cerr << endl << "PRunDataHandler::WriteMudFile(): **ERROR** Couldn't determine the mud-file size." << endl;
remove(fln.Data());
return false;
}
// allocate memory
buffer = new char [length];
// read data as a block
while (!is.eof()) {
is.read(buffer, length);
cout.write(buffer, length);
}
is.close();
delete [] buffer;
// delete temporary root file
remove(fln.Data());
}
return true;
}
@ -3100,14 +3349,15 @@ Bool_t PRunDataHandler::WriteMudFile(TString fln)
*/
Bool_t PRunDataHandler::WriteAsciiFile(TString fln)
{
cout << endl << ">> PRunDataHandler::WriteAsciiFile(): writing an ascii data file... " << endl;
if (!fAny2ManyInfo->useStandardOutput)
cout << endl << ">> PRunDataHandler::WriteAsciiFile(): writing an ascii data file... " << endl;
// generate output file name
if (fln.Length() == 0) {
Int_t start = fRunPathName.Last('/');
Int_t end = fRunPathName.Last('.');
if ((start == -1) || (end == -1)) {
cout << endl << ">> PRunDataHandler::WriteAsciiFile(): **ERROR** couldn't generate the output file name ..." << endl;
if (end == -1) {
cerr << endl << ">> PRunDataHandler::WriteAsciiFile(): **ERROR** couldn't generate the output file name ..." << endl;
return false;
}
// cut out the filename (get rid of the extension, and the path)
@ -3122,12 +3372,14 @@ Bool_t PRunDataHandler::WriteAsciiFile(TString fln)
} else {
fln.Prepend(fAny2ManyInfo->outPath);
}
// keep the file name if compression is whished
fAny2ManyInfo->outFileList.push_back(fln);
// write ascii file
ofstream fout;
streambuf* strm_buffer = 0;
if (!fAny2ManyInfo->useStandardOutput) {
if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) {
// open data-file
fout.open(fln.Data(), ofstream::out);
if (!fout.is_open()) {
@ -3214,7 +3466,7 @@ Bool_t PRunDataHandler::WriteAsciiFile(TString fln)
cout << endl;
if (!fAny2ManyInfo->useStandardOutput) {
if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) {
// restore old output buffer
cout.rdbuf(strm_buffer);
@ -3486,12 +3738,15 @@ TString PRunDataHandler::FileNameFromTemplate(TString &fileNameTemplate, Int_t r
Int_t runLength = 0;
// find position and length of the year tag
Bool_t foundLeft = false, foundRight = false;
for (Int_t i=0; i<str.Length(); i++) {
if (str[i] == '[') {
foundLeft = true;
tag = 1;
continue;
} else if (str[i] == ']') {
foundRight = true;
tag = 0;
continue;
}
@ -3511,14 +3766,21 @@ TString PRunDataHandler::FileNameFromTemplate(TString &fileNameTemplate, Int_t r
ok = true;
}
if (foundLeft && !foundRight)
ok = false;
else
ok = true;
if (ok) {
// find position and length of the run tag
foundLeft = false, foundRight = false;
for (Int_t i=0; i<str.Length(); i++) {
if (str[i] == '[') {
foundLeft = true;
tag = 1;
continue;
} else if (str[i] == ']') {
foundRight = true;
tag = 0;
continue;
}

View File

@ -1838,5 +1838,5 @@ MUD_setHistSecondsPerBin( int fd, int num, REAL64 secondsPerBin )
{
if( secondsPerBin < 0.0 || secondsPerBin > 4294967295.0e-15 )
return( 0 );
return( MUD_setHistFsPerBin( fd, num, (1.0e15 * (UINT32)secondsPerBin ) ) );
return( MUD_setHistFsPerBin( fd, num, (UINT32)(1.0e15 * secondsPerBin ) ) );
}

View File

@ -568,17 +568,20 @@ typedef struct {
* <p>Holds the informations for the any2many converter program
*/
typedef struct {
Bool_t useStandardOutput; ///< flag showing if the converted shall be sent to the standard output
TString inFormat; ///< holds the information about the input data file format
TString outFormat; ///< holds the information about the output data file format
TString inTemplate; ///< holds the input file template
TString outTemplate; ///< holds the output file template
TString year; ///< holds the information about the year to be used
PIntVector runList; ///< holds the run number list to be converted
TString inFileName; ///< holds the file name of the input data file
TString outFileName; ///< holds the file name of the output data file
TString outPath; ///< holds the output path
UInt_t rebin; ///< holds the number of bins to be packed
Bool_t useStandardOutput; ///< flag showing if the converted shall be sent to the standard output
TString inFormat; ///< holds the information about the input data file format
TString outFormat; ///< holds the information about the output data file format
TString inTemplate; ///< holds the input file template
TString outTemplate; ///< holds the output file template
TString year; ///< holds the information about the year to be used
PIntVector runList; ///< holds the run number list to be converted
TString inFileName; ///< holds the file name of the input data file
TString outFileName; ///< holds the file name of the output data file
PStringVector outFileList; ///< holds the out path/file name
TString outPath; ///< holds the output path
UInt_t rebin; ///< holds the number of bins to be packed
UInt_t compressionTag; ///< 0=no compression, 1=gzip compression, 2=bzip2 compression
TString compressFileName; ///< holds the name of the outputfile name in case of compression is used
} PAny2ManyInfo;
#endif // _PMUSR_H_