1414#include " ITSMFTSimulation/AlpideSimResponse.h"
1515#include < TFile.h>
1616#include < TSystem.h>
17+ #include < stdexcept>
1718#include < cstdio>
1819#include < cstddef>
1920#include < fstream>
2021#include < iostream>
2122#include < string>
2223
23- void alpideResponse (const std::string& inpath = " ./" ,
24- const std::string& outpath = " ./" ,
25- const std::string& response_file = " AlpideResponseData.root" )
24+ void alpideResponse (const std::string& inpath, const std::string& outpath, const std::string& chip_name)
2625{
26+ // Check input path validity
27+ if (gSystem ->AccessPathName (inpath.c_str ())) {
28+ throw std::invalid_argument (" Input path does not exist or is inaccessible: " + inpath);
29+ }
30+
31+ // Check output path validity
32+ if (gSystem ->AccessPathName (outpath.c_str (), kWritePermission )) {
33+ throw std::invalid_argument (" Output path is not writable: " + outpath);
34+ }
2735
2836 o2::itsmft::AlpideSimResponse resp0, resp1;
2937
30- resp0.initData (0 , inpath.data ());
31- resp1.initData (1 , inpath.data ());
38+ if (chip_name == " Alpide" ) {
39+ resp0.initData (0 , inpath.c_str ());
40+ resp1.initData (1 , inpath.c_str ());
41+ } else if (chip_name == " APTS" ) {
42+ resp1.setColMax (1.5e-4 );
43+ resp1.setRowMax (1.5e-4 );
44+ resp1.initData (1 , inpath.c_str ());
45+ } else {
46+ throw std::invalid_argument (" Unknown chip name: " + chip_name);
47+ }
3248
33- auto file = TFile::Open ((outpath + response_file).data (), " recreate" );
34- file->WriteObjectAny (&resp0, " o2::itsmft::AlpideSimResponse" , " response0" );
49+ std::string output_file = outpath + " /" + chip_name + " ResponseData.root" ;
50+ auto file = TFile::Open (output_file.c_str (), " recreate" );
51+
52+ if (!file || file->IsZombie ()) {
53+ throw std::runtime_error (" Failed to create output file: " + output_file);
54+ } else if (chip_name == " Alpide" ) {
55+ file->WriteObjectAny (&resp0, " o2::itsmft::AlpideSimResponse" , " response0" );
56+ }
3557 file->WriteObjectAny (&resp1, " o2::itsmft::AlpideSimResponse" , " response1" );
3658 file->Close ();
59+ delete file;
3760}
3861
3962int main (int argc, const char * argv[])
4063{
4164 namespace bpo = boost::program_options;
4265 bpo::variables_map vm;
43- bpo::options_description options (" Alpide reponse generator options" );
44- options.add_options ()(
45- " inputdir,i" , bpo::value<std::string>()->default_value (" ./" ), " Path where Vbb-0.0V and Vbb-3.0V are located." )(
46- " outputdir,o" , bpo::value<std::string>()->default_value (" ./" ), " Path where to store the output." )(
47- " name,n" , bpo::value<std::string>()->default_value (" AlpideResponseData.root" ), " Output file name." );
66+ bpo::options_description options (" Alpide response generator options" );
67+ options.add_options ()(" inputdir,i" , bpo::value<std::string>()->default_value (" ./" ), " Path where Vbb-0.0V and Vbb-3.0V are located." )(" outputdir,o" , bpo::value<std::string>()->default_value (" ./" ), " Path where to store the output." )(" chip,c" , bpo::value<std::string>()->default_value (" Alpide" ), " Chip name (Alpide or APTS)." );
4868
4969 try {
5070 bpo::store (parse_command_line (argc, argv, options), vm);
71+
5172 if (vm.count (" help" )) {
5273 std::cout << options << std::endl;
53- return 1 ;
74+ return 0 ;
5475 }
76+
5577 bpo::notify (vm);
5678 } catch (const bpo::error& e) {
5779 std::cerr << e.what () << " \n\n " ;
5880 std::cerr << " Error parsing command line arguments. Available options:\n " ;
59-
6081 std::cerr << options << std::endl;
6182 return 2 ;
6283 }
6384
64- std::cout << " Generating " << vm[" inputdir" ].as <std::string>() + vm[" name" ].as <std::string>() << std::endl;
65- alpideResponse (vm[" inputdir" ].as <std::string>(), vm[" outputdir" ].as <std::string>(), vm[" name" ].as <std::string>());
85+ try {
86+ std::cout << " Generating response for chip: " << vm[" chip" ].as <std::string>() << std::endl;
87+ std::cout << " Input directory: " << vm[" inputdir" ].as <std::string>() << std::endl;
88+ std::cout << " Output directory: " << vm[" outputdir" ].as <std::string>() << std::endl;
89+
90+ alpideResponse (vm[" inputdir" ].as <std::string>(),
91+ vm[" outputdir" ].as <std::string>(),
92+ vm[" chip" ].as <std::string>());
93+ std::cout << " Response file generated successfully." << std::endl;
94+ } catch (const std::exception& e) {
95+ std::cerr << " Error: " << e.what () << std::endl;
96+ return 1 ;
97+ }
6698
6799 return 0 ;
68- }
100+ }
0 commit comments