20 const std::string& delimiters)
23 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
25 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
28 while (std::string::npos != pos || std::string::npos != lastPos)
31 tokens.push_back(str.substr(lastPos, pos - lastPos));
33 lastPos = str.find_first_not_of(delimiters, pos);
35 pos = str.find_first_of(delimiters, lastPos);
44 std::string::size_type firstPos = str.find_first_of(delim,position);
45 if(firstPos==std::string::npos)
return -1;
48 firstPos = str.find_first_of(delim,position+1);
49 if(firstPos==std::string::npos)
return -1;
61 const char *start_delim,
const char *end_delim,
int order){
63 if(firstPos<0)
return std::string();
64 std::string::size_type lastPos = str.find_first_of(end_delim,firstPos+1);
65 if(lastPos==std::string::npos)
return std::string();
66 int length = lastPos - firstPos - 1;
67 return str.substr(firstPos+1, length);
71 int *ptr =
reinterpret_cast<int*
>(&buffer[position]);
76 int64_t *ptr =
reinterpret_cast<int64_t*
>(&buffer[position]);
81 int8_t *ptr =
reinterpret_cast<int8_t*
>(&buffer[position]);
86 std::cout <<
"************************************************" << std::endl;
87 std::cout <<
"* >=< : --------------------- *" << std::endl;
88 std::cout <<
"* ,.--' ''-. : HIPO 4.0 I/O Library *" << std::endl;
89 std::cout <<
"* ( ) ',_.' : Jefferson National Lab *" << std::endl;
90 std::cout <<
"* Xx'xX : Date: 01/24/2019 *" << std::endl;
91 std::cout <<
"************************************************" << std::endl;
92 std::cout << std::endl;
97 header.append(
"//***********************************************************************\n");
98 header.append(
"//***********************************************************************\n");
99 header.append(
"// ____ ____ _____ _______ ___ ______ __ \n");
100 header.append(
"// |_ || _||_ _||_ __ \\ .' `. / ____ `. / | \n");
101 header.append(
"// | |__| | | | | |__) |/ .-. \\ `' __) | `| | \n");
102 header.append(
"// | __ | | | | ___/ | | | | _ |__ '. | | \n");
103 header.append(
"// _| | | |_ _| |_ _| |_ \\ `-' / | \\____) | _ _| |_ \n");
104 header.append(
"// |____||____||_____||_____| `.___.' \\______.'(_)|_____| \n");
105 header.append(
"// \n");
106 header.append(
"//======================================================================= \n");
107 header.append(
"// Autogenerated code by HIPO 3.1 io library\n");
108 header.append(
"// Modify the main loop to suite your needs\n");
109 header.append(
"// Date: \n");
110 header.append(
"//***********************************************************************\n");
115 std::string file_header;
117 file_header.append(comments);
118 file_header.append(
"#include <cstdlib>\n#include <iostream>\n\n");
119 file_header.append(
"#include \"reader.h\"\n#include \"node.h\"\n");
120 file_header.append(
"\nint main(int argc, char** argv) {\n");
121 file_header.append(
" std::cout << \" reading file example program (HIPO) \" << std::endl;\n");
122 file_header.append(
" char inputFile[256];\n\n" );
123 file_header.append(
" if(argc>1) {\n sprintf(inputFile,\"%s\",argv[1]);\n } else {\n " );
124 file_header.append(
" std::cout << \" *** please provide a file name...\" << std::endl;\n" );
125 file_header.append(
" exit(1);\n }\n\n");
126 file_header.append(
" hipo::reader reader;\n");
127 file_header.append(
" reader.open(inputFile);\n\n" );
131 std::string file_trailer;
132 file_trailer.append(
"\n");
133 file_trailer.append(
" //----------------------------------------------------\n");
134 file_trailer.append(
" //-- Main LOOP running through events and printing\n");
135 file_trailer.append(
" //-- values of the first decalred branch\n");
136 file_trailer.append(
" //----------------------------------------------------\n");
137 file_trailer.append(
" int entry = 0;\n");
138 file_trailer.append(
" while(reader.next()==true){\n");
139 file_trailer.append(
" entry++;\n");
140 file_trailer.append(
" std::cout << \"event # \" << entry << std::endl;\n");
141 file_trailer.append(code);
142 file_trailer.append(
" }\n");
143 file_trailer.append(
" //----------------------------------------------------\n");
144 file_trailer.append(
"}\n");
145 file_trailer.append(
"//###### ENF OF GENERATED FILE #######\n");
149 std::string std__string;
150 std__string.append(
"#=================================================\n");
151 std__string.append(
"# The SCONSTRUCT file for building HIPO project.\n");
152 std__string.append(
"# \n");
153 std__string.append(
"#=================================================\n");
154 std__string.append(
"import glob\n");
155 std__string.append(
"import os\n");
156 std__string.append(
"import sys\n");
157 std__string.append(
"#=================================================\n");
158 std__string.append(
"# LOADING THE ENVIRONMENT\n");
159 std__string.append(
"#=================================================\n");
160 std__string.append(
"env = Environment(CPPPATH=[\"include\",\".\",\"/usr/include\",\"/usr/local/include\",\"/opt/local/include\",\"/group/clas12/packages/lz4/lib\",\"/group/clas12/packages/hipo-io/libcpp\"])\n");
161 std__string.append(
"env.Append(ENV = os.environ)\n");
162 std__string.append(
"env.Append(CPPPATH=[\"src/root\",\"src/evio\"])\n");
163 std__string.append(
"env.Append(CCFLAGS=[\"-O2\",\"-fPIC\",\"-m64\",\"-fmessage-length=0\",\"-g\"])\n");
164 std__string.append(
"env.Append(LIBPATH=[\"/opt/local/lib\",\"/usr/lib\",\"/usr/local/lib\",\"/group/clas12/packages/lz4/lib\",\"lib\",\"/group/clas12/packages/hipo-io/lib\"])\n");
165 std__string.append(
"env.Append(CONFIGUREDIR=[\"/group/clas12/packages/lz4/lib\",\"/group/clas12/packages/hipo-io/lib\"])\n");
166 std__string.append(
"#=================================================\n");
167 std__string.append(
"# Check for compression libraries.\n");
168 std__string.append(
"#=================================================\n");
169 std__string.append(
"conf = Configure(env)\n");
170 std__string.append(
"\n");
171 std__string.append(
"if conf.CheckLib('libhipo'):\n");
172 std__string.append(
" print '\\n\\033[32m[**] >>>>> found library : HIPO'\n");
173 std__string.append(
" print ''\n");
174 std__string.append(
" env.Append(CCFLAGS=\"-D__HIPO__\")\n");
175 std__string.append(
" \n");
176 std__string.append(
"if conf.CheckLib('liblz4'):\n");
177 std__string.append(
" print '\\n\\033[32m[**] >>>>> found library : LZ4'\n");
178 std__string.append(
" print '[**] >>>>> enabling lz4 compression. \\033[0m'\n");
179 std__string.append(
" print ''\n");
180 std__string.append(
" env.Append(CCFLAGS=\"-D__LZ4__\")\n");
181 std__string.append(
"\n");
182 std__string.append(
"if conf.CheckLib('libz'):\n");
183 std__string.append(
" print '\\n\\033[32m[**] >>>>> found library : libz'\n");
184 std__string.append(
" print '[**] >>>>> enabling gzip compression. \\033[0m'\n");
185 std__string.append(
" print ''\n");
186 std__string.append(
" env.Append(CCFLAGS=\"-D__LIBZ__\")\n");
187 std__string.append(
"#=================================================\n");
188 std__string.append(
"# BUILDING EXECUTABLE PROGRAM\n");
189 std__string.append(
"#=================================================\n");
190 std__string.append(
"runFileLoop = env.Program(target=\"runFileLoop\",source=[\"runFileLoop.cc\"])\n");
203 printf(
"[benchmark] %24s : time = %12.4f \n", benchmarkName.c_str(),
getTimeSec());
208 second = clock.now();
209 std::chrono::nanoseconds diff_ms =
210 std::chrono::duration_cast< std::chrono::nanoseconds >( second-first );
212 running_time += diff_ms.count();
220 return running_time*1e-9;
int getCounter()
Returns the number of resume/pause cycles recorded.
void resume()
Starts or resumes the timer.
void pause()
Pauses the timer and accumulates elapsed time.
double getTimeSec()
Returns the accumulated time in seconds.
void show()
Prints the benchmark name, accumulated time, and counter.
long getTime()
Returns the accumulated time in microseconds.
static std::string getFileHeader()
Returns the file header template string.
static void writeByte(char *buffer, int position, uint8_t value)
Writes a single byte into a byte buffer at the given position.
static std::string substring(const std::string &str, const char *start_delim, const char *end_delim, int order)
Extracts a substring between two delimiters.
static std::string getSConstruct()
Returns the SCons build configuration string.
static void writeLong(char *buffer, int position, long value)
Writes a 64-bit long into a byte buffer at the given position.
utils()
Default constructor.
static std::string getFileTrailer(const char *code)
Returns the file trailer template string.
static std::string getHeader()
Returns the HIPO header string for code generation.
static void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
Splits a string into tokens using the given delimiters.
static void printLogo()
Prints the HIPO library logo to standard output.
static int findposition(const std::string &str, const char *delim, int order)
Finds the position of the nth occurrence of a delimiter.
static void writeInt(char *buffer, int position, int value)
Writes a 32-bit integer into a byte buffer at the given position.
Utility functions and benchmark timer for HIPO library operations.