Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:15

0001 #include <iostream>
0002 #include <string>
0003 #include <vector>
0004 #include <time.h>
0005 #include <cstdlib>
0006 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0007 #include "OnlineDB/EcalCondDB/interface/all_od_types.h"
0008 
0009 
0010 using namespace std;
0011 
0012 class CondDBApp {
0013 public:
0014 
0015   /**
0016    *   App constructor; Makes the database connection
0017    */
0018   CondDBApp(string host, string sid, string user, string pass)
0019   {
0020     try {
0021       cout << "Making connection..." << flush;
0022       econn = new EcalCondDBInterface( sid, user, pass );
0023       cout << "Done." << endl;
0024     } catch (runtime_error &e) {
0025       cerr << e.what() << endl;
0026       exit(-1);
0027     }
0028 
0029   }
0030 
0031 
0032 
0033   /**
0034    *  App destructor;  Cleans up database connection
0035    */
0036   ~CondDBApp() 
0037   {
0038     delete econn;
0039   }
0040 
0041   void testWrite()
0042   {
0043 
0044     cout << "Writing a config to database..." << endl;
0045  
0046     //CCS
0047     ODCCSConfig ccs ;
0048     ccs.setConfigTag("CCSConfig_1");
0049     ccs.setDaccal(1 );
0050     ccs.setDelay( 2 );
0051     ccs.setGain( "3" );
0052     ccs.setMemGain(  "16" );
0053     ccs.setOffsetHigh( 10 );
0054     ccs.setOffsetLow(  20 );
0055     ccs.setOffsetMid(  15 );
0056     ccs.setTrgMode(      "unknown" );
0057     ccs.setTrgFilter(    "standard" );
0058     // write to the DB
0059     cout << "Inserting in DB..." << endl;
0060     econn->insertConfigSet(&ccs);
0061     int ccs_id=ccs.getId();
0062     cout << "CCS Config inserted with ID "<< ccs_id<< endl;
0063 
0064 
0065     //DCC
0066     ODDCCConfig dcc ;
0067     dcc.setConfigTag("DCCConfig_1");
0068     std::string my_string="here is a nice DCC configuration";
0069     char * dcc_clob= new char[my_string.length()];
0070     strcpy(dcc_clob, my_string.c_str());
0071     dcc.setDCCClob((unsigned char*)dcc_clob);
0072     // write to the DB
0073     cout << "Inserting in DB..." << endl;
0074     econn->insertConfigSet(&dcc);
0075     int dcc_id=dcc.getId();
0076     cout << "DCC Config inserted with ID "<< dcc_id<< endl;
0077     delete [] dcc_clob;
0078 
0079 
0080     //Laser
0081     ODLaserConfig las ;
0082     las.setConfigTag("LasConfig_1");
0083     las.setMatacqMode("whatever");
0084     las.setChannelMask(3);
0085     las.setMaxSamplesForDaq("10");
0086     las.setPedestalFile("thisfile");
0087     las.setUseBuffer(1);
0088     las.setPostTrig(0);
0089     las.setFPMode(1);
0090     las.setHalModuleFile("bho");
0091     las.setHalAddressTableFile("bho");
0092     las.setHalStaticTableFile("bho");
0093     las.setWaveLength(1 );
0094     las.setPower( 2 );
0095     las.setOpticalSwitch( 0 );
0096     las.setFilter( 1 );
0097     // write to the DB
0098     cout << "Inserting in DB..." << endl;
0099     econn->insertConfigSet(&las);
0100     int las_id=las.getId();
0101     cout << "LASER Config inserted with ID "<< las_id<< endl;
0102 
0103 
0104     // TCC
0105     ODTCCConfig tcc ;
0106     tcc.setConfigTag("TCCConfig_1");
0107     tcc.setNTestPatternsToLoad(184376);
0108     std::string my_tccstring="here is a nice DCC configuration";
0109     char * tcc_clob= new char[my_tccstring.length()];
0110     strcpy(tcc_clob, my_tccstring.c_str());
0111     tcc.setTCCClob((unsigned char*)tcc_clob);
0112     // write to the DB
0113     cout << "Inserting in DB..." << endl;
0114     econn->insertConfigSet(&tcc);
0115     int tcc_id=tcc.getId();
0116     cout << "TCC Config inserted with ID "<< tcc_id<< endl;
0117     delete [] tcc_clob;
0118 
0119 
0120     // TTCci
0121 
0122     cout << "TTCci now coming "<< endl;
0123 
0124     ODTTCciConfig ttcci ;
0125     ttcci.setConfigTag("TTCciConfig_1");
0126     ttcci.setTrgMode("unknown");
0127     std::string my_stringx="here is a nice TTCci configuration";
0128     char * ttcci_clob= new char[my_stringx.length()];
0129     strcpy(ttcci_clob, my_stringx.c_str());
0130     ttcci.setTTCciClob((unsigned char*)ttcci_clob);
0131     // write to the DB
0132     cout << "Inserting TTCci in DB..." << endl;
0133     econn->insertConfigSet(&ttcci);
0134     cout << "here we are..." << endl;
0135     int ttc_id=ttcci.getId();
0136     cout << "TTCci Config inserted with ID "<< ttc_id<< endl;
0137     delete [] ttcci_clob;
0138 
0139 
0140 
0141 
0142     // LTC
0143     ODLTCConfig ltc ;
0144     ltc.setConfigTag("LTCConfig_1");
0145     ltc.setLTCConfigurationFile("a_file.xml");
0146     std::string my_stringltc="here is a nice ltC configuration";
0147     char * ltc_clob= new char[my_stringltc.length()];
0148     strcpy(ltc_clob, my_stringltc.c_str());
0149     ltc.setLTCClob((unsigned char*)ltc_clob);
0150     // write to the DB
0151     cout << "Inserting in DB..." << endl;
0152     econn->insertConfigSet(&ltc);
0153     int ltc_id=ltc.getId();
0154     cout << "LTC Config inserted with ID "<< ltc_id<< endl;
0155     delete [] ltc_clob;
0156 
0157     // LTS
0158     ODLTSConfig lts ;
0159     lts.setConfigTag("LTSConfig_1");
0160     lts.setTriggerType("trigger_type");
0161     lts.setNumberOfEvents(2147);
0162     lts.setRate(200);
0163     lts.setTrigLocL1Delay(10);
0164     // write to the DB
0165     cout << "Inserting in DB..." << endl;
0166     econn->insertConfigSet(&lts);
0167     int lts_id=lts.getId();
0168     cout << "LTs Config inserted with ID "<< lts_id<< endl;
0169 
0170     // JBH4
0171     ODJBH4Config jbh4 ;
0172     jbh4.setConfigTag("JBH4Config_1");
0173     jbh4.setUseBuffer(1);
0174     jbh4.setHalModuleFile("bho");
0175     jbh4.setHalAddressTableFile("bho");
0176     jbh4.setHalStaticTableFile("bho");
0177     jbh4.setCbd8210SerialNumber("9287658346");
0178     jbh4.setCaenBridgeType("CAEN");
0179     jbh4.setCaenLinkNumber(2);
0180     jbh4.setCaenBoardNumber(34);
0181     // write to the DB
0182     cout << "Inserting in DB..." << endl;
0183     econn->insertConfigSet(&jbh4);
0184     int jbh4_id=jbh4.getId();
0185     cout << "JBH4 Config inserted with ID "<< jbh4_id<< endl;
0186 
0187 
0188     // now the ECAL_RUN_CONFIGURATION 
0189     RunTypeDef rundef;
0190     rundef.setRunType("TEST");
0191     RunModeDef runmode;
0192     runmode.setRunMode("LOCAL");
0193 
0194     int nseq=3;
0195 
0196     ODRunConfigInfo run_cfg;
0197     run_cfg.setId(1);
0198     run_cfg.setTag("test");
0199     run_cfg.setDescription("this is a test");
0200     run_cfg.setVersion(1);
0201     run_cfg.setNumberOfSequences(nseq);
0202     run_cfg.setRunTypeDef(rundef);
0203     run_cfg.setRunModeDef(runmode);
0204     cout << "Inserting in DB the ODRunConfigInfo..." << flush;
0205     econn->insertConfigSet(&run_cfg);
0206     cout << "Done." << endl;
0207     int ecal_id= run_cfg.getId();
0208     int last_cycle_id=0;
0209 
0210     // now the sequences
0211     for (int iseq=0; iseq<nseq; iseq++){
0212       RunSeqDef runSeqDef;
0213       runSeqDef.setRunTypeDef(rundef);
0214       runSeqDef.setRunSeq("TEST_SEQUENCE");
0215 
0216       int ncycles=2;
0217       ODRunConfigSeqInfo seq;
0218       seq.setEcalConfigId(ecal_id);
0219       seq.setDescription("this is a seq");
0220       seq.setNumberOfCycles(ncycles);
0221       seq.setSequenceNumber(iseq);
0222       seq.setRunSeqDef(runSeqDef);
0223       // here we insert the sequence and get back the id 
0224       cout << "Inserting in DB..." << flush;
0225       econn->insertConfigSet(&seq);
0226       int seq_id=seq.getId();
0227       cout << "Seq inserted with ID "<< seq_id<< endl;
0228 
0229       for (int icy=0; icy<ncycles; icy++){
0230 
0231     // here we insert the cycle 
0232 
0233     ODEcalCycle ec_cyc;
0234     ec_cyc.setCycleNum(icy );
0235     ec_cyc.setCycleTag("cycle_tag" );
0236     ec_cyc.setCycleDescription("the beautiful cycle" );
0237     ec_cyc.setCCSId(  ccs_id       );
0238     ec_cyc.setDCCId(  dcc_id       );
0239     ec_cyc.setLaserId(las_id       );
0240     ec_cyc.setLTCId(  ltc_id       );
0241     ec_cyc.setLTSId(  lts_id       );
0242     ec_cyc.setTCCId(  tcc_id       );
0243     ec_cyc.setTTCCIId(ttc_id       );
0244     ec_cyc.setJBH4Id( jbh4_id       );
0245     ec_cyc.setScanId( 0       );
0246     ec_cyc.setSequenceId(seq_id);
0247 
0248 
0249     econn->insertConfigSet(&ec_cyc);
0250 
0251     int cyc_id=ec_cyc.getId();
0252     last_cycle_id=cyc_id;
0253     cout << "Last Cycle inserted with ID "<< cyc_id<< endl;
0254       
0255 
0256       }
0257     }
0258 
0259     ODEcalCycle ecal_cycle; 
0260     ecal_cycle.setId(last_cycle_id);
0261     econn->fetchConfigSet(&ecal_cycle);
0262     ecal_cycle.printout();
0263     int dcc_prime_id=ecal_cycle.getDCCId();
0264     ODDCCConfig dcc_prime;
0265     dcc_prime.setId(dcc_prime_id);
0266     econn->fetchConfigSet(&dcc_prime);
0267     unsigned char * buffer_dcc=dcc_prime.getDCCClob();
0268     cout<< "the DCC clob buffer is:"<<endl;
0269     std::cout<< "DCC CLOB:"<<buffer_dcc<< std::endl;
0270     cout << "Done." << endl << endl << endl;
0271     delete [] buffer_dcc;
0272   };
0273 
0274 
0275 
0276 
0277 private:
0278   CondDBApp();  // hidden default constructor
0279   EcalCondDBInterface* econn;
0280   string locations[4];
0281   uint64_t startmicros;
0282   uint64_t endmicros;
0283   run_t startrun;
0284   run_t endrun;
0285 
0286   int tablesTried;
0287   int tablesOK;
0288 
0289   /**
0290    *   Iterate through the dataset and print some data
0291    */
0292 
0293 
0294   /**
0295    *   Print out a RunTag
0296    */
0297 };
0298 
0299 
0300 
0301 int main (int argc, char* argv[])
0302 {
0303   string host;
0304   string sid;
0305   string user;
0306   string pass;
0307 
0308   if (argc != 5) {
0309     cout << "Usage:" << endl;
0310     cout << "  " << argv[0] << " <host> <SID> <user> <pass>" << endl;
0311     exit(-1);
0312   }
0313 
0314   host = argv[1];
0315   sid = argv[2];
0316   user = argv[3];
0317   pass = argv[4];
0318 
0319   try {
0320     CondDBApp app(host, sid, user, pass);
0321 
0322     app.testWrite();
0323 
0324   } catch (exception &e) {
0325     cout << "ERROR:  " << e.what() << endl;
0326   } catch (...) {
0327     cout << "Unknown error caught" << endl;
0328   }
0329 
0330   cout << "All Done." << endl;
0331 
0332   return 0;
0333 }