Skip to content

Commit

Permalink
adding more clear command line inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorgoth committed Dec 2, 2017
1 parent 39bf110 commit e63fcaf
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 102 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ CPPFLAGS := $(shell root-config --cflags) -I$(INC)/include
LDFLAGS := $(shell root-config --glibs)
CPPFLAGS += -g -std=c++14

TARGET = dat2root
SRC = app/dat2root.cc src/Aux.cc src/Config.cc
TARGET = ConvertDat2Root
SRC = app/ConvertDat2Root.cc src/Aux.cc src/Config.cc

TARGET2 = Rereco
SRC2 = app/datroot2root.cc src/Aux.cc src/Config.cc
SRC2 = app/Rereco.cc src/Aux.cc src/Config.cc

TARGET3 = dat2rootPixels
SRC3 = app/dat2rootPixels.cc src/Aux.cc src/Config.cc
TARGET3 = ConvertDat2RootWithPixels
SRC3 = app/ConvertDat2RootWithPixels.cc src/Aux.cc src/Config.cc

TARGET4 = SkimTree
SRC4 = app/SkimTree.cc
Expand Down Expand Up @@ -48,4 +48,4 @@ $(TARGET4) : $(OBJ4)
@echo $@
$(CXX) $(CPPFLAGS) -o $@ -c $<
clean :
rm -f *.o src/*.o $(Aux)/src/*.o $(TARGET) $(TARGET2) $(TARGET3) $(TARGET4) *~
rm -f *.o app/*.o src/*.o $(Aux)/src/*.o $(TARGET) $(TARGET2) $(TARGET3) $(TARGET4) *~
120 changes: 99 additions & 21 deletions app/dat2root.cc → app/ConvertDat2Root.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@ TStyle* style;

int graphic_init();

std::string ParseCommandLine( int argc, char* argv[], std::string opt )
{
for (int i = 1; i < argc; i++ )
{
std::string tmp( argv[i] );
if ( tmp.find( opt ) != std::string::npos )
{
if ( tmp.find( "=" ) != std::string::npos ) return tmp.substr( tmp.find_last_of("=") + 1 );
if ( tmp.find( "--" ) != std::string::npos ) return "yes";
}
}

return "";
};


int main(int argc, char **argv) {
gROOT->SetBatch();
Expand All @@ -53,8 +38,99 @@ int main(int argc, char **argv) {
std::cerr << "Usage: dat2root in_file.dat num_events" << std::endl;
return -1;
}


std::cout << "\n=== Beginning program ===\n" << std::endl;

//****************************************
// Getting Input FileName (CAEN DRS4 file)
//****************************************
std::string inputFileName = ParseCommandLine( argc, argv, "--inputFileName=" );
if ( inputFileName == "" )
{
std::cerr << "[ERROR]: please provide a valid inputFileName. Use: --inputFileName=<your_input_file_name> " << std::endl;
exit(0);
}

//*******************************
// Getting Output FileName (ROOT)
//*******************************
std::string outputFileName = ParseCommandLine( argc, argv, "--outputFileName=" );
if ( outputFileName == "" )
{
std::cerr << "[ERROR]: please provide a valid outputFileName. Use: --outputFileName=<your_output_file_name> " << std::endl;
exit(0);
}

//*****************************************
// Getting number of events to be processed
//*****************************************
std::string nEvents = ParseCommandLine( argc, argv, "--nEvents=" );
if ( nEvents == "" )
{
std::cerr << "[ERROR]: please provide a valid nEvents. Use: --nEvents=<events_to_process> " << std::endl;
exit(0);
}
int nevents = atoi(nEvents.c_str());

std::cout << "[INFO]: input file --> " << inputFileName << std::endl;
std::cout << "[INFO]: output file --> " << outputFileName << std::endl;
std::cout << "[INFO]: processing --> " << nEvents << " events" << std::endl;

//****************************
// Getting channel config file
//****************************
std::string configName = ParseCommandLine( argc, argv, "--config=" );
if ( configName == "" )
{
configName = "config/15may2017.config";
std::cout << "[INFO]: using default config file: " << configName << ". Use: --config=<config_file> to set your config" << std::endl;
}

//*********************************************************
// Check if has valid input file, otherwise exit with error
//*********************************************************
ifstream ifile(inputFileName);
if (!ifile)
{
std::cerr << "[ERROR]: !USAGE! Input file does not exist. Please enter valid file name" << std::endl;
exit(0);
}

//******************************************************************
// Board number is fixed at 1 for now because we only have one board
//******************************************************************
std::string boardNumber = "1";
std::cout << "[INFO]: will use calibration files for board number " << boardNumber << "\n";

//*********************************************************
// Check if has valid input file, otherwise exit with error
//*********************************************************
bool saveRaw = false;
std::string _saveRaw = ParseCommandLine( argc, argv, "--saveRaw" );
if ( _saveRaw == "yes" )
{
saveRaw = true;
std::cout << "[INFO]: Will save raw pulses" << std::endl;
}

bool drawDebugPulses = false;
std::string _drawDebugPulses = ParseCommandLine( argc, argv, "--debug" );
if ( _drawDebugPulses == "yes" )
{
drawDebugPulses = true;
std::cout << "[INFO]: Will draw pulse to check procedure" << std::endl;
}

std::cout << "\n=== Parsing configuration file " << configName << " ===\n" << std::endl;
Config config(configName);
if ( !config.hasChannels() || !config.isValid() ) {
std::cerr << "\nFailed to load channel information from config " << configName << std::endl;
return -1;
}


/*
std::string inputFilename = argv[1];
std::string outputFilename = argv[2];
std::cout << "Input file: " << inputFilename << std::endl;
Expand Down Expand Up @@ -101,7 +177,9 @@ int main(int argc, char **argv) {
std::cerr << "\nFailed to load channel information from config " << configName << std::endl;
return -1;
}
*/


//**************************************
// Load Voltage Calibration
//**************************************
Expand Down Expand Up @@ -155,7 +233,7 @@ int main(int argc, char **argv) {
// Define output
//**************************************

TFile* file = new TFile( outputFilename.c_str(), "RECREATE", "CAEN V1742");
TFile* file = new TFile( outputFileName.c_str(), "RECREATE", "CAEN V1742");
TTree* tree = new TTree("pulse", "Digitized waveforms");

int event;
Expand Down Expand Up @@ -219,21 +297,21 @@ int main(int argc, char **argv) {
// Open Input File
//*************************

FILE* fpin = fopen( inputFilename.c_str(), "r" );
FILE* fpin = fopen( inputFileName.c_str(), "r" );

//*************************
//Event Loop
//*************************

std::cout << "\n=== Processing input data ===\n" << std::endl;
int nGoodEvents = 0;
int maxEvents = nEvents;
if (nEvents < 0) maxEvents = 999999;
int maxEvents = nevents;
if (nevents < 0) maxEvents = 999999;
for( int iEvent = 0; iEvent < maxEvents; iEvent++){

if ( iEvent % 100 == 0 ) {
if (nEvents >= 0) {
std::cout << "Event " << iEvent << " of " << nEvents << std::endl;
if (nevents >= 0) {
std::cout << "Event " << iEvent << " of " << nevents << std::endl;
} else {
std::cout << "Event " << iEvent << "\n";
}
Expand Down
Loading

0 comments on commit e63fcaf

Please sign in to comment.