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 
0007 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0008 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
0009 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0010 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
0011 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
0012 #include "OnlineDB/EcalCondDB/interface/MonPedestalsDat.h"
0013 
0014 
0015 using namespace std;
0016 
0017 class CondDBApp {
0018 public:
0019 
0020   /**
0021    *   App constructor; Makes the database connection
0022    */
0023   CondDBApp(string host, string sid, string user, string pass)
0024   {
0025     try {
0026       cout << "Making connection..." << flush;
0027       if (host != "?") {
0028     econn = new EcalCondDBInterface(host, sid, user, pass );
0029       } else {
0030     econn = new EcalCondDBInterface( sid, user, pass );
0031       }
0032       cout << "Done." << endl;
0033     } catch (runtime_error &e) {
0034       cerr << e.what() << endl;
0035       exit(-1);
0036     }
0037   }
0038 
0039 
0040 
0041   /**
0042    *  App destructor;  Cleans up database connection
0043    */
0044   ~CondDBApp() 
0045   {
0046     delete econn;
0047   }
0048 
0049 
0050   /**
0051    *  Write MonPedestalsDat objects with associated RunTag and RunIOVs
0052    *  IOVs are written using automatic updating of the 'RunEnd', as if
0053    *  the time of the end of the run was not known at the time of writing.
0054    */
0055   void testWrite(int startrun, int numruns)
0056   {
0057     // initial run
0058     run_t run = startrun;
0059 
0060     cout << "Writing MonPedestalsDat Objects to database..." << endl;
0061     // The objects necessary to identify a dataset
0062     LocationDef locdef;
0063     RunTypeDef rundef;
0064     RunTag runtag;
0065     RunIOV runiov;
0066 
0067     MonVersionDef monverdef;
0068     MonRunTag montag;
0069     MonRunIOV moniov;
0070 
0071     Tm startTm;
0072     Tm endTm;
0073     uint64_t oneMin = 1 * 60 * 1000000;
0074     uint64_t twentyMin = 20 * 60 * 1000000;
0075 
0076     // Set the beginning time
0077     startTm.setToString("2007-01-01 00:00:00");
0078     uint64_t microseconds = startTm.microsTime();
0079     microseconds += (startrun-1)*twentyMin;
0080 
0081     // The number of channels and IOVs we will write
0082 
0083     // The objects necessary to define a dataset
0084     EcalLogicID ecid;
0085     MonPedestalsDat ped;
0086     map<EcalLogicID, MonPedestalsDat> dataset;
0087 
0088     // Set the properties of the tag
0089     // The objects necessary to identify a dataset
0090     locdef.setLocation("H4");
0091     rundef.setRunType("PEDESTAL");
0092     
0093     runtag.setLocationDef(locdef);
0094     runtag.setRunTypeDef(rundef);
0095 
0096     runiov.setRunTag(runtag);
0097 
0098     monverdef.setMonitoringVersion("test01");
0099     montag.setMonVersionDef(monverdef);
0100 
0101     moniov.setMonRunTag(montag);
0102 
0103     // Get a set of channels to use
0104     cout << "Getting channel set..." << flush;
0105     vector<EcalLogicID> channels;
0106     channels = econn->getEcalLogicIDSet("EB_crystal_number",
0107                     1, 36,   // SM
0108                     1, 1700 // crystal
0109                     );
0110     cout << "Done." << endl;
0111 
0112     cout << "Writing " << numruns << " sets of pedestals..." << endl;
0113     for (int i=1; i<=numruns; i++) {  // For every IOV we will write
0114       // Set the properties of the runiov
0115       startTm.setToMicrosTime(microseconds);
0116       endTm.setToMicrosTime(microseconds + oneMin);
0117       runiov.setRunNumber(run);
0118       runiov.setRunStart(startTm);
0119       runiov.setRunEnd(endTm);
0120 
0121       // Write runiov
0122       econn->insertRunIOV(&runiov);
0123 
0124       // Set the properties of the moniov
0125       moniov.setRunIOV(runiov);
0126       moniov.setSubRunNumber(0);
0127       moniov.setSubRunStart(startTm);
0128       moniov.setSubRunEnd(endTm);
0129 
0130       for (vector<EcalLogicID>::const_iterator p = channels.begin();
0131        p != channels.end();
0132        ++p) {
0133       
0134     // Set the data
0135     float val = 1 + rand();
0136     ped.setPedMeanG1(val);
0137     ped.setPedMeanG6(val);
0138     ped.setPedMeanG12(val);
0139     ped.setPedRMSG1(val);
0140     ped.setPedRMSG6(val);
0141     ped.setPedRMSG12(val);
0142     ped.setTaskStatus(1);
0143     
0144     // Fill the dataset
0145     dataset[*p] = ped;
0146       }
0147 
0148       // Insert the dataset, identifying by moniov
0149       cout << "Writing IOV " << i << " of " << numruns 
0150        << " (run " << run << ")..." << flush;
0151       econn->insertDataArraySet(&dataset, &moniov );
0152       cout << "Done." << endl;
0153 
0154       // Increment IOV run, start_time
0155       run++;  // one run
0156       microseconds += twentyMin;
0157     }
0158     cout << "Done." << endl << endl;
0159   }
0160 
0161 
0162 
0163 private:
0164   CondDBApp();  // hidden default constructor
0165   EcalCondDBInterface* econn;
0166 };
0167 
0168 
0169 
0170 int main (int argc, char* argv[])
0171 {
0172   string host;
0173   string sid;
0174   string user;
0175   string pass;
0176   int startrun;
0177   int numruns;
0178 
0179   if (argc != 7) {
0180     cout << "Usage:" << endl;
0181     cout << "  " << argv[0] << " <host> <SID> <user> <pass> <start run> <num runs>" << endl;
0182     exit(-1);
0183   }
0184 
0185   host = argv[1];
0186   sid = argv[2];
0187   user = argv[3];
0188   pass = argv[4];
0189   startrun = atoi(argv[5]);
0190   numruns = atoi(argv[6]);
0191 
0192   try {
0193     cout << "Host:  " << host << endl;
0194     cout << "SID:   " << sid << endl;
0195     cout << "User:  " << user << endl;
0196     
0197     CondDBApp app(host, sid, user, pass);
0198 
0199     app.testWrite(startrun, numruns);
0200   } catch (runtime_error &e) {
0201     cout << "ERROR:  " << e.what() << endl;
0202   } catch (...) {
0203     cout << "Unknown error caught" << endl;
0204   }
0205 
0206   cout << "All Done." << endl;
0207 
0208   return 0;
0209 }