Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0002 #include "OnlineDB/EcalCondDB/interface/LMFDefFabric.h"
0003 #include "OnlineDB/EcalCondDB/interface/LMFLaserPulseDat.h"
0004 #include "OnlineDB/EcalCondDB/interface/LMFPnPrimDat.h"
0005 #include "OnlineDB/EcalCondDB/interface/all_lmf_types.h"
0006 #include <climits>
0007 #include <cstdlib>
0008 #include <ctime>
0009 #include <iomanip>
0010 #include <iostream>
0011 #include <string>
0012 #include <vector>
0013 
0014 using namespace std;
0015 
0016 class CondDBApp {
0017 public:
0018   /**
0019    *   App constructor; Makes the database connection
0020    */
0021   CondDBApp(string sid, string user, string pass, run_t r) {
0022     try {
0023       cout << "Making connection..." << flush;
0024       econn = new EcalCondDBInterface(sid, user, pass);
0025       run = r;
0026       cout << "Done." << endl;
0027     } catch (runtime_error &e) {
0028       cerr << e.what() << endl;
0029       exit(-1);
0030     }
0031   }
0032 
0033   /**
0034    *  App destructor;  Cleans up database connection
0035    */
0036   ~CondDBApp() { delete econn; }
0037 
0038   void doRead() {
0039     std::string location = "P5_Co";
0040     RunIOV runiov = econn->fetchRunIOV(location, run);
0041     cout << "Attaching data to Run " << runiov.getRunNumber() << endl;
0042     // now create a sequence
0043     LMFSeqDat seq(econn);
0044     seq.setRunIOV(runiov).setSequenceNumber(1);
0045     seq.debug();
0046     seq.fetchID();
0047     seq.dump();
0048     LMFRunIOV lmfruniov(econn);
0049     lmfruniov.debug();
0050     cout << econn->getEnv() << " " << econn->getConn() << endl;
0051     std::list<LMFRunIOV> iov_l = lmfruniov.fetchBySequence(seq);
0052     cout << iov_l.size() << endl;
0053     exit(0);
0054     lmfruniov.setSequence(seq).setLmr(3);
0055     lmfruniov.fetchID();
0056     lmfruniov.dump();
0057     vector<LMFDat *> v;
0058     LMFRunDat *lmfrundat = new LMFRunDat(econn);
0059     LMFTestPulseConfigDat *lmfconfigdat = new LMFTestPulseConfigDat(econn);
0060     LMFLaserConfigDat *lmflaserconfdat = new LMFLaserConfigDat(econn);
0061     LMFLaserPulseDat *lmfbluepulsedat = new LMFLaserPulseDat("BLUE");
0062     lmfbluepulsedat->setConnection(econn->getEnv(), econn->getConn());
0063     v.push_back(lmfrundat);
0064     v.push_back(lmfconfigdat);
0065     v.push_back(lmflaserconfdat);
0066     v.push_back(lmfbluepulsedat);
0067     for (unsigned int i = 0; i < v.size(); i++) {
0068       v[i]->setLMFRunIOV(lmfruniov);
0069       v[i]->fetch();
0070       v[i]->setMaxDataToDump(10);
0071       v[i]->dump();
0072     }
0073     delete lmfrundat;
0074     delete lmfconfigdat;
0075     delete lmflaserconfdat;
0076     delete lmfbluepulsedat;
0077   }
0078 
0079   void doRun() {
0080     LMFDefFabric fabric(econn);
0081     // find the RunIOV corresponding to a given run
0082     std::string location = "H4B";
0083     RunIOV runiov = econn->fetchRunIOV(location, run);
0084     cout << "Attaching data to Run " << runiov.getRunNumber() << endl;
0085     // now create a sequence
0086     LMFSeqDat seq;
0087     seq.setRunIOV(runiov).setSequenceNumber(1);
0088     Tm start;
0089     start.setToCurrentLocalTime();
0090     seq.setSequenceStart(start);
0091     seq.setVersions(1, 1);
0092     seq.dump();
0093     econn->insertLmfSeq(&seq);
0094     // note that after insert the ID is different from zero
0095     seq.dump();
0096     // a second insertion will not cause any write
0097     econn->insertLmfSeq(&seq);
0098     seq.dump();
0099     // change a parameter (i.e. the seq_num)
0100     seq.setSequenceNumber(2);
0101     // the ID has changed
0102     seq.dump();
0103     // now write and check that we have a different ID
0104     econn->insertLmfSeq(&seq);
0105     seq.dump();
0106     // now create the corresponding LMF_RUN_IOV
0107     LMFRunIOV lmfruniov(econn->getEnv(), econn->getConn());
0108     // we need to associate a tag to the LMF_RUN_IOV. For all classes we have
0109     // different constructors.
0110     LMFRunTag lmfruntag(econn);
0111     lmfruntag.setGeneralTag("gen").setVersion(2);  // operators can be catenated
0112     if (lmfruntag.exists()) {
0113       lmfruntag.dump();
0114       cout << "OK" << endl;
0115     } else {
0116       lmfruntag.dump();
0117       cout << "Does not exists" << endl;
0118     }
0119     // we can just get the tags from the DB
0120     auto listOfTags = lmfruntag.fetchAll();
0121     cout << "Found " << listOfTags.size() << " tags" << endl;
0122     for (auto &tag : listOfTags) {
0123       tag->dump();
0124     }
0125     // we can also get the tags from the fabric
0126     lmfruntag = fabric.getRunTag("gen", 3);
0127     lmfruntag.dump();
0128     // other possibilities
0129     lmfruntag = fabric.getRunTags().front();
0130     lmfruntag.dump();
0131     lmfruntag = fabric.getRunTags().back();
0132     lmfruntag.dump();
0133     // assign this tag to the run iov
0134     lmfruniov.setLMFRunTag(lmfruntag);
0135     lmfruniov.setSequence(seq);
0136     lmfruniov.setLmr(1);
0137     lmfruniov.setColor("blue");
0138     lmfruniov.setTriggerType("las");
0139     lmfruniov.dump();
0140     cout << "Starting filling primitives" << endl;
0141     // get the list of logic_ids
0142     vector<EcalLogicID> ecid_vec;
0143     int sm_min = 1;
0144     int sm_max = 36;
0145     int ch_min = 0;
0146     int ch_max = 1;
0147     ecid_vec = econn->getEcalLogicIDSetOrdered("EB_LM_side",
0148                                                sm_min,
0149                                                sm_max,
0150                                                ch_min,
0151                                                ch_max,
0152                                                EcalLogicID::NULLID,
0153                                                EcalLogicID::NULLID,
0154                                                "EB_crystal_number",
0155                                                1234);
0156     cout << ecid_vec.size() << endl;
0157     // create random data
0158     vector<EcalLogicID>::const_iterator i = ecid_vec.begin();
0159     vector<EcalLogicID>::const_iterator e = ecid_vec.end();
0160     LMFRunDat rundat(econn);
0161     rundat.setLMFRunIOV(lmfruniov);
0162     rundat.dump();
0163     lmfruniov.dump();
0164     cout << "Filling with data" << endl;
0165     while (i != e) {
0166       EcalLogicID logic_id = *i;
0167       int nevts = rand();
0168       int quality = rand() % 10;
0169       rundat.setData(logic_id, nevts, quality);
0170       cout << i->getLogicID() << '\r';
0171       i++;
0172     }
0173     cout << endl;
0174     econn->insertLmfDat(&rundat);
0175     cout << "LMFRunDAT written" << endl;
0176     // pulse + laser config
0177     LMFTestPulseConfigDat tpDat(econn);
0178     tpDat.setLMFRunIOV(lmfruniov);
0179     LMFLaserConfigDat lcDat(econn);
0180     lcDat.setLMFRunIOV(lmfruniov);
0181     i = ecid_vec.begin();
0182     int gain[3] = {1, 6, 12};
0183     while (i != e) {
0184       EcalLogicID logic_id = *i;
0185       i++;
0186       int g = rand() % 3;
0187       tpDat.setData(logic_id, gain[g], rand(), rand(), rand());
0188       vector<float> random_data;
0189       for (int k = 0; k < 8; k++) {
0190         random_data.push_back((float)rand() / static_cast<float>(RAND_MAX));
0191       }
0192       lcDat.setData(logic_id, random_data);
0193     }
0194     econn->insertLmfDat(&tpDat);
0195     econn->insertLmfDat(&lcDat);
0196     // test primitives
0197     cout << "Testing primitives" << endl;
0198     LMFLaserPulseDat laserbluepulsedat(econn, "BLUE");
0199     LMFLaserPulseDat laserirpulsedat(econn, "IR");
0200     LMFPnPrimDat pnPrimDat(econn, "BLUE", "LASER");
0201     laserbluepulsedat.setLMFRunIOV(lmfruniov);
0202     laserirpulsedat.setLMFRunIOV(lmfruniov);
0203     pnPrimDat.setLMFRunIOV(lmfruniov);
0204     i = ecid_vec.begin();
0205     while (i != e) {
0206       EcalLogicID id = *i;
0207       laserbluepulsedat.setFitMethod(id, rand());
0208       laserbluepulsedat.setMTQAmplification(id, rand());
0209       laserbluepulsedat.setMTQTime(id, rand());
0210       laserbluepulsedat.setMTQRise(id, rand());
0211       laserbluepulsedat.setMTQFWHM(id, rand());
0212       laserbluepulsedat.setMTQFW20(id, rand());
0213       laserbluepulsedat.setMTQFW80(id, rand());
0214       laserbluepulsedat.setMTQSliding(id, rand());
0215       laserbluepulsedat.setVersions(id, 1, 1);
0216 
0217       laserirpulsedat.setFitMethod(id, rand());
0218       laserirpulsedat.setMTQAmplification(id, rand());
0219       laserirpulsedat.setMTQTime(id, rand());
0220       laserirpulsedat.setMTQRise(id, rand());
0221       laserirpulsedat.setMTQFWHM(id, rand());
0222       laserirpulsedat.setMTQFW20(id, rand());
0223       laserirpulsedat.setMTQFW80(id, rand());
0224       laserirpulsedat.setMTQSliding(id, rand());
0225       laserirpulsedat.setVersions(id, 1, 1);
0226 
0227       pnPrimDat.setMean(id, rand());
0228       pnPrimDat.setRMS(id, rand());
0229       pnPrimDat.setM3(id, rand());
0230       pnPrimDat.setPNAoverBMean(id, rand());
0231       pnPrimDat.setPNAoverBRMS(id, rand());
0232       pnPrimDat.setPNAoverBM3(id, rand());
0233       pnPrimDat.setFlag(id, rand());
0234       pnPrimDat.setVersions(id, 1, 1);
0235 
0236       i++;
0237     }
0238     cout << "Setting up ok" << endl;
0239     laserbluepulsedat.writeDB();
0240     cout << "1" << endl;
0241     laserirpulsedat.writeDB();
0242     cout << "2" << flush << endl;
0243     pnPrimDat.debug();
0244     pnPrimDat.setMaxDataToDump(2);
0245     pnPrimDat.writeDB();
0246     cout << "3" << endl;
0247   }
0248 
0249 private:
0250   CondDBApp() = delete;  // hidden default constructor
0251   EcalCondDBInterface *econn;
0252   run_t run;
0253 };
0254 
0255 int main(int argc, char *argv[]) {
0256   string sid;
0257   string user;
0258   string pass;
0259 
0260   if (argc != 5) {
0261     cout << "Usage:" << endl;
0262     cout << "  " << argv[0] << " <SID> <user> <pass> <run>" << endl;
0263     exit(-1);
0264   }
0265 
0266   sid = argv[1];
0267   user = argv[2];
0268   pass = argv[3];
0269   int run = atoi(argv[4]);
0270 
0271   try {
0272     CondDBApp app(sid, user, pass, run);
0273     app.doRead();
0274   } catch (exception &e) {
0275     cout << "ERROR:  " << e.what() << endl;
0276   } catch (...) {
0277     cout << "Unknown error caught" << endl;
0278   }
0279 
0280   cout << "All Done." << endl;
0281 
0282   return 0;
0283 }