Skip to content

Commit

Permalink
manual output file
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Sep 25, 2024
1 parent f1d5242 commit 9f76615
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
21 changes: 12 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
Expand All @@ -43,8 +44,6 @@ using namespace std;
/*******************************************************************************
Constants types and global variables
*******************************************************************************/
char res_file[80] = {"\0"};
int save_res = 0;
int verbose = 4;
int format_ver = 2;
int pending_event = 0;
Expand Down Expand Up @@ -74,6 +73,14 @@ int SemaphoreId;
constexpr int MAX_SIGNALS = feminos_daq_storage::MAX_SIGNALS;
constexpr int MAX_POINTS = feminos_daq_storage::MAX_POINTS;

void removeRootExtension(std::string& filename) {
const std::string extension = ".root";
std::size_t pos = filename.rfind(extension);
if (pos != std::string::npos && pos == filename.length() - extension.length()) {
filename.erase(pos); // Remove the extension
}
}

template<typename T>
void stringIpToArray(const std::string& ip, T* ip_array) {
// we assume ip is a valid IP (this has to be checked beforehand)
Expand Down Expand Up @@ -150,7 +157,7 @@ int main(int argc, char** argv) {
->check(CLI::ValidIPV4);
app.add_option("-i,--input", input_file, "Read commands from file specified")
->group("File Options");
app.add_option("-o,--output", output_file, "Save results in file specified (DOES NOT WORK!)")
app.add_option("-o,--output", output_file, "Save results in file specified")
->group("File Options");
app.add_option("-d,--output-directory", output_directory, "Output directory. This can also be specified via the environment variable 'FEMINOS_DAQ_OUTPUT_DIRECTORY' or 'RAWDATA_PATH'")
->group("File Options");
Expand Down Expand Up @@ -207,12 +214,8 @@ int main(int argc, char** argv) {
stringIpToArray(local_ip, femarray.loc_ip);

if (!output_file.empty()) {
if (output_file.length() > 80) {
std::cerr << "Output file name is too long" << std::endl;
return 1;
}
strcpy(res_file, output_file.c_str());
save_res = 1;
removeRootExtension(output_file);
storage_manager.output_filename_manual = output_file;
}

if (!input_file.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/mclient/cmdfetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Constants types and global variables
*******************************************************************************/
#define CMD_ARRAY_SIZE 25000
#define CMD_LINE_SIZE 120
#define CMD_LINE_SIZE 200

typedef struct _CmdFetcher {
int id;
Expand Down
15 changes: 9 additions & 6 deletions src/mclient/evbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ int EventBuilder_FileAction(EventBuilder* eb,
if (readOnly) { return 0; }

struct tm* now;
char name[120];
char name[200];
time_t start_time;
char str_res[4];
char str_ext[8];
Expand Down Expand Up @@ -1026,8 +1026,7 @@ int EventBuilder_FileAction(EventBuilder* eb,
now->tm_sec);
*/
sprintf(eb->run_str,
"R%05d_%s_Vm_%s_Vd_%s_Pr_%s_Gain_%s_Shape_%"
"s_Clock_%s",
"R%05d_%s_Vm_%s_Vd_%s_Pr_%s_Gain_%s_Shape_%s_Clock_%s",
runNumber, runTagStr, meshVoltageStr,
driftFieldStr, detectorPressureStr, gainStr,
shapingStr, clockStr);
Expand Down Expand Up @@ -1087,7 +1086,13 @@ int EventBuilder_FileAction(EventBuilder* eb,
const auto output_directory = feminos_daq_storage::StorageManager::Instance().GetOutputDirectory();
sprintf(&(eb->file_path[0]), "%s", output_directory.c_str());

char filename_root[120] = {};
auto& storage_manager = feminos_daq_storage::StorageManager::Instance();
if (!storage_manager.output_filename_manual.empty()) {
// clear strings (c-string)
eb->file_path = {"\0"};
eb->run_str = storage_manager.output_filename_manual;
}
char filename_root[200] = {};
sprintf(filename_root, "%s/%s.%s", &(eb->file_path[0]),
&(eb->run_str[0]), "root");
cout << "Root file name : " << filename_root << endl;
Expand All @@ -1113,8 +1118,6 @@ int EventBuilder_FileAction(EventBuilder* eb,

printf("Opening file : %s\n", name);

auto& storage_manager = feminos_daq_storage::StorageManager::Instance();

// This loop is entered for every subrun, so we need to make sure this is only initialized once
if (!storage_manager.IsInitialized()) {
storage_manager.Initialize(filename_root);
Expand Down
2 changes: 1 addition & 1 deletion src/mclient/evbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct _EventBuilder {

void* fa; // pointer to FEM Array

char file_path[120]; // result file path
char file_path[200]; // result file path
int savedata; // 0: do not save data; 1: save to disk in ASCII; 2: save to disk in binary
FILE* fout; // output file pointer

Expand Down
2 changes: 2 additions & 0 deletions src/root/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class StorageManager {
std::string run_comments;
std::string run_commands;

std::string output_filename_manual;

float run_drift_field_V_cm_bar = 0.0;
float run_mesh_voltage_V = 0.0;
float run_detector_pressure_bar = 0.0;
Expand Down

0 comments on commit 9f76615

Please sign in to comment.