added some more sanity checks for dump_header.
All checks were successful
Build and Deploy Documentation / build-and-deploy (push) Successful in 19s

This commit is contained in:
2025-11-12 17:56:33 +01:00
parent 5ae66a0614
commit 4ab01f4faf

View File

@@ -201,22 +201,39 @@ int dump_header_root(const std::string fileName, const bool summary, const bool
std::cout << std::endl << "Detector Info (for all detectors the same): "; std::cout << std::endl << "Detector Info (for all detectors the same): ";
std::cout << std::endl << "-------------------"; std::cout << std::endl << "-------------------";
std::cout << std::endl << "Histo Length : " << runHeader->GetNChannels(); std::cout << std::endl << "Histo Length : " << runHeader->GetNChannels();
double *timeZero; double *timeZero = nullptr;
timeZero = runHeader->GetTimeZero(); timeZero = runHeader->GetTimeZero();
std::cout << std::endl << "Time Zero Bin : " << timeZero[0]; if (timeZero != nullptr) {
std::cout << std::endl << "First Good Bin : " << timeZero[0]; std::cout << std::endl << "Time Zero Bin : " << timeZero[0];
std::cout << std::endl << "First Good Bin : " << timeZero[0];
} else {
std::cout << std::endl << "Time Zero Bin : ??";
std::cout << std::endl << "First Good Bin : ??";
}
std::cout << std::endl << "Last Good Bin : " << runHeader->GetNChannels()-1; std::cout << std::endl << "Last Good Bin : " << runHeader->GetNChannels()-1;
std::cout << std::endl << "-------------------" << std::endl << std::endl; std::cout << std::endl << "-------------------" << std::endl << std::endl;
} else { // MusrRoot } else { // MusrRoot
// invoke the MusrRoot header object // invoke the MusrRoot header object
header = std::make_unique<TMusrRunHeader>(fileName.c_str(), true); // read quite header = std::make_unique<TMusrRunHeader>(fileName.c_str(), true); // read quite
if (header == nullptr) {
std::cerr << std::endl << "**ERROR** Couldn't invoke MusrRoot RunHeader from file:" << fileName;
std::cerr << std::endl;
f.Close();
return 1;
}
// check if TFolder or TDirectory is needed // check if TFolder or TDirectory is needed
if (fileType == DH_MUSR_ROOT) { // TFolder if (fileType == DH_MUSR_ROOT) { // TFolder
f.GetObject("RunHeader", folder); f.GetObject("RunHeader", folder);
if (folder == nullptr) {
std::cerr << std::endl << "**ERROR** Couldn't get folder from MusrRoot RunHeader from file:" << fileName;
std::cerr << std::endl;
f.Close();
return 1;
}
// try to populate the MusrRoot header object // try to populate the MusrRoot header object
if (!header->ExtractAll(folder)) { if (!header->ExtractAll(folder)) {
std::cerr << std::endl << "**ERROR** Couldn't invoke MusrRoot RunHeader in file:" << fileName; std::cerr << std::endl << "**ERROR** Couldn't invoke MusrRoot RunHeader content from file:" << fileName;
std::cerr << std::endl; std::cerr << std::endl;
f.Close(); f.Close();
return 1; return 1;
@@ -224,6 +241,12 @@ int dump_header_root(const std::string fileName, const bool summary, const bool
} else { // TDirectory } else { // TDirectory
TDirectoryFile *runHeader = nullptr; TDirectoryFile *runHeader = nullptr;
f.GetObject("RunHeader", runHeader); f.GetObject("RunHeader", runHeader);
if (runHeader == nullptr) {
std::cerr << std::endl << "**ERROR** Couldn't get runHeader (TDirectory) from MusrRoot RunHeader from file:" << fileName;
std::cerr << std::endl;
f.Close();
return 1;
}
// try to populate the MusrRoot header object // try to populate the MusrRoot header object
if (!header->ExtractAll(runHeader)) { if (!header->ExtractAll(runHeader)) {
std::cerr << std::endl << "**ERROR** Couldn't invoke MusrRoot RunHeader in file:" << fileName; std::cerr << std::endl << "**ERROR** Couldn't invoke MusrRoot RunHeader in file:" << fileName;
@@ -543,6 +566,7 @@ int dump_header_mud(const std::string fileName, const bool counts)
int success; int success;
char fln[256]; char fln[256];
memset(fln, '\0', sizeof(fln));
strncpy(fln, fileName.c_str(), sizeof(fln)); strncpy(fln, fileName.c_str(), sizeof(fln));
fh = MUD_openRead(fln, &type); fh = MUD_openRead(fln, &type);
if (fh == -1) { if (fh == -1) {
@@ -572,9 +596,12 @@ int dump_header_mud(const std::string fileName, const bool counts)
tval = static_cast<time_t>(val); tval = static_cast<time_t>(val);
if (success) { if (success) {
dt = localtime(static_cast<const time_t*>(&tval)); dt = localtime(static_cast<const time_t*>(&tval));
assert(dt); if (dt != nullptr) {
strftime(str, sizeof(str), "%F; %T", dt); strftime(str, sizeof(str), "%F; %T", dt);
std::cout << std::endl << "Run Start Time : " << str; std::cout << std::endl << "Run Start Time : " << str;
} else {
std::cout << std::endl << "Run Start Time : ??";
}
} else { } else {
std::cout << std::endl << "Run Start Time : ???"; std::cout << std::endl << "Run Start Time : ???";
} }
@@ -583,9 +610,12 @@ int dump_header_mud(const std::string fileName, const bool counts)
tval = static_cast<time_t>(val); tval = static_cast<time_t>(val);
if (success) { if (success) {
dt = localtime(static_cast<const time_t*>(&tval)); dt = localtime(static_cast<const time_t*>(&tval));
assert(dt); if (dt != nullptr) {
strftime(str, sizeof(str), "%F; %T", dt); strftime(str, sizeof(str), "%F; %T", dt);
std::cout << std::endl << "Run Stop Time : " << str; std::cout << std::endl << "Run Stop Time : " << str;
} else {
std::cout << std::endl << "Run Stop Time : ??";
}
} else { } else {
std::cout << std::endl << "Run Stop Time : ???"; std::cout << std::endl << "Run Stop Time : ???";
} }
@@ -780,10 +810,14 @@ int dump_current_year()
time_t rawtime; time_t rawtime;
struct tm *timeinfo; struct tm *timeinfo;
char buffer[32]; char buffer[32];
memset(buffer, '\0', sizeof(buffer));
time (&rawtime); time (&rawtime);
timeinfo = localtime(&rawtime); timeinfo = localtime(&rawtime);
strftime(buffer, 32, "%Y", timeinfo); if (timeinfo != nullptr)
strftime(buffer, 32, "%Y", timeinfo);
else
strncpy(buffer, "1900", sizeof(buffer));
return atoi(buffer); return atoi(buffer);
} }
@@ -940,13 +974,14 @@ int main(int argc, char *argv[])
// invoke the startup handler in order to get the default search paths to the data files // invoke the startup handler in order to get the default search paths to the data files
// read startup file // read startup file
char startup_path_name[128]; char startup_path_name[128];
memset(startup_path_name, '\0', sizeof(startup_path_name));
std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>(); std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
std::unique_ptr<PStartupHandler> startupHandler = std::make_unique<PStartupHandler>(); std::unique_ptr<PStartupHandler> startupHandler = std::make_unique<PStartupHandler>();
if (!startupHandler->StartupFileFound()) { if (!startupHandler->StartupFileFound()) {
std::cerr << std::endl << ">> musrfit **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data(); std::cerr << std::endl << ">> musrfit **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
std::cerr << std::endl; std::cerr << std::endl;
} else { } else {
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data()); strncpy(startup_path_name, startupHandler->GetStartupFilePath().Data(), sizeof(startup_path_name));
saxParser->ConnectToHandler("PStartupHandler", startupHandler.get()); saxParser->ConnectToHandler("PStartupHandler", startupHandler.get());
//status = saxParser->ParseFile(startup_path_name); //status = saxParser->ParseFile(startup_path_name);
// parsing the file as above seems to lead to problems in certain environments; // parsing the file as above seems to lead to problems in certain environments;