DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parsers.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_PARSERS_H
14 #define DD4HEP_PARSERS_H 1
15 // ============================================================================
16 // Include files
17 // ============================================================================
18 // STD & STL
19 // ============================================================================
20 #include <string>
21 #include <vector>
22 #include <list>
23 #include <set>
24 #include <map>
25 #include <deque>
26 
27 // ============================================================================
28 #define PARSERS_DECL_FOR_SINGLE(Type) \
29  int parse(Type& result, const std::string& input);
30 
31 #define PARSERS_DECL_FOR_PAIR(FirstType, SecondType) \
32  int parse(std::pair<FirstType, SecondType >& result,const std::string& input);
33 
34 #if defined(DD4HEP_HAVE_ALL_PARSERS)
35 #define PARSERS_DECL_FOR_LIST(InnerType) \
36  int parse(std::vector<InnerType >& result,const std::string& input); \
37  int parse(std::list<InnerType >& result,const std::string& input); \
38  int parse(std::set<InnerType >& result,const std::string& input); \
39  int parse(std::deque<InnerType >& result,const std::string& input); \
40  int parse(std::map<std::string,InnerType >& result,const std::string& input); \
41  int parse(std::map<int,InnerType >& result,const std::string& input); \
42  int parse(std::map<unsigned long,InnerType >& result,const std::string& input); \
43  int parse(std::pair<std::string,InnerType >& result,const std::string& input); \
44  int parse(std::pair<int,InnerType >& result,const std::string& input); \
45  int parse(std::pair<unsigned long,InnerType >& result,const std::string& input);
46 
47 #else
48 
49 #define PARSERS_DECL_FOR_LIST(InnerType) \
50  int parse(std::vector<InnerType >& result,const std::string& input); \
51  int parse(std::list<InnerType >& result,const std::string& input); \
52  int parse(std::set<InnerType >& result,const std::string& input); \
53  int parse(std::map<std::string,InnerType >& result,const std::string& input); \
54  int parse(std::map<int,InnerType >& result,const std::string& input); \
55  int parse(std::pair<std::string,InnerType >& result,const std::string& input); \
56  int parse(std::pair<int,InnerType >& result,const std::string& input);
57 
58 #endif // DD4HEP_HAVE_ALL_PARSERS
59 
60 // ============================================================================
92 // ============================================================================
93 
95 namespace DD4hep {
97  namespace Parsers {
98 
99  // ========================================================================
101 
111  // ========================================================================
113 
123 #if defined(DD4HEP_HAVE_ALL_PARSERS)
126  PARSERS_DECL_FOR_SINGLE(unsigned char)
128  PARSERS_DECL_FOR_SINGLE(signed char)
129 #endif
130  // ========================================================================
132 
145 #if defined(DD4HEP_HAVE_ALL_PARSERS)
149  PARSERS_DECL_FOR_SINGLE(unsigned short)
151  PARSERS_DECL_FOR_SINGLE(unsigned int)
153  PARSERS_DECL_FOR_SINGLE(unsigned long)
155  PARSERS_DECL_FOR_SINGLE(long long)
157  PARSERS_DECL_FOR_SINGLE(unsigned long long)
158 #endif
159  // ========================================================================
161 
174 #if defined(DD4HEP_HAVE_ALL_PARSERS)
175  PARSERS_DECL_FOR_SINGLE(long double)
177 #endif
178  // ========================================================================
190  PARSERS_DECL_FOR_SINGLE(std::string)
191  // ========================================================================
192 
196  PARSERS_DECL_FOR_LIST(double)
197  PARSERS_DECL_FOR_LIST(float)
198  PARSERS_DECL_FOR_LIST(std::string)
199 
200 #if defined(DD4HEP_HAVE_ALL_PARSERS)
202  PARSERS_DECL_FOR_LIST(unsigned char)
203  PARSERS_DECL_FOR_LIST(signed char)
204  PARSERS_DECL_FOR_LIST(short)
205  PARSERS_DECL_FOR_LIST(unsigned short)
206  PARSERS_DECL_FOR_LIST(unsigned int)
207  PARSERS_DECL_FOR_LIST(unsigned long)
208  PARSERS_DECL_FOR_LIST(long long)
209  PARSERS_DECL_FOR_LIST(unsigned long long)
210  PARSERS_DECL_FOR_LIST(long double)
211 #endif
212 
213  // ========================================================================
214  // Advanced parses
215  // ========================================================================
217 
228  PARSERS_DECL_FOR_PAIR(double, double)
229  // ========================================================================
242  PARSERS_DECL_FOR_PAIR(int, int)
243  // ========================================================================
244 
245 
246 
258  int parse(std::vector<std::pair<double, double> >& result, const std::string& input);
259  // ========================================================================
261 
273  int parse(std::vector<std::pair<int, int> >& result, const std::string& input);
274  // ========================================================================
275  // vector< vector< TYPE > >
276  // ========================================================================
278 
289  int parse(std::vector<std::vector<std::string> >& result, const std::string& input);
290  // ========================================================================
292 
303  int parse(std::vector<std::vector<double> >& result, const std::string& input);
304  // ========================================================================
305  // map< TYPE, TYPE >
306  // ========================================================================
308 
319  int parse(std::map<int, int>& result, const std::string& input);
320  // ========================================================================
322 
334  int parse(std::map<int, double>& result, const std::string& input);
335  // ========================================================================
337 
348  int parse(std::map<std::string, std::string>& result, const std::string& input);
349  // ========================================================================
351 
363  int parse(std::map<std::string, int>& result, const std::string& input);
364  // ========================================================================
366 
378  int parse(std::map<std::string, double>& result, const std::string& input);
379  // ========================================================================
381 
394  int parse(std::map<std::string, std::vector<std::string> >& result, const std::string& input);
395  // ========================================================================
397 
411  int parse(std::map<std::string, std::vector<int> >& result, const std::string& input);
412  // ========================================================================
414 
428  int parse(std::map<std::string, std::vector<double> >& result, const std::string& input);
429  // ========================================================================
431 
437  int parse(std::map<int, std::string>& result, const std::string& input);
438 
439  // ========================================================================
441 
447 #if defined(DD4HEP_HAVE_ALL_PARSERS)
448  int parse(std::map<unsigned int, std::string>& result, const std::string& input);
449 
450  // ========================================================================
452 
455  int parse(std::map<std::string, unsigned int>& result, const std::string& input);
456 #endif
457 
458  // ========================================================================
460 
485  int parse(std::string& name, std::string& value, const std::string& input);
486 
487  // ========================================================================
489 
499  int parse(std::map<std::string, std::pair<double, double> >& params, const std::string& input);
500 
501  // ========================================================================
503 
509  template <class T, unsigned int N>
510  int parse(T (&result)[N], const std::string& input) {
511  typedef std::vector<T> _Vct;
512  // create the temporary vector
513  _Vct tmp;
514  int sc = parse(tmp, input);
515  if (!sc) {
516  return sc;
517  } // RETURN
518  if (N != tmp.size()) {
519  return 0;
520  } // RETURN
521  //
522  std::copy(tmp.begin(), tmp.end(), result);
523  //
524  return 1; // RETURN
525  }
526  // ========================================================================
528 
534  template <unsigned int N>
535  int parse(char (&result)[N], const std::string& input) {
536  // clear the string
537  std::fill_n(result, N, ' ');
538  // create the temporary string
539  std::string tmp;
540  int sc = parse(tmp, input);
541  if (!sc) {
542  return sc;
543  } // RETURN
544  if (N == tmp.size()) {
545  std::copy(tmp.begin(), tmp.end(), result);
546  }
547  else if (N + 2 == tmp.size() && ('\'' == tmp[0] || '\"' == tmp[0]) && (tmp[0] == tmp[tmp.size() - 1])) {
548  std::copy(tmp.begin() + 1, tmp.end() - 1, result);
549  }
550  else {
551  return 0;
552  }
553  //
554  return 1; // RETURN
555  }
556  // ========================================================================
557  }// end of namespace Parsers
558  // ==========================================================================
559 }// end of namespace DD4hep
560 
561 #ifndef DD4HEP_PARSERS_NO_ROOT
562 
563 #include "Math/Point3D.h"
564 #include "Math/Vector3D.h"
565 #include "Math/Vector4D.h"
566 
567 namespace ROOT {
568  namespace Math {
570  bool operator<(const XYZPoint& a, const XYZPoint& b);
572  bool operator<(const XYZVector& a, const XYZVector& b);
574  bool operator<(const PxPyPzEVector& a, const PxPyPzEVector& b);
575  }
576 }
577 
579 namespace DD4hep {
581  namespace Parsers {
582 
583  // ========================================================================
585 
619  int parse(ROOT::Math::XYZPoint& result, const std::string& input);
620 
621  // ========================================================================
623 
657  int parse( ROOT::Math::XYZVector& result, const std::string& input);
658 
659  // ========================================================================
661 
728  int parse(ROOT::Math::PxPyPzEVector& result, const std::string& input);
729 
730  // ========================================================================
732 
737  PARSERS_DECL_FOR_LIST(ROOT::Math::XYZPoint)
738 
739  // ========================================================================
741 
746  PARSERS_DECL_FOR_LIST(ROOT::Math::XYZVector)
747 
748  // ========================================================================
750 
755  PARSERS_DECL_FOR_LIST(ROOT::Math::PxPyPzEVector)
756  // ========================================================================
757  }// end of namespace Parsers
758  // ==========================================================================
759 }// end of namespace DD4hep
760 #endif
761 // ============================================================================
762 // The END
763 // ============================================================================
764 #endif // DD4HEP_PARSERS_H
765 // ============================================================================
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
#define PARSERS_DECL_FOR_LIST(InnerType)
Definition: Parsers.h:49
#define PARSERS_DECL_FOR_SINGLE(Type)
Definition: Parsers.h:28
bool operator<(const XYZPoint &a, const XYZPoint &b)
Allow point insertion of a point in maps.
int parse(Property &result, const std::string &input)
#define PARSERS_DECL_FOR_PAIR(FirstType, SecondType)
Definition: Parsers.h:31