Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:58

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 /* 
0015    Plugin invocation:
0016    ==================
0017    This plugin behaves like a main program.
0018    Invoke the plugin with something like this:
0019 
0020    geoPluginRun -plugin DD4hep_PersistencyExample_write_cond \
0021                 -output <file-name>
0022 
0023    Test the writing of a bunch of standard conditions objects
0024    to a native ROOT file.
0025 
0026 */
0027 // Framework include files
0028 #include "PersistencySetup.h"
0029 #include "DD4hep/Factories.h"
0030 
0031 using namespace std;
0032 using namespace dd4hep;
0033 using namespace PersistencyExamples;
0034 
0035 /// Plugin function: Condition program example
0036 /**
0037  *  Factory: DD4hep_PersistencyExample_write_cond
0038  *
0039  *  \author  M.Frank
0040  *  \version 1.0
0041  *  \date    01/12/2016
0042  */
0043 static int persistency_example (Detector& /* description */, int argc, char** argv)  {
0044   string output;
0045   bool   arg_error = false;
0046   for(int i=0; i<argc && argv[i]; ++i)  {
0047     if ( 0 == ::strncmp("-output",argv[i],4) )
0048       output = argv[++i];
0049     else
0050       arg_error = true;
0051   }
0052   if ( arg_error || output.empty() )   {
0053     /// Help printout describing the basic command line interface
0054     cout <<
0055       "Usage: -plugin <name> -arg [-arg]                                             \n"
0056       "     name:   factory name     DD4hep_PersistencyExample_write_cond                \n"
0057       "     -output  <string>        Geometry output file                            \n"
0058       "     -iovs    <number>        Number of parallel IOV slots for processing.    \n"
0059       "\tArguments given: " << arguments(argc,argv) << endl << flush;
0060     ::exit(EINVAL);
0061   }
0062 
0063   std::vector<Condition> conditions;
0064 
0065   //Condition char_data    = make_condition<char>   ("char_data", 'A');
0066   //Condition shrt_data    = make_condition<short>  ("short_data",11);
0067   Condition int_data     = make_condition<int>    ("int_data",  12);
0068   Condition long_data    = make_condition<long>   ("long_data", 13);
0069   Condition dble_data    = make_condition<double> ("dble_data", 14.222);
0070   Condition flt_data     = make_condition<float>  ("flt_data",  15.88);
0071   Condition str_data     = make_condition<string> ("str_data",  string("Hello"));
0072   Condition delta_data   = make_condition<Delta>  ("delta_data",Delta(Position(333.0,0,0)));
0073   Condition align_data   = make_condition<AlignmentData>  ("align_data",AlignmentData());
0074   Condition alignment    = AlignmentCondition("Test#alignment");
0075   
0076   Condition flt_vector   = make_condition<vector<float> >  ("float_vector",{0.,1.,2.,3.,4.,5.,6.,7.,8.,9.});
0077   Condition dbl_vector   = make_condition<vector<double> > ("double_vector",{0.,1.,2.,3.,4.,5.,6.,7.,8.,9.});
0078   //Condition char_vector  = make_condition<vector<char> > ("char_vector",{'a','b','c','d','e','f','g','h','i','j'});
0079   //Condition shrt_vector  = make_condition<vector<short> >("short_vector",{0,10,20,30,40,50,60,70,80,90});
0080   Condition int_vector   = make_condition<vector<int> >    ("int_vector",{0,10,20,30,40,50,60,70,80,90});
0081   Condition long_vector  = make_condition<vector<long> >  ("long_vector",{0,10,20,30,40,50,60,70,80,90});
0082   Condition str_vector   = make_condition<vector<string> > ("str_vector",{"Hello","World","!","Here","I","am","!"});
0083   Condition string_map   = make_condition<map<string,int> >("string_map",{{"A",10},{"B",20},{"C",30}});
0084 
0085   //conditions.push_back(char_data);
0086   //conditions.push_back(shrt_data);
0087   conditions.push_back(int_data);
0088   conditions.push_back(long_data);
0089   conditions.push_back(dble_data);
0090   conditions.push_back(flt_data);
0091   conditions.push_back(str_data);
0092 
0093   conditions.push_back(flt_vector);
0094   conditions.push_back(dbl_vector);
0095   //conditions.push_back(char_vector);
0096   conditions.push_back(int_vector);
0097   conditions.push_back(long_vector);
0098   conditions.push_back(str_vector);
0099   
0100   conditions.push_back(string_map);
0101 
0102   /// Alignment stuff
0103   conditions.push_back(delta_data);
0104   conditions.push_back(align_data);
0105   conditions.push_back(alignment);
0106   
0107   PersistencyIO io;
0108   printout(INFO,"Example","+++ Writing generic conditions vector to %s",output.c_str());
0109   int nbytes = io.write(output,"Conditions",conditions);
0110   printout(INFO,"Example","+++ Wrote %d bytes to file %s",nbytes,output.c_str());
0111   printout(INFO,"Example","+++ %s %ld conditions to file.",
0112            nbytes > 0 ? "PASSED Wrote" : "FAILED +++ Could not write",conditions.size());
0113   // All done.
0114   return 1;
0115 }
0116 
0117 // first argument is the type from the xml file
0118 DECLARE_APPLY(DD4hep_PersistencyExample_write_cond,persistency_example)