Skip to content

Commit 776e342

Browse files
authored
ctpdev (#12974)
* dev: suppressing error from rpcnts * dev:getConfigFromCCDB fix * clang * clang * dev: py macro for watching scalers * dev: keeping old function for compaitibility with QC * clang
1 parent cab2644 commit 776e342

File tree

5 files changed

+149
-5
lines changed

5 files changed

+149
-5
lines changed

DataFormats/Detectors/CTP/include/DataFormatsCTP/RunManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class CTPRunManager
3939
void printActiveRuns() const;
4040
int saveRunScalersToCCDB(int i);
4141
int saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart);
42+
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool& ok);
4243
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run);
4344
CTPRunScalers getScalersFromCCDB(long timestamp, std::string, bool& ok);
4445
int loadScalerNames();

DataFormats/Detectors/CTP/src/RunManager.cxx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
186186
LOG(info) << "EOX received";
187187
mEOX = 1;
188188
}
189+
static int nerror = 0;
190+
if (topic == "rocnts") {
191+
if (nerror < 1) {
192+
LOG(warning) << "Skipping topic rocnts";
193+
nerror++;
194+
}
195+
return 0;
196+
}
189197
//
190198
std::vector<std::string> tokens;
191199
if (firstcounters.size() > 0) {
@@ -198,7 +206,7 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
198206
mNew = 0;
199207
LOG(warning) << "v2 scaler size";
200208
} else {
201-
LOG(error) << "Scalers size wrong:" << tokens.size() << " expected:" << CTPRunScalers::NCOUNTERS + 1 << " or " << CTPRunScalers::NCOUNTERSv2 + 1;
209+
LOG(warning) << "Scalers size wrong:" << tokens.size() << " expected:" << CTPRunScalers::NCOUNTERS + 1 << " or " << CTPRunScalers::NCOUNTERSv2 + 1;
202210
return 1;
203211
}
204212
}
@@ -298,7 +306,7 @@ int CTPRunManager::saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart)
298306
LOG(info) << "CTP config saved in ccdb:" << mCCDBHost << " run:" << cfg->getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
299307
return 0;
300308
}
301-
CTPConfiguration CTPRunManager::getConfigFromCCDB(long timestamp, std::string run)
309+
CTPConfiguration CTPRunManager::getConfigFromCCDB(long timestamp, std::string run, bool& ok)
302310
{
303311
auto& mgr = o2::ccdb::BasicCCDBManager::instance();
304312
mgr.setURL(mCCDBHost);
@@ -307,12 +315,24 @@ CTPConfiguration CTPRunManager::getConfigFromCCDB(long timestamp, std::string ru
307315
auto ctpconfigdb = mgr.getSpecific<CTPConfiguration>(CCDBPathCTPConfig, timestamp, metadata);
308316
if (ctpconfigdb == nullptr) {
309317
LOG(info) << "CTP config not in database, timestamp:" << timestamp;
318+
ok = 0;
310319
} else {
311320
// ctpconfigdb->printStream(std::cout);
312321
LOG(info) << "CTP config found. Run:" << run;
322+
ok = 1;
313323
}
314324
return *ctpconfigdb;
315325
}
326+
CTPConfiguration CTPRunManager::getConfigFromCCDB(long timestamp, std::string run)
327+
{
328+
bool ok;
329+
auto ctpconfig = getConfigFromCCDB(timestamp, run, ok);
330+
if (ok == 0) {
331+
LOG(error) << "CTP config not in CCDB";
332+
return CTPConfiguration();
333+
}
334+
return ctpconfig;
335+
}
316336
CTPRunScalers CTPRunManager::getScalersFromCCDB(long timestamp, std::string run, bool& ok)
317337
{
318338
auto& mgr = o2::ccdb::BasicCCDBManager::instance();

Detectors/CTP/macro/TestConfig.C

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ void TestConfig(bool test = 0)
2323
uint64_t timestamp = 1660196771632;
2424
std::string run = "523148";
2525
o2::ctp::CTPRunManager::setCCDBHost("https://alice-ccdb.cern.ch");
26-
auto ctpcfg = o2::ctp::CTPRunManager::getConfigFromCCDB(timestamp, run);
26+
bool ok;
27+
auto ctpcfg = o2::ctp::CTPRunManager::getConfigFromCCDB(timestamp, run, ok);
28+
if (ok == 0) {
29+
std::cout << "Can not get config for run:" << run << std::endl;
30+
}
2731
CTPConfiguration ctpconfig;
2832
ctpconfig.loadConfigurationRun3(ctpcfg.getConfigString());
2933
// ctpconfig.printStream(std::cout);
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/python3
2+
import requests,re
3+
import os,sys,time,math
4+
import time
5+
from subprocess import Popen, PIPE
6+
def send2(text = "ahoj"):
7+
headers = { 'Content-Type':'application/json',}
8+
data = {
9+
'text':text,
10+
'username':'alicetrg',
11+
}
12+
response = requests.post('https://mattermost.web.cern.ch/hooks/75949oimoinr9b47uhp8c1oomh',headers=headers,json=data)
13+
print(response)
14+
#
15+
def send():
16+
"""
17+
does not work always return can not parse data
18+
"""
19+
Hpar = '\\"Content-Type:application/json\\"'
20+
texth = '\\"text\\"'
21+
text = '\\"lalal\\"'
22+
usernameh = '\\"username\\"'
23+
username = '\\"alicetrg\\"'
24+
dpar = '{}:{},{}:{}'.format(texth,text,usernameh,username)
25+
dpar = "{"+dpar+"}"
26+
dpar = '"'+dpar+'"'
27+
#print(dpar)
28+
cmd = 'curl -g -i -X POST -H {} -d {} https://mattermost.web.cern.ch/hooks/75949oimoinr9b47uhp8c1oomh'.format(Hpar,dpar)
29+
#cmd = 'curl -i -X POST -H {} https://mattermost.web.cern.ch/hooks/75949oimoinr9b47uhp8c1oomh'.format(Hpar)
30+
#cmd='curl -s -o /dev/null {} -F blob=@datafile.root {}/CTP/Calib/{}/{}/{}'.format(wpar, ccdb, actid, tval_s, tval_e)
31+
process = Popen(cmd.split(), stdout = PIPE, stderr = PIPE)
32+
stdo, stde = process.communicate()
33+
print(cmd)
34+
print(stdo)
35+
print("====")
36+
print(stde)
37+
def getLog(service):
38+
#cmd = "journalctl --no-hostname --user-unit "+service
39+
cmd = 'journalctl --no-hostname --user-unit --since "1 day ago" '+service
40+
print(cmd,cmd.split())
41+
process = Popen(cmd.split(), stdout = PIPE, stderr = PIPE)
42+
stdo, stde= process.communicate()
43+
stdo_str = stdo.decode("utf-8")
44+
if stdo_str.find("No entries") != -1:
45+
print("No entries for service:",service)
46+
return None
47+
#print(stdo)
48+
return stdo_str
49+
NMAX = 3
50+
def parseLog(log):
51+
nsent = 0
52+
lines = log.split('\n')
53+
print("# lines:",len(lines))
54+
print(lines[len(lines)-2])
55+
for line in lines:
56+
if line.find("ERROR") != -1:
57+
print(line)
58+
if nsent < NMAX:
59+
send2(line)
60+
nsent += 1
61+
if line.find("ALARM") != -1:
62+
print(line)
63+
if nsent < NMAX:
64+
send2(line)
65+
nsent += 1
66+
#
67+
nWarn = 0
68+
nAlarm = 0
69+
nError = 0
70+
def printNew(list,n,send = 0):
71+
print(n,len(list))
72+
sendnow = 0
73+
if len(list) > n :
74+
sendnow = 1
75+
for i in list[n:]:
76+
print(i)
77+
n = len(list)
78+
if sendnow and send:
79+
print("sending to mm:",line)
80+
send2(line)
81+
return n
82+
def getLogFile():
83+
global nWarn, nAlarm,nError
84+
nWarnList = []
85+
nAlarmList = []
86+
nErrorList = []
87+
MAX = 3
88+
file = "/home/rl/WORK/ctpproxy110424.log"
89+
f = open(file,"r")
90+
nsent = 0
91+
for line in f:
92+
if line.find("ERROR") != -1:
93+
print(line)
94+
if line.find("ALARM") != -1:
95+
#print(line)
96+
nAlarmList.append(line)
97+
#send2(line)
98+
#nsent += 1
99+
if line.find("WARN") != -1:
100+
#print(line)
101+
#items = line.split("\]\[")
102+
#items = re.split('\[|\]',line)
103+
nWarnList.append(line)
104+
#print(nWarn)
105+
nWarn = printNew(nWarnList,nWarn)
106+
nAlarm = printNew(nAlarmList,nAlarm,1)
107+
f.close()
108+
if __name__ =="__main__":
109+
#send2("uj0");
110+
while 1:
111+
now = time.localtime()
112+
current_time = time.strftime("%H:%M:%S",now)
113+
print("===> Time =", current_time)
114+
log = getLogFile()
115+
time.sleep(15)
116+
117+
#parseLog(log)

Detectors/CTP/workflowScalers/src/ctp-ccdb-orbit.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
#include <string>
3434
namespace bpo = boost::program_options;
3535
//
36-
// get object from ccdb auto pp = ccdbMgr.getSpecific<std::vector<long>>("CTP/Calib/OrbitResetTest")
37-
// std::cout << (*pp3)[0] << std::endl;
36+
// get object from ccdb
37+
// auto & cc = o2::ccdb::BasicCCDNManager::instance();
38+
// auto pp = ccdbMgr.getSpecific<std::vector<long>>("CTP/Calib/OrbitResetTest")
39+
// std::cout << (*pp)[0] << std::endl;
3840
int main(int argc, char** argv)
3941
{
4042
const std::string testCCDB = "http://ccdb-test.cern.ch:8080";

0 commit comments

Comments
 (0)