Condition DAQ condition condition 2 3 XML key value

Similar documents
解きながら学ぶC++入門編

Java演習(4) -- 変数と型 --

double float

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

新版明解C言語 実践編

ohp03.dvi


double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

とても使いやすい Boost の serialization

programmingII2019-v01

r03.dvi

1.3 ( ) ( ) C

K227 Java 2

第5回お試しアカウント付き並列プログラミング講習会

cpp1.dvi

SystemC言語概論

プログラミング及び演習 第1回 講義概容・実行制御

新・明解C言語 実践編

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

r07.dvi

ohp07.dvi

untitled

2017_08_ICN研究会_印刷用

I 2 tutimura/ I 2 p.1/??

tuat1.dvi

exec.dvi

r08.dvi

Microsoft Word - C.....u.K...doc

新・明解Java入門

ex01.dvi

untitled

program.dvi

PowerPoint Presentation

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

fp.gby

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

ohp08.dvi

slide5.pptx

RHEA key

コーディング基準.PDF


Java updated

cpp4.dvi

VMware Player Scientific Linux 5.x 6.x 7.x RPM

design_pattern.key

cpp2.dvi

プログラミング及び演習 第1回 講義概容・実行制御

‚æ4›ñ

ex01.dvi

C

CX-Checker CX-Checker (1)XPath (2)DOM (3) 3 XPath CX-Checker. MISRA-C 62%(79/127) SQMlint 76%(13/17) XPath CX-Checker 3. CX-Checker 4., MISRA-C CX- Ch

VB.NETコーディング標準

グラフと組み合わせ 課題 7 ( 解答例 ) 2013/5/27 1 列挙 n 個の文字の集合 { } S = a, a,, an の全てからなる文字列 つまり同じ文字を含まない 長さ n の文字列を列挙する 方法を考える 1. 何通りの文字列があるかを答えなさい また そのことが正しい

1.ppt

(Eclipse\202\305\212w\202\324Java2\215\374.pdf)

新・明解C言語 ポインタ完全攻略

intra-mart Accel Platform — イベントナビゲータ 開発ガイド   初版  


Smalltalk_

SystemC 2.0を用いた簡易CPUバスモデルの設計

8 if switch for while do while 2

新コンフィギュレータのフレームワークについて

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

Java プログラミング Ⅰ 3 回目変 数 今日の講義講義で学ぶ内容 変数とは 変数の使い方 キーボード入力の仕方 変 数 変 数 一時的に値を記憶させておく機能 変数は 型 ( データ型 ) と識別子をもちます 2 型 ( データ型 ) 変数に記憶する値の種類変数の型は 記憶できる値の種類と範囲

解きながら学ぶJava入門編

新版 明解C++入門編

CM-3G 周辺モジュール拡張技術文書 MS5607センサ(温度、気圧)

J.JSSAC Vol. 7, No. 2, Mathematica Maple,., Open asir Open xxx asir. Open xxx Open asir, asir., Open xxx, Linux Open asir Open sm1 (kan/sm1). C

JavaプログラミングⅠ

ValueHolder... 9 Customer.java Oracle TopLink 10g(10.1.3) È Volume3 2

Microsoft PowerPoint - CproNt02.ppt [互換モード]

#include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 sta

For_Beginners_CAPL.indd

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

Exam : 1z1-809-JPN Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z1-809-JPN Exam's Question and Answers 1 from Ac

Copyright c 2008 Zhenjiang Hu, All Right Reserved.

Parametric Polymorphism

Microsoft PowerPoint pptx

P6dark P6dark µ-pic 2 µ-pic 2 3 µ-pic µ-pic µ-pic 3 µ-pic (10cm ) MPGC N3035-KA195 No. SN ASD (16ns[C]) (16nsC

解きながら学ぶC++入門編

6-1

BW BW

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

ex12.dvi

listings-ext

:30 12:00 I. I VI II. III. IV. a d V. VI

file:///D|/C言語の擬似クラス.txt

パターン化されたロジックのコンポーネント化

WinHPC ppt

untitled

Q&A集

yacc.dvi

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 条件判断文 3 switch 文 switch 文式が case の値と一致した場合 そこから直後の break; までを処理し どれにも一致しない場合 default; から直後の break; までを処理する 但し 式や値 1

ソフトゼミC 第二回 C++の基礎

C++ TR1 / Boost C++ Library概要

A/B (2018/06/08) Ver kurino/2018/soft/soft.html A/B

Transcription:

Condition DAQ condition 2009 6 10 2009 7 2 2009 7 3 2010 8 3 1 2 2 condition 2 3 XML key value 3 4 4 4.1............................. 5 4.2...................... 5 5 6 6 Makefile 7 7 9 7.1 Condition.h............................. 9 7.2 ConditionSample.h......................... 11 8 11

2 CONDITION 1 condition DAQ configuration DAQ condition configuration XML condition configuration URL 2 condition condition DAQ XML configuration XML DAQ JSON DAQ XML configuration DAQ JSO N C++ DAQ XML/JSON XML JSON XML JSON XML XML <?xml version="1.0" encoding="utf-8"?> <condition> <daq id="0"> <module id="0"> <type>test0</type> <value>0</value> </module> <module id="1"> <type>test1</type> <value>1</value> </module> </daq> </condition> XML JSON % Xalan o condition-tmp.json condition.xml xml2json-with-attribute.xslt 2

3 XML KEY VALUE % python extract.py condition-tmp.json > condition.json DAQ-Middleware 1.0.0 /usr/bin/condition xml2json condition_xml2json condition.xml JSON (JSON ) ( 1 ): {"condition":{"daq":{"@id":0,"module":[{"@id":0,"type":"test0","value":0, {"@id":1,"type":"test1","value":1] JSON DAQ Condition 3 XML key value XML DAQ key value XML key value XML tag attribute Attribute id tag condition tag condition tag key tag attribute _ XML <daq id="0"> <module id="0"> <type>test0</type> key daq_0_module_0_type value test0 value string digit(hex/dec) XML key DAQ prefix daq_0_module_0_ prefix DAQ type find 3

4 4 DAQ string type int value sampleparam struct sampleparam { std::string type; int value; ; typedef struct sampleparam sampleparam; ConditionSample include #include <string> #include Condition.h class ConditionSample : public Condition { public: ConditionSample(); virtual ~ConditionSample(); bool initialize(std::string file); bool getparam(std::string prefix, sampleparam* sampleparam); private: Json2ConList m_json2conlist; conlist m_conlistsample; ; Json2ConList conlist JSON key value std::map key value private getparam ConditionSample getparam prefix getparam key key ConditionSample.h prefix+ type key prefix+ value key sampleparam false 4

4.1 4 bool ConditionSample::getParam(std::string prefix, sampleparam* sampleparam) { setprefix(prefix); std::string type; int value; if( find("type", &type)) { sampleparam->type = type; std::cout << prefix+ "type = " << type << std::endl; else { std::cout << prefix + "type is not found" << std::endl; return false; if( find("value", &value) ) { sampleparam->value = value; std::cout << prefix+ "value = " << value << std::endl; else { std::cout << prefix + "value is not found" << std::endl; return false; return true; 4.1 initialize file JSON m json2conlist.makeconlist bool ConditionSample::initialize(std::string file) { if (m_json2conlist.makeconlist(file, &m_conlistsample) == false) { std::cerr << "### ERROR: Failed to read the Condition file" << std::endl; std::cerr << "### Condition file: " << file << std::endl; return false; init(&m_conlistsample); return true; conlist 4.2 Sample.h #include ConditionSample.h Sample.cpp 5

5 #include <iostream> #include Sample.h int main() { ConditionSample mycondition; try { if (!mycondition.initialize("condition.json")) { std::cerr << "initialization error" << std::endl; return 0; sampleparam sampleparam; sampleparams sampleparams; if (mycondition.getparam("daq_0_module_0_", &sampleparam)) sampleparams.push_back(sampleparam); else throw "error for getting daq_0_module_0_"; if (mycondition.getparam("daq_0_module_1_", &sampleparam)) sampleparams.push_back(sampleparam); else throw "error for getting daq_0_module_1_"; catch (const char* str) { std::cerr << str << std::endl; catch (...) { std::cerr << "some error..." << std::endl; 5 Condition.h condition ConditionSample Sample Json2ConList conlist Condition 6

6 MAKEFILE #include <iostream> #include <string> #include "Condition.h" int main(int argc, char** argv) { Json2ConList m_json2conlist; conlist m_conlist; Condition m_condition; std::string file = argv[1]; if (m_json2conlist.makeconlist(file, &m_conlist) == false) { std::cerr << "### ERROR: Failed to read the Condition file" << std::endl; std::cerr << "### Condition file: " << "condition.json" << std::endl; m_condition.init(&m_conlist); std::string prefix = argv[2]; m_condition.setprefix(prefix); std::string type; int value; if (m_condition.find("type", &type)) { std::cout << prefix+ "type = " << type << std::endl; else { std::cout << prefix + "type is not found" << std::endl; return false; if( m_condition.find("value", &value) ) { std::cout << prefix+ "value = " << value << std::endl; else { std::cout << prefix + "value is not found" << std::endl; return false; 6 Makefile Sample Simple JSON JSON spirit JSON spirit json spirit.h include libjsonspirit.so JSON condition List json2conlist.h(class Json2ConList) Condition.h DAQ- Middleware 1.0.0 /usr/ include/daqmw/ /usr/lib/daqmw/ Makefile boost regex CC = g++ PROG = Sample CXXFLAGS = -g -O0 -Wall CPPFLAGS += -I/usr/include/daqmw LDLIBS += -L/usr/lib/daqmw -ljsonspirit -lboost_regex 7

6 MAKEFILE all: $(PROG) OBJS += ConditionSample.o OBJS += Sample.o $(PROG): $(OBJS) $(PROG).o: $(PROG).cpp $(PROG).h ConditionSample.o: ConditionSample.cpp ConditionSample.h Condition.h clean: rm -f *.o ${PROG./Sample ConditionSample created key: daq_0_module_0_type daq_0_module_0_type = test0 key: daq_0_module_0_value daq_0_module_0_value = 0 key: daq_0_module_1_type daq_0_module_1_type = test1 key: daq_0_module_1_value daq_0_module_1_value = 1 ConditionSample deleted Simple %./Simple condition.json daq_0_module_0_ key: daq_0_module_0_type daq_0_module_0_type = test0 key: daq_0_module_0_value daq_0_module_0_value = 0 8

7 7 7.1 Condition.h 1 #ifndef CONDITION_H 2 #define CONDITION_H 3 4 #include <ctype.h> 5 #include "json2conlist.h" 6 7 class Condition 8 { 9 public: 10 Condition() {; 11 ~Condition() {; 12 13 public: 14 void init(conlist* clist) { 15 m_clist = clist; 16 m_prefix = ""; 17 18 19 void setprefix(std::string prefix) { 20 m_prefix = prefix; 21 22 23 bool find(std::string key, void* value) { 24 std::cerr << "key: " << m_prefix << key << std::endl; 25 conit it = m_clist->find(m_prefix+key); 26 if (it == m_clist->end()) { 27 // cerr << "not find!" << endl; 28 return false; 29 30 31 std::string second = it->second; 32 type t = check(second); 33 switch (t) { 34 case type_digit: 35 case type_xdigit: 36 char *e; 37 *(unsigned int*)value = (unsigned int)strtoul(second.c_str(), &e, 0); 38 break; 39 default: // type_string 40 *(std::string *)value = second.c_str(); 41 break; 42 43 return true; 44 45 46 protected: 47 void printint(std::string name, unsigned int value) { 48 std::cout << name << ":" << value << std::endl; 49 50 51 void printstring(std::string name, std::string value) { 52 std::cout << name << ":" << value << std::endl; 53 9

7.1 Condition.h 7 54 55 private: 56 enum type { 57 type_digit, 58 type_xdigit, 59 type_string 60 ; 61 62 bool isdigit(std::string str) { 63 for (int i = 0; i < (int)str.size(); ++i) { 64 if (isdigit(str[i]) == false) { 65 return false; 66 67 68 return true; 69 70 71 bool isxdigit(std::string str) { 72 if (str[0]!= 0 ) { 73 return false; 74 75 if (str[1]!= x && str[1]!= X ) { 76 return false; 77 78 for (int i = 2; i < (int)str.size(); ++i) { 79 if (isxdigit(str[i]) == false) { 80 return false; 81 82 83 return true; 84 85 86 type check(std::string str) { 87 if (isdigit(str) == true) { 88 // std::cout << "digit!" << std::endl; 89 return type_digit; 90 91 if (isxdigit(str) == true) { 92 // std::cout << "xdigit!" << std::endl; 93 return type_xdigit; 94 95 // std::cout << "string!" << std::endl; 96 return type_string; 97 98 99 private: 100 conlist* m_clist; 101 std::string m_prefix; 102 ; 103 #endif 10

7.2 ConditionSample.h 8 7.2 ConditionSample.h 1 #ifndef CONDITION_SAMPLE_H 2 #define CONDITION_SAMPLE_H 3 4 #include <string> 5 #include "Condition.h" 6 7 8 struct sampleparam 9 { 10 std::string type; 11 int value; 12 ; 13 14 typedef struct sampleparam sampleparam; 15 16 typedef vector< sampleparam > sampleparams; 17 18 class ConditionSample : public Condition 19 { 20 public: 21 ConditionSample(); 22 virtual ~ConditionSample(); 23 24 bool initialize(std::string file); 25 bool getparam(std::string prefix, sampleparam* sampleparam); 26 bool getparams(std::string prefix, sampleparams* sampleparams); 27 28 private: 29 Json2ConList m_json2conlist; 30 conlist m_conlistsample; 31 ; 32 33 #endif 8 1. World Wide Web Consortium, Extensible Markup Language (XML), http://www.w3. org/xml/ 2. Apache Software Foundation, Xalan, http://xalan.apache.org/ 3. Crockford D, The application/json Media Type for JavaScript Object Notation (JSON), RFC 4627 (Introducing JSON, http://www.json.org/) 4. JSON, http://www.json.org/json-ja.html 5. JSON Spirit, http://www.codeproject.com/kb/recipes/json Spirit.aspx 6. Keita Kitamura, xml2json.xsl 7. http://daqmw.kek.jp/src/condition-for-daq-middleware-1.0.0. tar.gz 11