#include #include #include #include #include "TFile.h" #include "TMap.h" #include "TObjString.h" #include "TVectorT.h" #include "AliTPCCalROC.h" #include "AliTPCCalPad.h" using namespace std; //========================================================================================== // Stuff for ARGP const char *argp_program_version = "makeCalPad.app (Revision" TPC_REVISION ")"; const char *argp_program_bug_address = ""; static char doc[] = "This program converts text files with configuration data to root files."; static char args_doc[] = "FILE1 [FILE2 ...] (ALTRO and/or RCU config files)"; //========================================================================================== // The options ARGP understands static struct argp_option options[] = { {"verbose", 'v', 0, 0, "Produce verbose output" }, {"quiet", 'q', 0, 0, "Don't produce any output" }, {"outfile", 'o', "FILE", 0, "Specify output file (default: ALTROConfig.root)" }, { 0 } }; //========================================================================================== // Used by main to communicate with ARGP parse_opt struct arguments { int silent, verbose; char **input_files; char *output_file; }; //========================================================================================== //Get the input argument from argp_parse, which is a pointer to the ARGP arguments structure. static error_t parse_opt (int key, char *arg, struct argp_state *state) { struct arguments *arguments = (struct arguments*)state->input; switch (key) { // Parse a single option case 'q': arguments->silent = 1; break; case 'v': arguments->verbose = 1; break; case 'o': arguments->output_file = arg; break; case ARGP_KEY_ARG: arguments->input_files = &state->argv[state->next-1]; state->next = state->argc; break; case ARGP_KEY_END: if (state->arg_num < 1) argp_usage(state); // Not enough arguments break; default: return ARGP_ERR_UNKNOWN; } return 0; } //========================================================================================== static struct argp argp = { options, parse_opt, args_doc, doc }; //========================================================================================== //========================================================================================== //========================================================================================== int main (int argc, char **argv) { // // Main function. Convert config file in ASCII format to rootfile with CalPad objects. // // Objects which contain the values per pad AliTPCCalPad Masked, ZsThr, AcqStart, AcqStop, FPED, K1, K2, K3, L1, L2, L3; // ALTRO values int test, roc, padrow, pad, mask, fped, zsthr, aqstart, aqstop, ch_off_ctr, k1, k2, k3, l1, l2, l3; // RCU values int rcuON, cstb_delay, clk_ratio, nsam_ev, dis_rdyrx, sparse_rdo, meb_mode, l1_latency; int l1_window, l1_msg_lat_min, l1_msg_lat_max, l2_lat_min, l2_lat_max, roi_lat_min, roi_lat_max; int roi_conf1, roi_conf2, cdh_version, trg_mode, ddl; // RCU output values TVectorT CSTB_DELAY(216), CLK_RATIO(216), NSAM_EV(216), SPARSE_RDO(216), MEB_MODE(216); TVectorT L1_LATENCY(216), L1_WINDOW(216), L1_MSG_LAT_MIN(216), L1_MSG_LAT_MAX(216); TVectorT L2_LAT_MIN(216), L2_LAT_MAX(216), TRG_MODE(216), ROI_LAT_MIN(216); TVectorT ROI_LAT_MAX(216), ROI_CONF1(216), ROI_CONF2(216), CDH_VERSION(216); for (int ii=0; ii<216; ii++) { NSAM_EV[ii] = -1; CLK_RATIO[ii] = -1; CSTB_DELAY[ii] = -1; SPARSE_RDO[ii] = -1; MEB_MODE[ii] = -1; //DIS_RDYRX[ii] = -1; CDH_VERSION[ii] = -1; L1_LATENCY[ii] = -1; L1_WINDOW[ii] = -1; L1_MSG_LAT_MIN[ii] = -1; L1_MSG_LAT_MAX[ii] = -1; L2_LAT_MIN[ii] = -1; L2_LAT_MAX[ii] = -1; ROI_CONF1[ii] = -1; ROI_CONF2[ii] = -1; ROI_LAT_MIN[ii] = -1; ROI_LAT_MAX[ii] = -1; TRG_MODE[ii] = -1; } struct arguments arguments; // Default values arguments.silent = 0; arguments.verbose = 0; arguments.output_file = "ALTROconfig.root"; // Parse arguments; every option seen by parse_opt will be reflected in arguments argp_parse (&argp, argc, argv, 0, 0, &arguments); TFile *rootfile = new TFile(arguments.output_file, "recreate"); TMap RCUconfig; TObjArray toa(12); ch_off_ctr = 0; for (int j = 0; arguments.input_files[j]; j++) { ifstream ifs(arguments.input_files[j], ifstream::in); // open file if ( !ifs.good() ) { if (!arguments.silent) cerr << "*Error: File " << arguments.input_files[j] << " can not be opened!" << endl; continue; } else if (!arguments.silent) cout << "*Opening file " << arguments.input_files[j] << "!" << endl; // test file ifs >> test; if ( (test != 98) && (test != 99) ) { if (!arguments.silent) cerr << "*Error: File seems not to be a configuration file!" << endl; continue; } if ( test == 98 ) { // RCU config if ( !arguments.silent && arguments.verbose ) cout << "*It contains RCU config data!" << endl; // Loop over file content and fill cal pad objects while ( ifs >> ddl >> rcuON >> nsam_ev >> clk_ratio >> cstb_delay >> sparse_rdo >> meb_mode >> dis_rdyrx >> cdh_version >> l1_latency >> l1_window >> l1_msg_lat_min >> l1_msg_lat_max >> l2_lat_min >> l2_lat_max >> roi_conf1 >> roi_conf2 >> roi_lat_min >> roi_lat_max >> trg_mode && !ifs.eof() ) { if ( rcuON && (ddl>=0) && (ddl<216) ) { NSAM_EV[ddl] = nsam_ev; CLK_RATIO[ddl] = clk_ratio; CSTB_DELAY[ddl] = cstb_delay; SPARSE_RDO[ddl] = sparse_rdo; MEB_MODE[ddl] = meb_mode; //DIS_RDYRX[ddl] = dis_rdyrx; CDH_VERSION[ddl] = cdh_version; L1_LATENCY[ddl] = l1_latency; L1_WINDOW[ddl] = l1_window; L1_MSG_LAT_MIN[ddl] = l1_msg_lat_min; L1_MSG_LAT_MAX[ddl] = l1_msg_lat_max; L2_LAT_MIN[ddl] = l2_lat_min; L2_LAT_MAX[ddl] = l2_lat_max; ROI_CONF1[ddl] = roi_conf1; ROI_CONF2[ddl] = roi_conf2; ROI_LAT_MIN[ddl] = roi_lat_min; ROI_LAT_MAX[ddl] = roi_lat_max; TRG_MODE[ddl] = trg_mode; } } } else if ( test == 99 ) { // ALTRO config if ( !arguments.silent && arguments.verbose ) cout << "*It contains ALTRO config data!" << endl; // Loop over file content and fill cal pad objects while ( ifs >> roc >> padrow >> pad >> mask >> fped >> zsthr >> aqstart >> aqstop >> k1 >> k2 >> k3 >> l1 >> l2 >> l3 && !ifs.eof() ) { // Is this a new ROC? if ( !Masked.GetCalROC(roc) ) { if ( !arguments.silent && arguments.verbose ) cout << "*Found ROC " << roc << endl; Masked.SetCalROC(new AliTPCCalROC(roc), roc); ZsThr.SetCalROC(new AliTPCCalROC(roc), roc); AcqStart.SetCalROC(new AliTPCCalROC(roc), roc); AcqStop.SetCalROC(new AliTPCCalROC(roc), roc); FPED.SetCalROC(new AliTPCCalROC(roc), roc); K1.SetCalROC(new AliTPCCalROC(roc), roc); K2.SetCalROC(new AliTPCCalROC(roc), roc); K3.SetCalROC(new AliTPCCalROC(roc), roc); L1.SetCalROC(new AliTPCCalROC(roc), roc); L2.SetCalROC(new AliTPCCalROC(roc), roc); L3.SetCalROC(new AliTPCCalROC(roc), roc); } // Fill Masked.GetCalROC(roc)->SetValue(padrow, pad, mask); ZsThr.GetCalROC(roc)->SetValue(padrow, pad, zsthr); AcqStart.GetCalROC(roc)->SetValue(padrow, pad, aqstart); AcqStop.GetCalROC(roc)->SetValue(padrow, pad, aqstop); FPED.GetCalROC(roc)->SetValue(padrow, pad, fped); K1.GetCalROC(roc)->SetValue(padrow, pad, k1); K2.GetCalROC(roc)->SetValue(padrow, pad, k2); K3.GetCalROC(roc)->SetValue(padrow, pad, k3); L1.GetCalROC(roc)->SetValue(padrow, pad, l1); L2.GetCalROC(roc)->SetValue(padrow, pad, l2); L3.GetCalROC(roc)->SetValue(padrow, pad, l3); if (mask==1) ch_off_ctr++; } } // end if test file ifs.close(); } // // Fill RCU parameters // RCUconfig.Add(new TObjString("ALTROIF_NSAM_EV"), &NSAM_EV); RCUconfig.Add(new TObjString("ALTROIF_CLK_RATIO"), &CLK_RATIO); RCUconfig.Add(new TObjString("ALTROIF_CSTB_DELAY"), &CSTB_DELAY); RCUconfig.Add(new TObjString("RDOMOD_SPARSE_RDO"), &SPARSE_RDO); RCUconfig.Add(new TObjString("RDOMOD_MEB_MODE"), &MEB_MODE); //RCUconfig.Add(new TObjString("RDOMOD_DISABLE_RDYRX"), &DIS_RDYRX); RCUconfig.Add(new TObjString("TTC_CONTROL_CDH_VERSION"), &CDH_VERSION); RCUconfig.Add(new TObjString("TTC_L1_LATENCY"), &L1_LATENCY); RCUconfig.Add(new TObjString("TTC_L1_LATENCY_WINDOW"), &L1_WINDOW); RCUconfig.Add(new TObjString("TTC_L1_MSG_LATENCY_MIN"), &L1_MSG_LAT_MIN); RCUconfig.Add(new TObjString("TTC_L1_MSG_LATENCY_MAX"), &L1_MSG_LAT_MAX); RCUconfig.Add(new TObjString("TTC_L2_LATENCY_MIN"), &L2_LAT_MIN); RCUconfig.Add(new TObjString("TTC_L2_LATENCY_MAX"), &L2_LAT_MAX); RCUconfig.Add(new TObjString("TTC_ROI_CONFIG1"), &ROI_CONF1); RCUconfig.Add(new TObjString("TTC_ROI_CONFIG2"), &ROI_CONF2); RCUconfig.Add(new TObjString("TTC_ROI_LATENCY_MIN"), &ROI_LAT_MIN); RCUconfig.Add(new TObjString("TTC_ROI_LATENCY_MAX"), &ROI_LAT_MAX); RCUconfig.Add(new TObjString("TRGCONF_TRG_MODE"), &TRG_MODE); // Set Names Masked.SetName("Masked"); ZsThr.SetName("ZsThr"); AcqStart.SetName("AcqStart"); AcqStop.SetName("AcqStop"); FPED.SetName("FPED"); K1.SetName("K1"); K2.SetName("K2"); K3.SetName("K3"); L1.SetName("L1"); L2.SetName("L2"); L3.SetName("L3"); // RCUconfig.SetName("RCUconfig"); //RCUconfig.SetOwnerKeyValue(true, true); // Combine all in TObjArray toa.Add(&Masked); toa.Add(&ZsThr); toa.Add(&AcqStart); toa.Add(&AcqStop); toa.Add(&FPED); toa.Add(&K1); toa.Add(&K2); toa.Add(&K3); toa.Add(&L1); toa.Add(&L2); toa.Add(&L3); // toa.Add(&RCUconfig); toa.Write("AltroConfig", TCollection::kSingleKey); delete rootfile; rootfile = 0; if ( !arguments.silent ) cout << "*Wrote " << arguments.output_file << endl; if ( !arguments.silent && arguments.verbose ) cout << "*Found " << ch_off_ctr << " masked channels." << endl; return 0; } // EOF