Cat
Typedefs | Functions | Variables
Tools.h File Reference
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <time.h>
#include "StatusCode.h"
#include "var.h"

Go to the source code of this file.

Typedefs

typedef bool(* AskPrinter) (std::string)
 
typedef bool(* GraphPrinter) ()
 
typedef std::vector< bool > bits
 
typedef std::vector< std::string > commands
 

Functions

void setApplication (Application *)
 
Applicationapplication ()
 
void wait (int nbr_ms)
 
std::string itos (int)
 
std::string ftos (float)
 
std::string dtos (float)
 
int stoi (std::string)
 
std::vector< bool > itob (int, int)
 
std::string btos (std::vector< bool >)
 
double toDouble (std::string)
 
std::string command (std::string, std::vector< std::string > &)
 
StatusCode checkCmd (std::string, commands, vars &)
 
bool isInt (const char *)
 
bool isFloat (const char *)
 
bool askSvc (std::string)
 
std::string inputSvc (std::string)
 

Variables

unsigned int const BIT =1
 
unsigned int const OCTET =8
 

Detailed Description

Function tools

Author
Frederic Machefert
Date
2004-01-18

Definition in file Tools.h.

Typedef Documentation

◆ AskPrinter

typedef bool( * AskPrinter) (std::string)

Definition at line 36 of file Tools.h.

◆ bits

typedef std::vector<bool> bits

Definition at line 40 of file Tools.h.

◆ commands

typedef std::vector<std::string> commands

Definition at line 42 of file Tools.h.

◆ GraphPrinter

typedef bool( * GraphPrinter) ()

Definition at line 38 of file Tools.h.

Function Documentation

◆ application()

Application* application ( )

◆ askSvc()

bool askSvc ( std::string  )

Definition at line 242 of file Tools.cpp.

242  {
243  /*
244  AskPrinter asker = application() -> options() -> askPrinter ();
245  return asker ( msg);
246  */
247  return false;
248 }

◆ btos()

std::string btos ( std::vector< bool >  )

Conversion from binary (std::vector<std::string>) to std::string

Definition at line 67 of file Tools.cpp.

References itos().

Referenced by IOdata::dump().

67  {
68  int i=bits.size()-1;
69  std::string output;
70  while(i>=0){
71  output+=itos(bits[i]);
72  i--;
73  }
74  return output;
75 }
std::string itos(int i)
Definition: Tools.cpp:46
std::vector< bool > bits
Definition: Tools.h:40

◆ checkCmd()

StatusCode checkCmd ( std::string  ,
commands  ,
vars  
)

check the format of an instruction

Definition at line 126 of file Tools.cpp.

References application(), StatusCode::FAILURE, images::index, Object::info(), isFloat(), isInt(), cat::size, StatusCode::SUCCESS, and Object::warning().

126  {
127  int size = instruction.size();
128  if ( size<=0 ){
129  return StatusCode::FAILURE;
130  }
131 
132  // line is empty
133  if ( format.empty() || std::string::npos==format.find_first_not_of(' ') ) {
134  return StatusCode::FAILURE;
135  }
136 
137  // split the format in a vector of strings
138  // decode the main command
139  std::string line = std::string (format,
140  format.find_first_not_of(' ') ,
141  format.size());
142  std::vector<std::string> cmd;
143  std::string separator(1,' ');
144  unsigned int ipos = line.find( separator );
145  cmd.push_back ( std::string( line, 0, ipos ) );
146  if ( 0!=std::string ( line , 0 , ipos ).compare(instruction[0]) ){
147  application()->info(std::string ( line , 0 , ipos )+" "+instruction[0],"");
148  return StatusCode::FAILURE;
149  }
150 
151  unsigned int pos ;
152 
153  std::string str = line;
154  while ( ipos!=std::string::npos ){
155  std::string tmp = std::string (str, ipos , str.size());
156  str = tmp;
157  pos=str.find_first_not_of( ' ' );
158  if ( pos == std::string::npos ) {
159  break;
160  }
161  std::string arg;
162  ipos = str.find(separator,pos);
163 
164  if (ipos==std::string::npos){
165  arg = std::string(str , pos );
166  }
167  else {
168  arg = std::string(str , pos, ipos - 1);
169  }
170  cmd.push_back(arg);
171  }
172 
173  // check parameter number
174  if ( instruction.size() != cmd.size() ){
175  application()->info("wrong number of parameter. a enelver !!!!","");
176  return StatusCode::FAILURE;
177  }
178  // no parameter
179  if ( 1==cmd.size() ){
180  return StatusCode::SUCCESS;
181  }
182  // decode the format
183  for (unsigned int index = 1; index < cmd.size() ; ++index){
184  // int ?
185  if ( 0==cmd[index].compare("%i") || 0==cmd[index].compare("%I") ){
186  if ( !isInt ( instruction[index].c_str() ) ) {
187  application()->warning("We expect an integer parameter ["+instruction[index]+"]","checkCmd");
188  return StatusCode::FAILURE;
189  }
190  varlist.push_back ( var( atoi(instruction[index].c_str()) ) );
191  }
192  // float ?
193  if ( 0==cmd[index].compare("%f") || 0==cmd[index].compare("%F") ){
194  if ( !isFloat ( instruction[index].c_str() ) ) {
195  application()->warning("We expect a float parameter ["+instruction[index]+"]","checkCmd");
196  return StatusCode::FAILURE;
197  }
198  varlist.push_back( var ( atof(instruction[index].c_str()) ) );
199  }
200  }
201  return StatusCode::SUCCESS;
202 }
void info(std::string mymsg)
Definition: Object.h:38
Definition: var.h:19
def size
Definition: cat.py:38
bool isInt(const char *chain)
Definition: Tools.cpp:223
list index
Definition: images.py:1021
bool isFloat(const char *chain)
Definition: Tools.cpp:206
Application * application()
Definition: Tools.cpp:42
void warning(std::string mymsg)
Definition: Object.h:39

◆ command()

std::string command ( std::string  ,
std::vector< std::string > &   
)

extract vector of std::string out of a command

◆ dtos()

std::string dtos ( float  )

Conversion from double to std::string

◆ ftos()

std::string ftos ( float  )

Conversion from float to std::string

Definition at line 53 of file Tools.cpp.

Referenced by Processus::endProcessing(), PhaserRampExec::finalize(), Server_NI6008::setAIRange(), Server_NI6008::setAORange(), Server_NI6008::status(), and ICECALv3::version().

53  {
54  char val[20];
55  sprintf(val,"%f",f);
56  std::string str(val);
57  return str;
58 }
f
Definition: cat.py:54

◆ inputSvc()

std::string inputSvc ( std::string  )

Definition at line 259 of file Tools.cpp.

259  {
260  /*
261  InputSvc inp = application() -> options() -> inputSvc ();
262  return inp ( msg );
263  */
264  return std::string("not implemented.");
265 }

◆ isFloat()

bool isFloat ( const char *  )

check if string is compatible with float

Definition at line 206 of file Tools.cpp.

Referenced by checkCmd().

206  {
207  const char *pChain = chain;
208  while (*pChain!='\0') {
209  if ( *pChain!='0' && *pChain!='1' && *pChain!='2' && *pChain!='3' &&
210  *pChain!='4' && *pChain!='5' && *pChain!='6' && *pChain!='7' &&
211  *pChain!='8' && *pChain!='9' && *pChain!='+' && *pChain!='-' &&
212  *pChain!='.' ){
213  return false;
214  }
215  pChain++;
216  }
217  return true;
218 }

◆ isInt()

bool isInt ( const char *  )

check if string is compatible with int

Definition at line 223 of file Tools.cpp.

References application(), and Object::info().

Referenced by checkCmd().

223  {
224  const char *pChain = chain;
225  bool first = true;
226  while (*pChain!='\0') {
227  if ( ( *pChain<'0' || *pChain>'9' ) ){
228  application()->info(chain,"");
229  if ( !first || *pChain!='-' ){
230  return false;
231  }
232  }
233  first = false;
234  pChain++;
235  }
236  return true;
237 }
void info(std::string mymsg)
Definition: Object.h:38
Application * application()
Definition: Tools.cpp:42

◆ itob()

std::vector<bool> itob ( int  ,
int   
)

Conversion from integer to binary (std::string)

Definition at line 77 of file Tools.cpp.

Referenced by IOdata::dump().

77  {
78  int i=nbit-1;
79  int power;
80  std::vector<bool> bits(nbit);
81  // int limit=1<<(nbit-1);
82  //int vsat=(val<limit)?val:int(limit-1); //saturation
83  int vsat=val;
84  while(i>=0){
85  power=1<<i;
86  bits[i]=(vsat/power==1);
87  vsat=vsat%power;
88  i--;
89  }
90  return bits;
91 }
std::vector< bool > bits
Definition: Tools.h:40

◆ itos()

std::string itos ( int  )

Conversion from int (long) to std::string

Definition at line 46 of file Tools.cpp.

Referenced by DCU::acquire(), btos(), FEB_v1::calibCte(), MSOxxxx::channelDisplay(), MSOxxxx::channelDisplayName(), MSOxxxx::channelOffset(), MSOxxxx::channelScale(), ICECALv3::checkChNumber(), LSDelayChipV1::checkConfigAddr(), LSDelayChipV1::checkStatusAddr(), FEB_v1::clock80MHzFallingEdge(), FEB_v1::clockFallingEdge(), UsbFTInterface::close(), UsbFTMLInterface::close(), SpecsMezzanine::cmdline(), SpecsSlave::detect(), FEB_v1::disableSubtract(), IOdata::dump(), A3PE::dumpFromAX(), Processus::endProcessing(), Acquisition::execute(), PhaserRampExec::execute(), FEB_v1::FEB_v1(), PhaserRampExec::finalize(), FEB_v1::gain4(), FEB_v1::gbt80MHzClkEport(), FEB_v1::gbtAcknowledgeConfig(), FEB_v1::gbtDataPath(), FEB_v1::gbtDLLEport(), FEB_v1::gbtDLLReset(), FEB_v1::gbtEnableEport(), FEB_v1::gbtMode(), FEB_v1::gbtStatus(), FEB_v1::gbtTermEport(), FEB_v1::gbtTrackMode(), EmulateFE::generateFile(), ICECALv3::getAnalogCh(), LSDelayChipV1::getConfigReg(), ICECALv3::getDelayLineCh(), ICECALv3::getMainReg(), FEB_v1::globalPseudoPMEnable(), NI6008::init(), SpecsSlave::init(), SpecsMaster::init(), UsbFTMLInterface::init(), UsbFTInterface::init(), A3PE_BitFlip::initialize(), CurrentMeasurement::initialize(), FEB_v1::injectModeFE(), FEB_v1::latency(), FEB_v1::latencyLLT(), A3PE::loadFromAX(), Application::loadHistoryFile(), A3PE::loadPattern(), A3PE::loadStorage(), A3PE::loadToAX(), A3PE::loadTrigger(), Application::loop(), FEB_v1::maskLLT(), Data::name(), FEB_v1::oldSubtract(), MSOxxxx::open(), DLL::print(), FEB_v1::probeEnable(), FEB_v1::pseudoADCEnable(), FEB_v1::pseudoPMEnable(), Phaser::read(), ICPhaser::read(), UsbSpiBus::read(), UsbFTMLInterface::read(), UsbFTInterface::read(), SpecsMaster::reset(), SpecsSlave::reset(), FEB_v1::resetFE(), FEB_v1::resetFifoInjectFE(), FEB_v1::resetFifoSpyFE(), SpecsSlave::resetInternal(), Server_NI6008::Server_NI6008(), A3PE::setAddFromAXRam(), A3PE::setAddToAXRam(), A3PE::setAXRamUsb(), FEB_v1::setCalibCte(), FEB_v1::setClock80MHzFallingEdge(), A3PE::setClockDivision(), FEB_v1::setClockFallingEdge(), LSDelayChipV1::setConfigReg(), UsbSpiBus::setDataLength(), FEB_v1::setDisableSubtract(), A3PE::setEnableADC(), A3PE::setFifoDepth(), A3PE::setFifoLatency(), FEB_v1::setGain4(), FEB_v1::setGbt80MHzClkEport(), FEB_v1::setGbtClockStrength(), FEB_v1::setGbtDataPath(), FEB_v1::setGbtDLLEport(), FEB_v1::setGbtEnableEport(), FEB_v1::setGbtMode(), FEB_v1::setGbtTermEport(), FEB_v1::setGbtTrackMode(), FEB_v1::setGlobalPseudoPMEnable(), FEB_v1::setInjectModeFE(), A3PE::setInternalAXSequence(), FEB_v1::setLatency(), A3PE::setLatencyAX(), A3PE::setLengthAX(), A3PE::setNTrigger(), FEB_v1::setOldSubtract(), FEB_v1::setOutputEport(), Phaser::setPhase(), ICPhaser::setPhase(), A3PE::setPipeline(), FEB_v1::setPseudoADCEnable(), FEB_v1::setPseudoPMEnable(), RAM::setSize(), A3PE::setSoftwareTrigger(), FEB_v1::setSpareForTrigEnable(), SpecsMaster::setSpeed(), FEB_v1::setSpyModeFE(), FEB_v1::setStopInjLoop(), FEB_v1::setTestDuration(), FEB_v1::setThreshold(), A3PE::setTriggerDelay(), A3PE::setTriggerRate(), IOdata::setU16(), IOdata::setU32(), IOdata::setU8(), MSOxxxx::setupAvgVoltage(), MSOxxxx::setupDeltaTime(), MSOxxxx::setupJitter(), LSDelayChipV1::showConfig(), TestSuite::sigma(), FEB_v1::spareForTrigEnable(), SpecsI2c::SpecsI2c(), SpecsInterface::specsReadI2c(), SpecsInterface::specsReadParallel(), SpecsInterface::specsReadRegister(), SpecsInterface::specsWriteI2c(), SpecsInterface::specsWriteParallel(), SpecsInterface::specsWriteRegister(), ICECALv3::spiAddressScan(), LSDelayChipV1::spiBERTest(), FEB_v1::spyModeFE(), FEB_v1::spyModeSeq(), Server_NI6008::status(), FEB_v1::statusRegister(), FEB_v1::stopInjLoop(), Options::storageFullPath(), Application::terminate(), FEB_v1::testDuration(), FEB_v1::threshold(), Data::title(), MSOxxxx::triggerConfig(), UsbFTInterface::usbRead(), UsbFTMLInterface::usbRead(), UsbFTMLInterface::usbReadU16(), UsbFTInterface::usbReadU16(), UsbFTMLInterface::usbReadU32(), UsbFTInterface::usbReadU32(), UsbFTMLInterface::usbReadU8(), UsbFTInterface::usbReadU8(), UsbFTMLInterface::usbWrite(), UsbFTInterface::usbWrite(), UsbFTMLInterface::usbWriteRead(), UsbFTInterface::usbWriteRead(), UsbFTInterface::usbWriteU16(), UsbFTMLInterface::usbWriteU16(), UsbFTMLInterface::usbWriteU32(), UsbFTInterface::usbWriteU32(), UsbFTInterface::usbWriteU8(), UsbFTMLInterface::usbWriteU8(), Data::vectorPtr(), ICECALv3::version(), wait(), MSOxxxx::waveformCapture(), Phaser::write(), ICPhaser::write(), UsbSpiBus::write(), UsbFTMLInterface::write(), and UsbFTInterface::write().

46  {
47  char val[20];
48  sprintf(val,"%d",i);
49  std::string str(val);
50  return str;
51 }

◆ setApplication()

void setApplication ( Application )

Define entry point for the application

Definition at line 38 of file Tools.cpp.

References gui::cat.

Referenced by Application::Application().

38  {
39  gApp = cat;
40 }
cat
Definition: gui.py:104
Application * gApp
Definition: Tools.cpp:36

◆ stoi()

int stoi ( std::string  )

Conversion from binary (std::string) to integer

Definition at line 93 of file Tools.cpp.

References cat::size.

93  {
94  const unsigned int codage=2;
95  int result=0;
96  char h[codage]={'0','1'};
97  const unsigned int size=value.size();
98  const char* word=value.c_str();
99  unsigned int pos=0;
100  while (pos<size){
101  bool isSeen=false;
102  for (unsigned int j=0; j<codage && !isSeen; j++){
103  if (h[j]==word[pos]){
104  result+=int(j*pow(2.,(int)(size-pos-1)));
105  isSeen=true;
106  }
107  }
108  pos++;
109  }
110  return result;
111 }
def size
Definition: cat.py:38

◆ toDouble()

double toDouble ( std::string  )

Conversion from string (potentially with a comma) to a double

Definition at line 113 of file Tools.cpp.

113  {
114  // do not use a reference, since we're going to modify this string
115  // If you do not care about ',' or '.' in your string use a
116  // reference instead.
117  size_t found = s.find(",");
118  if(found != std::string::npos)
119  s[found]='.'; // Change ',' to '.'
120  return atof(s.c_str());
121 }

◆ wait()

void wait ( int  nbr_ms)

system wait for a few seconds

Definition at line 271 of file Tools.cpp.

References application(), itos(), and Object::verbose().

Referenced by ADCMeasurement::execute(), CurrentMeasurement::execute(), UsbFTInterface::init(), and UsbFTMLInterface::init().

272 {
273  application()->verbose("wait for "+itos(n)+" ms.","Tools::wait");
274 #ifdef WIN32
275  Sleep( n );
276 #else
277  usleep( 1000 * n );
278 #endif
279 }
void verbose(std::string mymsg)
Definition: Object.h:36
Application * application()
Definition: Tools.cpp:42
std::string itos(int i)
Definition: Tools.cpp:46

Variable Documentation

◆ BIT

unsigned int const BIT =1

Definition at line 44 of file Tools.h.

◆ OCTET

unsigned int const OCTET =8

Definition at line 45 of file Tools.h.